Skip to content

fix: return JSON-RPC errors from MCP route when server/transport construction fails#1783

Open
Matt Van Horn (mvanhorn) wants to merge 1 commit into
browseros-ai:mainfrom
mvanhorn:fix/1437-mcp-internal-server-error-jsonrpc
Open

fix: return JSON-RPC errors from MCP route when server/transport construction fails#1783
Matt Van Horn (mvanhorn) wants to merge 1 commit into
browseros-ai:mainfrom
mvanhorn:fix/1437-mcp-internal-server-error-jsonrpc

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

JSON-RPC calls to the built-in MCP server no longer fail with an opaque InternalServerError. Construction failures in the MCP server or transport are now caught by the route's own error path and returned as spec-compliant JSON-RPC errors with the underlying message, so clients see what actually broke.

Why this matters

On v0.46.0 every POST /mcp call (initialize, tools/list) returned InternalServerError even with cdpConnected: true and a working raw CDP endpoint; the reporter in #1437 verified with curl that the failure is immediate on first request and hits every MCP client. That response shape matches the generic app.onError fallback in apps/server/src/api/server.ts, which fires because the POST / handler in apps/server/src/api/routes/mcp.ts constructed the MCP server and transport BEFORE its try/catch — any synchronous throw during construction (tool registration, connector wiring, transport options) bypassed the JSON-RPC error path entirely.

Changes

  • Server and transport construction moved inside the route's existing try block, so construction failures log with request context, report with the route: mcp tag, and return a JSON-RPC error (code: -32603) carrying the underlying error message instead of the app-level fallback shape.

Testing

Extended the existing test suite (which already injects createMcpServer/createMcpTransport factories) with cases where each factory throws; asserts the response is a 500 JSON-RPC error object, not the app-level InternalServerError shape.

Fixes #1437

@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP Server Returns InternalServerError on All JSON-RPC Calls Despite Healthy CDP Connection

1 participant