-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
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.
maxdeichmann, HemangRajvanshy, smcsicardi, ramana-pz and bencevansramana-pz
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working