Skip to content

Issue: Custom HTTP Headers (e.g., mcp-session-id) Not Received by FastMCP Server #1063

Open
@hileamlakB

Description

@hileamlakB

Initial Checks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions