-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
enhancementNew feature or requestNew feature or requestv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
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 stateless_http=True
, the lifespan of the MCP server enters and exits with each request. Surely this is unintended behavior?

Example Code
from mcp.server.fastmcp import Context, FastMCP
from contextlib import asynccontextmanager
@asynccontextmanager
async def tmp_lifespan(server: FastMCP):
print(f"Starting lifespan...")
yield
print(f"Ending lifespan...")
mcp = FastMCP("localmcp", host="127.0.0.1", lifespan=tmp_lifespan, port=8000, stateless_http=True)
# Add an addition tool
@mcp.tool()
async def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
if __name__ == "__main__":
print(f"Starting MCP server...")
mcp.run(transport="streamable-http")
Python & MCP Python SDK
1.13.0
jpoehnelt and mamuqsit
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes