Skip to content

fix(mcp): support MCP SDK 1.27+ by creating per-request transport#149

Open
jungdaesuh wants to merge 1 commit intoCaviraOSS:mainfrom
jungdaesuh:fix/mcp-sdk-1.27-transport-compat
Open

fix(mcp): support MCP SDK 1.27+ by creating per-request transport#149
jungdaesuh wants to merge 1 commit intoCaviraOSS:mainfrom
jungdaesuh:fix/mcp-sdk-1.27-transport-compat

Conversation

@jungdaesuh
Copy link

Summary

  • Upgrade @modelcontextprotocol/sdk from 1.22.0 to 1.27.1 to support MCP protocol version 2025-11-25 (required by Claude Code 2.1.74+)
  • Fix single-transport bug in mcp.ts: MCP SDK 1.27 rejects re-initialization on a single StreamableHTTPServerTransport instance ("Invalid Request: Server already initialized"). The previous code shared one transport for all connections, so only the first client could connect — every subsequent initialize request returned HTTP 500. Fixed by creating a fresh transport + server per request (safe in stateless mode with sessionIdGenerator: undefined).
  • Fix TS2589 in mcp_tools.ts: The SDK upgrade pulls in zod 3.25+ types that cause Type instantiation is excessively deep and possibly infinite when zodToJsonSchema receives z.ZodType<any> from "zod". Fixed by importing from "zod/v3" to align with zod-to-json-schema's expected type universe.

Test plan

  • tsc --noEmit passes clean (no TS2589, no errors)
  • Server starts and responds to multiple concurrent initialize requests (verified 3 sequential clients all get 200 OK)
  • MCP SDK client (StreamableHTTPClientTransport) connects and lists all 6 tools
  • Protocol version negotiation returns 2025-11-25 (compatible with Claude Code 2.1.74+)
  • Upstream CI

🤖 Generated with Claude Code

MCP SDK 1.27 introduced a guard that rejects re-initialization on a
single StreamableHTTPServerTransport instance. The previous code shared
one transport for all connections, which caused every client after the
first to receive a 500 error. This broke Claude Code, Codex, and any
other MCP client that connects to the server.

Changes:
- Upgrade @modelcontextprotocol/sdk from 1.22.0 to 1.27.1
- Create a fresh transport + server per request in mcp.ts (stateless
  mode requires no session state, so this is safe)
- Align mcp_tools.ts zod import to "zod/v3" to match zod-to-json-schema's
  expected type universe, fixing TS2589 caused by the SDK upgrade

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant