Skip to content

MCP server in NextJS app crashes API Endpoints with error - No response is returned from route handler #139

@akshay-kumardhage-deel

Description

@akshay-kumardhage-deel

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

  1. Create a NextJS App Router project
    e.g. npx create-next-app@latest my-app --yes
  2. Install dependencies with latest versions - mcp-handler@1.0.6 and @modelcontextprotocol/sdk@1.25.2
  3. Create a simple GET API endpoint
    e.g. app/api/health/route.ts as above
  4. Create a simple MCP server
    e.g. follow mcp-handler example - https://www.npmjs.com/package/mcp-handler
  5. Run the app and connect to the MCP Server from tools like Cursor or MCP Inspector (MUST connect to MCP first)
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions