fastmcp.server.dependencies
Dependency injection for FastMCP.
DI features (Depends, CurrentContext, CurrentFastMCP) work without pydocket
using a vendored DI engine. Only task-related dependencies (CurrentDocket,
CurrentWorker) and background task execution require fastmcp[tasks].
Functions
is_docket_available
require_docket
feature: Description of what requires docket (e.g., “task=True”, “CurrentDocket()”). Will be included in the error message.
transform_context_annotations
fn: Function to transform
- Function with modified signature (same function object, updated signature)
get_context
get_server
- The active FastMCP server
RuntimeError: If no server in context
get_http_request
get_http_headers
content-length that cause issues
if forwarded to downstream clients. If include_all is True, all headers are returned.
get_access_token
- The access token if an authenticated user is available, None otherwise.
without_injected_parameters
- Legacy Context injection (always works)
- Depends() injection (always works - uses docket or vendored DI engine)
fn: Original function with Context and/or dependencies
- Async wrapper function without injected parameters
resolve_dependencies
- Filters out any dependency parameter names from user arguments (security)
- Resolves Depends() parameters via the DI system
ctx: Context to ctx: Context = Depends(get_context) at registration
time, so all injection goes through the unified DI system.
Args:
fn: The function to resolve dependencies forarguments: User arguments (may contain keys that match dependency names, which will be filtered out)
CurrentContext
- A dependency that resolves to the active Context instance
RuntimeError: If no active context found (during resolution)
CurrentDocket
- A dependency that resolves to the active Docket instance
RuntimeError: If not within a FastMCP server contextImportError: If fastmcp[tasks] not installed
CurrentWorker
- A dependency that resolves to the active Worker instance
RuntimeError: If not within a FastMCP server contextImportError: If fastmcp[tasks] not installed
CurrentFastMCP
- A dependency that resolves to the active FastMCP server
RuntimeError: If no server in context (during resolution)
Classes
ProgressLike
Protocol for progress tracking interface.
Defines the common interface between InMemoryProgress (server context)
and Docket’s Progress (worker context).
Methods:
current
total
message
set_total
increment
set_message
InMemoryProgress
In-memory progress tracker for immediate tool execution.
Provides the same interface as Docket’s Progress but stores state in memory
instead of Redis. Useful for testing and immediate execution where
progress doesn’t need to be observable across processes.
Methods:
current
total
message
set_total
increment
set_message
Progress
FastMCP Progress dependency that works in both server and worker contexts.
Handles three execution modes:
- In Docket worker: Uses the execution’s progress (observable via Redis)
- In FastMCP server with Docket: Falls back to in-memory progress
- In FastMCP server without Docket: Uses in-memory progress

