fix(mcp): Use SDK web-standard transport for copilot mcp #4320
fix(mcp): Use SDK web-standard transport for copilot mcp #4320TheodoreSpeaks merged 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Simplifies MCP request handling by switching to Reviewed by Cursor Bugbot for commit 71c906a. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR reverts the MCP copilot route to use Confidence Score: 5/5Safe to merge — straightforward transport swap that removes a broken custom adapter; only finding is a P2 abort edge case. All findings are P2 (minor inconsistency in abort handling between inner/outer catch). No P0 or P1 issues found. The core change is a clean simplification that delegates to well-tested SDK internals. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant POST Handler
participant handleMcpRequestWithSdk
participant WebStandardTransport
participant MCP Server
Client->>POST Handler: POST /api/mcp/copilot
POST Handler->>POST Handler: Auth check
POST Handler->>POST Handler: request.json()
POST Handler->>handleMcpRequestWithSdk: (request, parsedBody)
handleMcpRequestWithSdk->>MCP Server: buildMcpServer(request.signal)
handleMcpRequestWithSdk->>WebStandardTransport: new WebStandardStreamableHTTPServerTransport
handleMcpRequestWithSdk->>MCP Server: server.connect(transport)
handleMcpRequestWithSdk->>WebStandardTransport: transport.handleRequest(request, {parsedBody})
WebStandardTransport->>MCP Server: dispatch tool call
MCP Server-->>WebStandardTransport: tool result
WebStandardTransport-->>handleMcpRequestWithSdk: Response
handleMcpRequestWithSdk-->>POST Handler: Response
POST Handler-->>Client: JSON response
note over POST Handler: On AbortError → 499
note over POST Handler: On other error → 500
Reviews (2): Last reviewed commit: "fix(mcp): fix copilot mcp response" | Re-trigger Greptile |
|
@greptile review |
Summary
Our mcp copilot was broken, consistently returning 5xx. This was due to upgrading mcp sdk versions. Since now the sdk supports WebStandardStreamableHTTPServerTransport, removed the shims and directly used that class instead.
When it broke
Commit
45bf39696— "fix(deps): bump drizzle-orm 0.45.2 + adopt MCP SDK 1.25.3 native types (#4252)" — merged 2026-04-21.That PR touched only
apps/sim/package.json(one-line bump@modelcontextprotocol/sdk1.20.2 → 1.25.3) andapps/sim/lib/copilot/tools/mcp/definitions.ts(cosmetic type cleanup). The route file itself was not modified. The shim there had been working untouched since 2026-02-09.Why the PR review didn't catch it
The SDK's
StreamableHTTPServerTransportwas silently re-architected upstream:handleRequest(req, res, parsedBody)signature → TypeScript saw nothing.raw-body+node:crypto. Only ever readreq.headers.*. Our minimal shim{ method, headers }was sufficient.WebStandardStreamableHTTPServerTransport" using@hono/node-server'sgetRequestListener. For any non-GET/HEAD request, Hono callsincoming.on("end", …)(listener.js:598)..on→TypeError→ caught by Hono → routed tohandleFetchError→Response(null, { status: 500 })→ written to ourNextResponseCaptureviawriteHead(500, …)→ returned by our route as if it were a normal response.route.test.tsunderapps/sim/app/api/mcp/copilot/— nothing in CI round-tripped a POST through the transport, so the regression slipped to prod.The fix
Swap the broken Node-style transport for the SDK's web-standard transport, which Next.js can drive directly (
NextRequestalready extends WebRequest)Also drops the now-unused
NextResponseCaptureshim (~190 lines) andnormalizeRequestHeadershelper. The catch block additionally maps client-aborted requests to 499 (ConnectionClosed) since aborts do legitimately reach it now (unlike everything else, which the SDK handles internally).Verification (local)
initializePOSTtext/plainapplication/jsontools/listPOSTlist_workspaces,create_workflow,sim_workflow, …)Confirmed end-to-end with
claude mcp add --transport http sim-copilot http://localhost:3000/api/mcp/copilot --header "x-api-key: …"→Connected.Type of Change
Testing
tools/listreturns all 23 tools.claude mcp add --transport http sim-copilot http://localhost:3000/api/mcp/copilotsucceeds withConnected.Checklist