Skip to content

Conversation

@mr-kelly
Copy link

The @modelcontextprotocol/sdk has dependencies (via undici) that modify the global Response object at import time. This breaks Next.js App Routes which rely on instanceof Response checks, causing "No response is returned" errors.

This fix:

  • Converts eager SDK imports to type-only imports
  • Adds a lazy loadSdk() function that dynamically imports SDK modules
  • Defers StreamableHTTPServerTransport creation to first request
  • Calls loadSdk() before SDK usage in both HTTP and SSE endpoints

This ensures the SDK is only loaded after Next.js has fully initialized.

The @modelcontextprotocol/sdk has dependencies (via undici) that modify
the global Response object at import time. This breaks Next.js App Routes
which rely on instanceof Response checks, causing "No response is returned"
errors.

This fix:
- Converts eager SDK imports to type-only imports
- Adds a lazy loadSdk() function that dynamically imports SDK modules
- Defers StreamableHTTPServerTransport creation to first request
- Calls loadSdk() before SDK usage in both HTTP and SSE endpoints

This ensures the SDK is only loaded after Next.js has fully initialized.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jd-jam
Copy link

jd-jam commented Jan 20, 2026

Hello all, this issue is impacting my project as well. Using Mr Kelly's patch is working. Is there a timeline for incorporating a fix for this issue into the vercel mcp-handler project?

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.

2 participants