Expand description
Core types and traits for FastMCP.
This crate provides the fundamental building blocks:
McpContextwrapping asupersync’sCx- Error types for MCP operations
- Core traits for tool, resource, and prompt handlers
§Design Principles
- Zero-copy where possible
- No runtime reflection (compile-time via macros)
- All types support
Send + Sync - Cancel-correct via asupersync integration
§Role in the System
fastmcp-core is the foundation layer shared by every other crate.
It defines:
McpContext, the capability-carrying handle that wraps asupersync’sCx- The FastMCP error model (
McpError,McpErrorCode,McpResult) - Budget/cancellation semantics that handlers and transports must obey
- Outcome bridging utilities so server/client code can stay 4-valued
If you are implementing a new transport, handler, or runtime adapter, this is the crate that gives you the shared primitives used everywhere else.
§Asupersync Integration
This crate uses asupersync as its async runtime foundation, providing:
- Structured concurrency: Tool handlers run in regions
- Cancel-correctness: Graceful cancellation via checkpoints
- Budgeted timeouts: Request timeouts via budget exhaustion
- Deterministic testing: Lab runtime for reproducible tests
Re-exports§
pub use runtime::block_on;
Modules§
- combinator
- Parallel combinator helpers for MCP handlers.
- logging
- Structured logging for FastMCP.
- runtime
- Minimal runtime helpers for FastMCP.
Macros§
- log_
handler - Logs a handler execution event at DEBUG level.
- log_
router - Logs a request routing event at DEBUG level.
- log_
server - Logs a server lifecycle event at INFO level.
- log_
transport - Logs a transport event at DEBUG level.
Structs§
- Access
Token - Parsed access token (scheme + token value).
- Auth
Context - Authentication context stored for a request/session.
- Budget
- A budget constraining resource usage for a task or region.
- Cancelled
Error - Error returned when a request has been cancelled.
- Client
Capability Info - Client capability information accessible from handlers.
- Cx
- The capability context for a task.
- Elicitation
Request - Parameters for an elicitation request.
- Elicitation
Response - Response from an elicitation request.
- LabConfig
- Configuration for the lab runtime.
- LabRuntime
- The deterministic lab runtime.
- McpContext
- MCP context that wraps asupersync’s capability context.
- McpError
- An MCP error response.
- NoOp
Elicitation Sender - A no-op elicitation sender that always returns an error.
- NoOp
Notification Sender - A no-op notification sender used when progress reporting is disabled.
- NoOp
Sampling Sender - A no-op sampling sender that always returns an error.
- Parse
Duration Error - Error type for duration parsing.
- Progress
Reporter - Progress reporter that wraps a notification sender with a progress token.
- Region
Id - A unique identifier for a region in the runtime.
- Resource
Content Item - A single item of resource content.
- Resource
Read Result - Result of reading a resource.
- Sampling
Request - Parameters for a sampling request.
- Sampling
Request Message - A message in a sampling request.
- Sampling
Response - Response from a sampling request.
- Scope
- A scope for spawning work within a region.
- Server
Capability Info - Server capability information accessible from handlers.
- Session
State - Thread-safe session state container for per-session key-value storage.
- TaskId
- A unique identifier for a task in the runtime.
- Tool
Call Result - Result of calling a tool.
Enums§
- Elicitation
Action - Action taken by the user in response to elicitation.
- Elicitation
Mode - Mode of elicitation.
- McpError
Code - Standard MCP/JSON-RPC error codes.
- Outcome
- The four-valued outcome of a concurrent operation.
- Sampling
Role - Role in a sampling message.
- Sampling
Stop Reason - Stop reason for sampling.
- Tool
Content Item - A single item of content returned from a tool call.
Constants§
- AUTH_
STATE_ KEY - Session state key used to store authentication context.
- DISABLED_
PROMPTS_ KEY - Session state key for disabled prompts.
- DISABLED_
RESOURCES_ KEY - Session state key for disabled resources.
- DISABLED_
TOOLS_ KEY - Session state key for disabled tools.
- MAX_
RESOURCE_ READ_ DEPTH - Maximum depth for nested resource reads to prevent infinite recursion.
- MAX_
TOOL_ CALL_ DEPTH - Maximum depth for nested tool calls to prevent infinite recursion.
Traits§
- Elicitation
Sender - Trait for sending elicitation requests to the client.
- Into
Outcome - Extension trait for converting MCP results to asupersync Outcome.
- Notification
Sender - Trait for sending notifications back to the client.
- Outcome
Ext - Extension trait for converting Outcomes to MCP-friendly forms.
- Resource
Reader - Trait for reading resources from within handlers.
- Result
Ext - Extension trait for converting Results to Outcomes.
- Sampling
Sender - Trait for sending sampling requests to the client.
- Tool
Caller - Trait for calling tools from within handlers.
Functions§
- cancelled
- Creates an MCP error Outcome from a cancellation.
- err
- Creates an MCP error Outcome with the given error.
- ok
- Creates an MCP success Outcome.
- parse_
duration - Parses a human-readable duration string into a
Duration.
Type Aliases§
- McpOutcome
- Outcome type alias for MCP operations with 4-valued returns.
- McpResult
- Result type alias for MCP operations.