-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Question
Issue Description
When using FastMCP's streamable_http_app()
, requests to the /mcp
endpoint result in a 307 Temporary Redirect to /mcp/
, causing unnecessary latency and potential client compatibility issues.
Current Behavior
INFO: 127.0.0.1:58306 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 127.0.0.1:58306 - "POST /mcp/ HTTP/1.1" 200 OK
## Code
```python
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("My MCP Server")
app = mcp.streamable_http_app()
Root Cause
FastMCP uses Starlette's Router with redirect_slashes=True
by default, which automatically redirects URLs without trailing slashes to URLs with trailing slashes using HTTP 307.
K8s Deployment Issues
In Kubernetes environments, this redirect behavior causes additional problems:
- Ingress Controllers: Some ingress controllers (nginx, traefik) may not preserve request bodies during 307 redirects
- Load Balancers: External load balancers may timeout or fail on redirect chains
- Service Mesh: Istio/Linkerd may not handle redirects properly for streaming connections
- TLS Termination: HTTPS redirects between services can cause certificate validation issues
Impact
- Performance: Extra round-trip for every MCP request
- Client Compatibility: Some HTTP clients may not handle 307 redirects properly
- Debugging Confusion: Logs show double requests for every operation
Attempted Solutions
Solution 1: Disable redirect_slashes (Breaks Routing)
app = mcp.streamable_http_app()
app.router.redirect_slashes = False # This breaks MCP routing entirely
Result: 404 Not Found for all MCP requests
Solution 2: Manual Route Configuration (Complex)
Requires understanding FastMCP's internal routing structure.
Proposed Solutions
Option 1: Add Configuration Parameter
app = mcp.streamable_http_app(redirect_slashes=False)
Option 2: Canonical Endpoint Documentation
Clearly document whether the canonical endpoint is /mcp
or /mcp/
and ensure consistency.
Option 3: Handle Both Routes Explicitly
FastMCP could register both /mcp
and /mcp/
routes to avoid redirects.
Environment
- mcp version:1.11.0
- Python version: 3.11.3
- HTTP Transport: SSE (Server-Sent Events)
- Framework: Starlette (via FastMCP)
Reproduction Steps
- Create FastMCP server with
streamable_http_app()
- Make POST request to
/mcp
(without trailing slash) - Observe 307 redirect in logs
- Request is automatically redirected to
/mcp/
Request
Could FastMCP provide a way to either:
- Disable the redirect behavior without breaking routing
- Configure the canonical endpoint path
- Handle both
/mcp
and/mcp/
without redirects
This would improve performance and reduce confusion for developers implementing MCP servers.
Additional Context
Environment
- mcp version:1.11.0
- Python version: 3.11.3
- HTTP Transport: SSE (Server-Sent Events)
- Framework: Starlette (via FastMCP)