MCP Python SDK streamable-http: why 307 redirect from /mcp to /mcp/ and how to fix?
I start an MCP server built with the modelcontextprotocol/python-sdk using mcp.run(transport='streamable-http') and the log shows POST /mcp returning '307 Temporary Redirect', then POST /mcp/ returning 200 OK. Why does every request redirect from /mcp to /mcp/, and how do I avoid it?
Originally asked on GitHub: https://github.com/modelcontextprotocol/python-sdk/issues/732
4 answers
Explained: the 307 redirect is not a bug in the MCP Python SDK. As a contributor explained in the thread, Starlette/FastAPI automatically turns a route without a trailing slash (
/mcp) into one with it (/mcp/), and the SDK'sstreamable_http_clientdoes not handle redirects. The log in the issue body shows the client hittingPOST /mcp, getting the 307, then retryingPOST /mcp/and getting 200 OK. A commenter attributed this to FastAPI behavior and suggested the issue may be closed in this project.Two workarounds came out of the thread:
-
Client side (confirmed by the contributor): call the client with the trailing slash:
streamablehttp_client("http://myserver.com/mcp/")The version without the trailing slash (
http://myserver.com/mcp) triggers the redirect errors. -
Server side (suggested by a commenter, not explicitly confirmed): set
streamable_http_path='/mcp/'when configuring the server so the route matches the direct path.
The contributor also noted that not all MCP clients handle redirects, mentioning a VS Code issue as an example, so using the trailing-slash URL from the start is the safer option. General advice: keep the server path and the client URL consistent (both with or both without the trailing slash) so you don't rely on redirect behavior.
Did this work for you?-
What a GitHub user tried on GitHub (Outcome unclear)
Reporter started the server with mcp.run(transport='streamable-http') and reported the log showing POST /mcp returning 307 Temporary Redirect, followed by POST /mcp/ returning 200 OK.
Source: https://github.com/modelcontextprotocol/python-sdk/issues/732 (opens external site)
Did this work for you?What @pamelafox tried on GitHub (Worked)
A contributor tested streamablehttp_client("http://myserver.com/mcp/") and confirmed it resolves the redirect errors, while the URL without the trailing slash triggers them.
Did this work for you?What @chi2liu tried on GitHub (Outcome unclear)
A commenter suggested setting streamable_http_path='/mcp/' to avoid the redirect; the thread contains no confirmation that this fixed it.
Did this work for you?
Related questions
- MCP python-sdk simple-chatbot: 'Attempted to exit cancel scope in a different task than it was entered in'
- Why is my MCP resource template (greeting://{name}) not available in Claude Desktop?
- How to disable TLS certificate verification (verify=False) in MCP streamablehttp_client?
- anyio.ClosedResourceError in MCP StreamableHTTP message router on fast-failing requests?
- Python MCP SDK streamable HTTP: 'Error in message router' ClosedResourceError after 307 redirect