Problem
When a MCP server is built with latest versions mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.25.2 the Nextjs App router API endpoints throw below error
Error:
Error: No response is returned from route handler '[project]/app/api/health/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler. at ignore-listed frames
app/api/health/route.ts
import { NextResponse } from "next/server"
export const GET = () => {
return NextResponse.json({
status: "Ok"
})
}
Same error persists for versions 1.25.X of @modelcontextprotocol/sdk along side of mcp-handler@1.0.6
The only properly working version found - mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.24.3
Expected
NextJS API endpoints must keep functioning correctly along side of MCP routes in same app, when using mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.25.x
Reproducible Steps
- Create a NextJS App Router project
e.g. npx create-next-app@latest my-app --yes
- Install dependencies with latest versions -
mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.25.2
- Create a simple GET API endpoint
e.g. app/api/health/route.ts as above
- Create a simple MCP server
e.g. follow mcp-handler example - https://www.npmjs.com/package/mcp-handler
- Run the app and connect to the MCP Server from tools like Cursor or MCP Inspector (MUST connect to MCP first)
- Ping the
api/health endpoint. Observe that server starts to throw error -
Error: No response is returned from route handler '[project]/app/api/health/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler
Problem
When a MCP server is built with latest versions
mcp-handler@1.0.6and@modelcontextprotocol/sdk@1.25.2the Nextjs App router API endpoints throw below errorError:
Error: No response is returned from route handler '[project]/app/api/health/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler. at ignore-listed framesapp/api/health/route.ts
Same error persists for versions
1.25.Xof@modelcontextprotocol/sdkalong side ofmcp-handler@1.0.6The only properly working version found -
mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.24.3Expected
NextJS API endpoints must keep functioning correctly along side of MCP routes in same app, when using
mcp-handler@1.0.6and@modelcontextprotocol/sdk@1.25.xReproducible Steps
e.g.
npx create-next-app@latest my-app --yesmcp-handler@1.0.6and@modelcontextprotocol/sdk@1.25.2e.g.
app/api/health/route.tsas abovee.g. follow mcp-handler example - https://www.npmjs.com/package/mcp-handler
api/healthendpoint. Observe that server starts to throw error -Error: No response is returned from route handler '[project]/app/api/health/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler