fastmcp.server.context
Functions
set_context
Classes
LogData
Data object for passing log arguments to client-side handlers.
This provides an interface to match the Python standard library logging,
for compatibility with structured logging.
Context
Context object providing access to MCP capabilities.
This provides a cleaner interface to MCP’s RequestContext functionality.
It gets injected into tool and resource functions that request it via type hints.
To use context in a tool function, add a parameter with the Context type annotation:
fastmcp
request_context
report_progress
progress
: Current progress value e.g. 24total
: Optional total value e.g. 100
read_resource
uri
: Resource URI to read
- The resource content as either text or bytes
log
message
: Log messagelevel
: Optional log level. One of “debug”, “info”, “notice”, “warning”, “error”, “critical”, “alert”, or “emergency”. Default is “info”.logger_name
: Optional logger nameextra
: Optional mapping for additional arguments
client_id
request_id
session_id
- The session ID for StreamableHTTP transports, or a generated ID
- for other transports.
session
debug
info
warning
error
list_roots
send_tool_list_changed
send_resource_list_changed
send_prompt_list_changed
sample
elicit
elicit
elicit
elicit
message
: A human-readable message explaining what information is neededresponse_type
: The type of the response, which should be a primitive type or dataclass or BaseModel. If it is a primitive type, an object schema with a single “value” field will be generated.