Repository navigation
Closed
langfuse/langfuse
#11645Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Version 1.25.x introduced hono as dependency. Hono defaults to overrideGlobalObjects: true (see their docs).
After initializing the MCP SDK in our web server (i.e. the first MCP endpoint is called), the hono SDK overwrites all our Next Responses on App Router routes, breaking our app.
To Reproduce
package.json:
{
"name": "mcp-hono-response-bug",
"version": "1.0.0",
"description": "MCP SDK 1.25.x breaks Next.js App Router Response instanceof check",
"type": "module",
"scripts": {},
"dependencies": {
"@modelcontextprotocol/sdk": "1.25.2"
}
}#!/usr/bin/env bun
/**
* @modelcontextprotocol/sdk v1.25.x uses @hono/node-server which overwrites
* global.Response when StreamableHTTPServerTransport is instantiated. This breaks
* Next.js App Router routes because NextResponse extends the original Response class.
*
*/
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
// Capture original Response (simulates Next.js startup)
const OriginalResponse = globalThis.Response;
console.log("\n[1] Original Response captured");
console.log(" Response.name:", Response.name);
// Simulate NextResponse (what next/server does internally)
class NextResponse extends OriginalResponse {
static json(data: unknown, init?: ResponseInit) {
return new NextResponse(JSON.stringify(data), {
...init,
headers: { ...init?.headers, "content-type": "application/json" },
});
}
}
// Verify instanceof works BEFORE MCP SDK instantiation
const before = NextResponse.json({ status: "before" });
console.log("\n[2] BEFORE StreamableHTTPServerTransport instantiation:");
console.log(" response instanceof Response:", before instanceof Response);
console.log(" Response === OriginalResponse:", Response === OriginalResponse);
console.log(" global.Response:", Response.toString().slice(0, 60) + "...");
console.log(" OriginalResponse:", OriginalResponse.toString().slice(0, 60) + "...");
// Instantiate MCP SDK's StreamableHTTPServerTransport
// This is what triggers the bug - internally calls @hono/node-server's getRequestListener()
// which overwrites global.Response with Hono's implementation
console.log("\n[3] Instantiating StreamableHTTPServerTransport...");
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined,
});
console.log(" Transport created");
// Check instanceof AFTER MCP SDK instantiation
const after = NextResponse.json({ status: "after" });
console.log("\n[4] AFTER StreamableHTTPServerTransport instantiation:");
console.log(" Response === OriginalResponse:", Response === OriginalResponse);
console.log(" response instanceof Response:", after instanceof Response);
console.log(
" NextResponse.prototype instanceof Response:",
NextResponse.prototype instanceof Response,
);
console.log(" global.Response:", Response.toString().slice(0, 60) + "...");
console.log(" OriginalResponse:", OriginalResponse.toString().slice(0, 60) + "...");this outputs:
[1] Original Response captured
Response.name: Response
[2] BEFORE StreamableHTTPServerTransport instantiation:
response instanceof Response: true
Response === OriginalResponse: true
global.Response: function Response() {
[native code]
}...
OriginalResponse: function Response() {
[native code]
}...
[3] Instantiating StreamableHTTPServerTransport...
Transport created
[4] AFTER StreamableHTTPServerTransport instantiation:
Response === OriginalResponse: false
response instanceof Response: false
NextResponse.prototype instanceof Response: false
global.Response: class _Response {
#body;
#init;
[getResponseCache]() {...
OriginalResponse: function Response() {
[native code]
}...
confirming that just adding the MCP SDK and initiating a function basically globally breaks all app router routes in NextJS because it overwrites the response object.
Expected behavior
Don't overwrite the response objects.
Logs
This is the error you get from the application if you call an app router route:
web:dev: [Error: No response is returned from route handler '[project]/web/src/app/api/chatCompletion/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler.]
Additional context
i would like to upgrade to 1.25.x because of security implications.
Reacted by Max Deichmann, Hemang Rajvanshy, Sebastian Sicardi, ramana-pz, Ben Evans, Will Selway, Guillermo Enrique Bernal Moreira, Claire Vo and Till Kahlen
Reacted by ramana-pz and Guillermo Enrique Bernal Moreira
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
[-]Inclusion of HONO as dependency after 1.25.x breaks Next AppRouter Routes by globally overwriting response objects[/-][+]Next AppRouter routes break because hono globally overwrites the response objects (v1.25.x +)[/+]HemangRajvanshy commentedon Jan 8, 2026
Related: #1209
Potential Fix (in src/server/streamableHttp.ts):
mattzcarey commentedon Jan 9, 2026
can you use the
webStandardStreamableHTTPServerTransportto unblock yourselves?TiKa-Nexus commentedon Jan 19, 2026
I stumbled upon a problem in my app which likely results from the same underlying issue.
Whenever I run my app on localhost and trigger the mcp server - also hosted on the same localhost port - the app breaks. Its whatever is first "using" the server works but the other one does not. So, I can either use only mcp or only use the app on localhost not both.
The error is always the same:
I use
[email protected]and@modelcontextprotocol/[email protected]nimarb commentedon Jan 19, 2026
hi @mattzcarey , is there a timely plan to fix this / what are your thoughts? work around could be done here potentially (i would just patch out hono personally, as there is no trust), but ideally i would like to see it addressed in the MCP SDK perhaps also on process level when adding such libraries.
this might have been fixed here now, if you bump the deps: honojs/node-server#295
mattzcarey commentedon Jan 19, 2026
Hey I think the latest version of '@hono/node-server' should fix this. Will raise a PR soon
shiftan commentedon Jan 20, 2026
Hey,
Had a similar issue. I believe bumping @hono/node-server won't fix this - PR honojs/node-server#295 only removes the global.fetch override, not Response.
I think the fix is passing { overrideGlobalObjects: false } to getRequestListener() in the SDK.
fix: prevent Hono from overriding global Response object
fix: prevent Hono from overriding global Response object
fix: prevent Hono from overriding global Response object
fix: prevent Hono from overriding global Response object