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
list_resources
- List of Resource objects available on the server
list_prompts
- List of Prompt objects available on the server
get_prompt
name: The name of the prompt to getarguments: Optional arguments to pass to the prompt
- The prompt result
read_resource
uri: Resource URI to read
- The resource content as either text or bytes
log
fastmcp.server.context.to_client logger with a level of DEBUG.
Args:
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
DEBUG-level message to the connected MCP Client.
Messages sent to Clients are also logged to the fastmcp.server.context.to_client logger with a level of DEBUG.
info
INFO-level message to the connected MCP Client.
Messages sent to Clients are also logged to the fastmcp.server.context.to_client logger with a level of DEBUG.
warning
WARNING-level message to the connected MCP Client.
Messages sent to Clients are also logged to the fastmcp.server.context.to_client logger with a level of DEBUG.
error
ERROR-level message to the connected MCP Client.
Messages sent to Clients are also logged to the fastmcp.server.context.to_client logger with a level of DEBUG.
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.

