Update routing for streamable HTTP to avoid 307 redirect
Setup the endpoint for the streamable HTTP (/mcp) in the routing table as a route served by an ASGI app, instead of mounting it as a base path.
Resolves: #732
As mentioned in MCP specification (version 2025-06-18):
The server MUST provide a single HTTP endpoint path (hereafter referred to as the MCP endpoint) that supports both POST and GET methods. For example, this could be a URL like https://example.com/mcp
This also aligns with JSON-RPC specification.
Motivation and Context
The change is required to avoid a 307 Temporary Redirect, from /mcp to /mcp/ endpoint, which currently happens. The redirect causes issues for several popular clients and also impedes hosting MCP servers behind proxy servers.
How Has This Been Tested?
Tested locally and on a remote server with MCP clients.
Breaking Changes
The users who have MCP clients configured to consume the endpoint with a slash, e.g. /mcp/, will start experiencing a 307 Temporary redirect to the endpoint without the slash /mcp.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed