Summary
After introducing an MCP route, Next.js App Routes fail at runtime with “No response is returned” only when the application is running inside a Docker container.
The same code works correctly in a non-Docker (local) environment.
The issue is caused by a newly added dependency that modifies global runtime state during startup.
Expected Behavior
- App Routes (e.g.
/api/health) should execute normally in all environments.
- Returning a
Response object from a route handler should be correctly recognized by Next.js.
- Behavior should be consistent between local execution and Docker container execution.
- Adding an MCP route should not affect unrelated App Routes.
Actual Behavior
- In a Docker container, when executing an App Route, Next.js fails its internal
instanceof Response check.
- The runtime throws the error:
No response is returned
- The same route works correctly outside of Docker (in my localhost).
- The route handler does return a valid
Response, but Next.js fails to recognize it.
Root Cause (by Coding Agent)
The newly introduced MCP route brings in a dependency that patches global state at startup via undici/polyfill.
Inside the Docker runtime, this global patch causes a mismatch in the Response constructor used by Next.js, leading to a failed instanceof Response check during App Route execution.
This results in Next.js incorrectly reporting that no response was returned.
This is not an issue with the /api/health implementation itself, but an environment-sensitive side effect of global polyfilling.
Steps to Reproduce
- Build and run the application inside a Docker container.
- Start the Next.js server.
- Call an App Route such as
/api/health.
- Observe the runtime error: “No response is returned.”
- Run the same code outside Docker and observe that it works correctly.
Summary
After introducing an MCP route, Next.js App Routes fail at runtime with “No response is returned” only when the application is running inside a Docker container.
The same code works correctly in a non-Docker (local) environment.
The issue is caused by a newly added dependency that modifies global runtime state during startup.
Expected Behavior
/api/health) should execute normally in all environments.Responseobject from a route handler should be correctly recognized by Next.js.Actual Behavior
instanceof Responsecheck.No response is returnedResponse, but Next.js fails to recognize it.Root Cause (by Coding Agent)
The newly introduced MCP route brings in a dependency that patches global state at startup via
undici/polyfill.Inside the Docker runtime, this global patch causes a mismatch in the
Responseconstructor used by Next.js, leading to a failedinstanceof Responsecheck during App Route execution.This results in Next.js incorrectly reporting that no response was returned.
This is not an issue with the
/api/healthimplementation itself, but an environment-sensitive side effect of global polyfilling.Steps to Reproduce
/api/health.