fastmcp
fastmcp copied to clipboard
Mounted Server Lifespans
Description
It looks like the generics on FastMCP require the mounted servers and the root server to share the same lifespan context type object?
It also looks like mounted server lifespans are never invoked
from contextlib import asynccontextmanager
from logging import getLogger
from fastmcp.server import FastMCP
@asynccontextmanager
async def mounted_lifespan(app):
"""Lifespan context manager for the MCP server."""
raise "Running mounted lifespan."
mcp = FastMCP(name="Parent MCP Server")
mcp.mount(
"/mounted",
FastMCP(name="Mounted MCP Server", lifespan=mounted_lifespan),
)
if __name__ == "__main__":
mcp.run(transport="sse")
and when using the tool only the context from a lifespan on the root server is available
Example Code
Version Information
2.2.6
Additional Context
No response