fix(ai-sdk): spawn the MCP server without requiring a build - #507
Merged
Conversation
The MCP client factory spawned `node lib/mcp-server.js` — a cwd-relative path
into compiled output that neither `npm start` nor `npm run start.watch`
produces, since both run the Worker straight from `src` via ts-node. On a fresh
clone `npm run workflow mcp` then failed on every attempt with
`MCPClientError: Connection closed`: the child exited immediately with
MODULE_NOT_FOUND, the stdio transport fired `onclose`, and the pending
`initialize` request was rejected.
Resolve the server with `require.resolve('./mcp-server')` so the path is
absolute and follows whichever output is running (`src/*.ts` under ts-node,
`lib/*.js` when compiled), and run it with `process.execPath` plus
`-r ts-node/register` for the TypeScript case.
Also move the startup banner to stderr: stdout is the JSON-RPC channel of a
stdio MCP server, so the client was parsing that line as a message.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
brianstrauch
commented
Aug 10, 2026
brianstrauch
commented
Aug 10, 2026
brianstrauch
commented
Aug 10, 2026
Co-authored-by: Brian Strauch <brian@brianstrauch.com>
brianstrauch
enabled auto-merge (squash)
August 10, 2026 16:24
xumaple
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
ai-sdksample's MCP client factory spawned the MCP server asnode lib/mcp-server.js— a cwd-relative path into compiled output that neithernpm startnornpm run start.watchproduces, since both run the Worker straight fromsrcvia ts-node.On a fresh clone,
npm run workflow mcpfailed on every attempt (retried forever) with:The child process exited immediately with
MODULE_NOT_FOUND, the stdio transport firedonclose, and the pendinginitializerequest was rejected. The message is generic enough that it reads like a broken MCP session rather than "the server script isn't there".Changes
ai-sdk/src/worker.ts— resolve the server withrequire.resolve('./mcp-server'), so the path is absolute (cwd-independent) and follows whichever output is actually running:src/mcp-server.tsunder ts-node,lib/mcp-server.jswhen compiled. Spawn it withprocess.execPath(the same Node binary running the Worker) plus-r ts-node/registerfor the TypeScript case, and set the childcwdto the project root so ts-node finds this project'stsconfig.json.ai-sdk/src/mcp-server.ts— move the startup banner fromconsole.logtoconsole.error. stdout is the JSON-RPC channel of a stdio MCP server, so that line was being fed to the client's read buffer as a bogus message (swallowed as a parse error, but latent breakage).No build step is required anymore, which matches the README's setup instructions.
Testing
temporal server start-dev+npm start+npm run workflow mcpagainst a fresh, unbuiltlib/:testServer-listToolsandtestServer-callToolboth succeeded on the first attempt — no retries, noConnection closed.node -r .../ts-node/register .../ai-sdk/src/mcp-server.ts, and the banner landed on the Worker's stderr.require.resolve('./mcp-server')fromlib/worker.jsresolves tolib/mcp-server.jsand takes the plain-node branch.npm run buildandprettier --checkpass.🤖 Generated with Claude Code