-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on
Milestone
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
When using FastMCP with the streamable-http transport, the client sends a custom header (mcp-session-id) as confirmed by debug output. However, the FastMCP server does not receive this header—it's missing from the request headers seen by the tool handler.
This breaks session persistence and any feature relying on custom headers.
I have attached a demo code below, to run server
python demo.py server
and to run client
python demo.py server
As can be seen in the small demo code
Client debug:
Shows mcp-session-id is present in outgoing headers.
Server debug:
mcp-session-id is missing from all received headers.
Example Code
import sys, asyncio
from fastmcp import FastMCP, Client
from fastmcp.server.dependencies import get_http_headers
PORT = 10000
async def print_headers_tool(ctx):
headers = get_http_headers(include_all=True)
print("SERVER RECEIVED HEADERS:", headers)
return headers
def run_server():
mcp = FastMCP(name="header-demo")
mcp.tool(name="print_headers")(print_headers_tool)
mcp.run(transport="streamable-http", host="0.0.0.0", port=PORT)
def run_client():
async def main():
async with Client(f"http://localhost:{PORT}/mcp") as client:
transport = getattr(client, 'transport', None)
if transport and hasattr(transport, 'headers'):
print("CLIENT OUTGOING HEADERS:", transport.headers)
result = await client.call_tool("print_headers", {})
asyncio.run(main())
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python demo.py [server|client]")
elif sys.argv[1] == "server":
run_server()
elif sys.argv[1] == "client":
run_client()
else:
print("Unknown mode", sys.argv[1])Python & MCP Python SDK
macOS 15.0.1, BuildVersion: 24A348
Python 3.13.5
fastmcp 2.9.0
rhlarora84
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on