-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
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
- Start app (Next.js + Payload) with MCP plugin enabled.
- Confirm baseline routes are healthy:
GET /api/health->200GET /api/redirects-map->200GET /robots.txt->200GET /sitemap.xml->200GET /api/nonexistent->404
- Send valid MCP requests to
POST /api/mcp:initializetools/list- Include
Authorization: Bearer <api-key> - Include
Accept: application/json, text/event-stream
- 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.