Skip to content

plugin-mcp can poison Next.js runtime: subsequent routes fail Response/NextResponse type checks (500s) #15856

@arminnajafi

Description

@arminnajafi

Describe the bug

With @payloadcms/plugin-mcp enabled, successful MCP requests can put the Next.js runtime into a bad state where unrelated route handlers start failing with Response type errors.

After triggering MCP calls, multiple endpoints return 500 with errors like:

  • No response is returned from route handler ... Expected a Response object but received 'NextResponse'
  • TypeError: Expected an instance of Response to be returned

Link to reproduction

I do not yet have a public minimal repo, but this is consistently reproducible in our local setup with exact steps below.

To Reproduce

  1. Start app (Next.js + Payload) with MCP plugin enabled.
  2. Confirm baseline routes are healthy:
    • GET /api/health -> 200
    • GET /api/redirects-map -> 200
    • GET /robots.txt -> 200
    • GET /sitemap.xml -> 200
    • GET /api/nonexistent -> 404
  3. Send valid MCP requests to POST /api/mcp:
    • initialize
    • tools/list
    • Include Authorization: Bearer <api-key>
    • Include Accept: application/json, text/event-stream
  4. Re-check same endpoints.

Expected behavior

MCP calls should not affect response type validation for unrelated route handlers. Endpoints should remain healthy.

Actual behavior

After MCP calls, endpoints start returning 500 with Response/NextResponse type mismatch errors until server restart.

Environment

  • Node: 22.19.0
  • Next: 16.2.0-canary.71
  • Runtime: Next dev server with Turbopack

Version matrix (A/B)

  • Fails:
    • payload@~3.79.0 + @payloadcms/plugin-mcp@~3.79.0
  • Passes (same app, same workflow):
    • payload@~3.79.0 + @payloadcms/plugin-mcp@~3.76.1

So this appears to be a regression in newer plugin-mcp versions.

Additional notes

We observed this both as local repro and as real production-like failure pattern (Cloud Run) where route handlers flip from healthy to 500 after MCP activity.

Metadata

Metadata

Assignees

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