• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-python-sdkNeeds helpSolved

    FastMCP streamable_http_app() returns 307 redirect from /mcp to /mcp/, how to stop it?

    Using mcp 1.11.0 with FastMCP's streamable_http_app() on Python 3.11.3, every POST to /mcp returns "307 Temporary Redirect" to /mcp/ before the 200 OK, adding latency and confusing clients. Setting app.router.redirect_slashes = False makes everything return 404 Not Found. How can I eliminate the redirect without breaking MCP routing?

    Originally asked on GitHub: https://github.com/modelcontextprotocol/python-sdk/issues/1168

    5 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: fixed for the original reporters in mcp 1.12.0; the issue was closed as completed. One later commenter says it still occurs for them in production.

      The redirect is caused by Starlette's Router default redirect_slashes=True, which FastMCP inherits. With mcp 1.11.0, POST /mcp gets a 307 to /mcp/ and then the real response. Two commenters confirmed that upgrading to mcp 1.12.0 made the redirect go away for them, with no other changes mentioned.

      Do not use app.router.redirect_slashes = False on the app returned by streamable_http_app() or http_app(). The original reporter tried this on mcp 1.11.0 and every MCP request returned 404 Not Found. A later commenter on FastMCP 2.10.6 with mcp 1.12.0/1.12.3 and http_app(path='/mcp', transport='streamable-http', stateless_http=True) in a Docker deployment saw the same 404 when disabling redirect_slashes.

      Caveat from the thread: that same commenter still saw /mcp redirect to /mcp/ (followed by 400 Bad Request) after deployment, even after upgrading, even though it worked locally and even though their client was configured with the trailing-slash URL .../mcp/. The thread records no fix for that production-specific case.

      General advice: on versions where the redirect exists, configuring the client with the trailing-slash URL avoids the extra round-trip, and check that any ingress controller or load balancer preserves request bodies during 307 redirects.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Reporter set app.router.redirect_slashes = False on the app returned by mcp.streamable_http_app() with mcp 1.11.0. Every MCP request to /mcp then returned 404 Not Found, breaking routing entirely.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/1168 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @bluedog13 tried on GitHub (Worked)

      A commenter upgraded to mcp 1.12.0 and reported that the 307 redirect to /mcp/ disappeared for them.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/1168#issuecomment-3102971257 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @duaraghav8 tried on GitHub (Worked)

      Another user confirmed that upgrading to mcp 1.12.0 fixed the redirect issue for them as well.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/1168#issuecomment-3106685928 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @harshad5498 tried on GitHub (Didn't work)

      With FastMCP 2.10.6 and mcp 1.12.0/1.12.3, a user deployed http_app(path='/mcp', transport='streamable-http', stateless_http=True) via Docker. Setting app.router.redirect_slashes = False still made /mcp return 404, and in production /mcp still redirected to /mcp/ with 400 Bad Request even though it worked locally and the client already used the .../mcp/ URL.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/1168#issuecomment-3151189037 (opens external site)

      Did this work for you?

    Add your answer or comment