Skip to content

Incorrect 307 Temporary Redirect -> 400 Bad Request after deploymentΒ #435

@bitnom

Description

@bitnom

Description

Example repo for issue: https://github.com/bitnom/fastmcp-flyio

All my local testing runs without errors. After deployment via a docker image, I see in the fly logs (Upon running a test client):

2025-05-13T18:28:05Z app[d891165bed3418] atl [info][05/13/25 18:28:05] INFO     Starting server "My MCP server.py:207
2025-05-13T18:28:05Z app[d891165bed3418] atl [info]                             Metadata Server"...
2025-05-13T18:28:05Z app[d891165bed3418] atl [info]INFO:     Started server process [628]
2025-05-13T18:28:05Z app[d891165bed3418] atl [info]INFO:     Waiting for application startup.
2025-05-13T18:28:05Z app[d891165bed3418] atl [info]INFO:     Application startup complete.
2025-05-13T18:28:05Z app[d891165bed3418] atl [info]INFO:     Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
2025-05-13T18:28:26Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:36830 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
2025-05-13T18:28:26Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:36844 - "GET /mcp/ HTTP/1.1" 400 Bad Request
2025-05-13T18:28:26Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:36830 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
2025-05-13T18:28:26Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:36844 - "GET /mcp/ HTTP/1.1" 400 Bad Request
2025-05-13T18:29:49Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:49232 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
2025-05-13T18:29:49Z app[d891165bed3418] atl [info]INFO:     172.16.4.26:49250 - "GET /mcp/ HTTP/1.1" 400 Bad Request

how to fix this redirect to work with production url?

Test client:

import asyncio
from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport

mcp_host = "https://mymcp.fly.dev/mcp"
# mcp_host = "http://127.0.0.1:5000/mcp"

async def example():

    async with Client(StreamableHttpTransport(mcp_host)) as client:
        print(await client.ping())

if __name__ == "__main__":
    asyncio.run(example())

client log:

uv run fastmcp_client.py 
Error in post_writer: Client error '400 Bad Request' for url 'https://mymcp.fly.dev/mcp'

server config:

import asyncio
import logging
from fastmcp import FastMCP
from typing import List, Dict, Any, Optional, Union

mcp = FastMCP("YouTube Transcript & Metadata Server", host="0.0.0.0", base_path="/mcp")  # have tried with and withotu base_path

@mcp.tool()
def fetch_video_data_with_concatenated_transcript() -> List[Dict[str, Any]]:
    """
    test tool

    Returns:
        some text
    """
    return "this is a test"

if __name__ == "__main__":
    # Run the MCP server when the script is executed directly
    asyncio.run(mcp.run_streamable_http_async(transport="streamable-http", port=5000, host="0.0.0.0", log_level="debug"))

EXPOSE 5000 is set in the dockerfile.

Example Code

Version Information

FastMCP version:                                                                      2.3.3
MCP version:                                                                          1.8.0
Python version:                                                                      3.12.7

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions