From bb93f7570e2c22c98bb913d63bcd63a51500b5cc Mon Sep 17 00:00:00 2001 From: Chris Hendrickson Date: Thu, 23 Apr 2026 16:09:30 -0400 Subject: [PATCH] Fix MCP serve: remove stdin conflict and premature ProjectContext call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs caused immediate connection close: 1. ProjectContext.find() at startup crashed if cwd wasn't a project root; it's not needed here — each tool handler calls it on demand. 2. io.stdin.drain() added a second listener to stdin after stdioChannel already subscribed, throwing StateError and killing the process. The Dart event loop keeps the process alive while stdin has a listener. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/mcp/lib/src/commands/serve_command.dart | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/mcp/lib/src/commands/serve_command.dart b/packages/mcp/lib/src/commands/serve_command.dart index 89eeb3d..851726f 100644 --- a/packages/mcp/lib/src/commands/serve_command.dart +++ b/packages/mcp/lib/src/commands/serve_command.dart @@ -21,21 +21,17 @@ class ServeCommand extends DewCommand { @override Future run() async { - final context = await ProjectContext.find(); final tools = _toolRegistry.allTools; io.stderr.writeln( - 'Dew MCP server starting — ' - '${tools.length} tool(s) registered, ' - 'project root: ${context.root}', + 'Dew MCP server starting — ${tools.length} tool(s) registered.', ); + // stdioChannel subscribes to stdin; do not touch stdin after this point. + // The Dart event loop keeps the process alive until the client disconnects. DewMcpServer( stdioChannel(input: io.stdin, output: io.stdout), tools, ); - - // Keep the process alive until the MCP client closes the connection. - await io.stdin.drain(); } }