Access the Context Object
Reach the request context inside a tool.
Meet the Context Object
The Context object is your tool's gateway to the request: it carries shared state plus helpers for logging and progress.
Ask for It by Type
Add a parameter type-hinted as Context and FastMCP injects it automatically. Clients never see this argument.
from mcp.server.fastmcp import Context
@mcp.tool()
async def greet(name: str, ctx: Context) -> str:
return "hi " + nameAll lessons in this course
- The Lifespan Startup Hook
- Share State via App Context
- Access the Context Object
- Clean Shutdown & Resource Release