Initial Checks
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
Initial Checks
Description
When
stateless_http=True, the lifespan of the MCP server enters and exits with each request. Surely this is unintended behavior?Example Code
Python & MCP Python SDK