Expand description
FastMCP: Fast, cancel-correct MCP framework for Rust.
FastMCP is a Rust implementation of the Model Context Protocol (MCP), providing a high-performance, cancel-correct framework for building MCP servers and clients.
§Features
- Fast: Zero-copy parsing, minimal allocations
- Cancel-correct: Built on asupersync for structured concurrency
- Simple: Familiar API inspired by FastMCP (Python)
- Complete: Tools, resources, prompts, and all MCP features
§Quick Start
use fastmcp_rust::prelude::*;
#[tool]
async fn greet(ctx: &McpContext, name: String) -> String {
format!("Hello, {name}!")
}
fn main() {
Server::new("my-server", "1.0.0")
.tool(greet)
.run_stdio();
}§Architecture
FastMCP is organized into focused crates:
fastmcp-core: Core types and asupersync integrationfastmcp-protocol: MCP protocol types and JSON-RPCfastmcp-transport: Transport implementations (stdio, SSE)fastmcp-server: Server implementationfastmcp-client: Client implementationfastmcp-derive: Procedural macros (#tool, #resource, #prompt)
§Role in the System
This crate is the public façade of the workspace. It is published as
fastmcp-rust on crates.io and imported as fastmcp_rust. It re-exports the
pieces you need for day-to-day server and client development so that most
applications can depend on a single crate and write use fastmcp_rust::prelude::*;.
Concretely, fastmcp_rust glues together:
- Core runtime + context from
fastmcp-core - Protocol models from
fastmcp-protocol - Transports from
fastmcp-transport - Server/client APIs from
fastmcp-serverandfastmcp-client - Macros from
fastmcp-derive
§When to Use fastmcp_rust
- You are building an MCP server or client and want the canonical, batteries-included API surface.
- You want a single dependency rather than wiring the sub-crates yourself.
Use the sub-crates directly only when you need a narrower dependency surface
(for example, a custom transport that depends on fastmcp-transport but not
the full server stack).
§Asupersync Integration
FastMCP uses asupersync for:
- Structured concurrency: All tasks belong to regions
- Cancel-correctness: Graceful cancellation via checkpoints
- Budgeted timeouts: Resource limits for requests
- Deterministic testing: Lab runtime for reproducible tests
Modules§
- caching
- Response caching middleware for MCP servers.
- docket
- Docket: Distributed task queue for FastMCP.
- event_
store - Event store for SSE resumability.
- http
- HTTP transport for FastMCP.
- logging
- Structured logging for FastMCP.
- mcp_
config - MCP Configuration file support for server registry.
- memory
- In-memory transport for testing MCP servers without subprocess spawning.
- oauth
- OAuth 2.0/2.1 Authorization Server for MCP.
- oidc
- OpenID Connect (OIDC) Provider for MCP.
- prelude
- Prelude module for convenient imports.
- rate_
limiting - Rate limiting middleware for protecting FastMCP servers from abuse.
- testing
- Test harness infrastructure for FastMCP.
- transform
- Tool transformations for dynamic schema modification.
Structs§
- Access
Token - Parsed access token (scheme + token value).
- Allow
AllAuth Provider - Default allow-all provider (returns anonymous auth context).
- Auth
Context - Authentication context stored for a request/session.
- Auth
Request - Authentication request view used by providers.
- Budget
- A budget constraining resource usage for a task or region.
- Call
Tool Params - tools/call request params.
- Call
Tool Result - tools/call response result.
- Cancelled
Error - Error returned when a request has been cancelled.
- Cancelled
Params - Cancelled notification params.
- Client
- An MCP client instance.
- Client
Builder - Builder for configuring an MCP client.
- Client
Capabilities - Client capabilities.
- Client
Info - Client information.
- Client
Session - Client-side session state.
- Codec
- Codec for encoding/decoding JSON-RPC messages.
- Cx
- The capability context for a task.
- GetPrompt
Params - prompts/get request params.
- GetPrompt
Result - prompts/get response result.
- Initialize
Params - Initialize request params.
- Initialize
Result - Initialize response result.
- Json
RpcError - JSON-RPC 2.0 error object.
- Json
RpcRequest - JSON-RPC 2.0 request.
- Json
RpcResponse - JSON-RPC 2.0 response.
- LabConfig
- Configuration for the lab runtime.
- LabRuntime
- The deterministic lab runtime.
- List
Prompts Params - prompts/list request params.
- List
Prompts Result - prompts/list response result.
- List
Resource Templates Params - resources/templates/list request params.
- List
Resource Templates Result - resources/templates/list response result.
- List
Resources Params - resources/list request params.
- List
Resources Result - resources/list response result.
- List
Tools Params - tools/list request params.
- List
Tools Result - tools/list response result.
- McpContext
- MCP context that wraps asupersync’s capability context.
- McpError
- An MCP error response.
- Prompt
- Prompt definition.
- Prompt
Argument - Prompt argument definition.
- Prompt
Message - A message in a prompt.
- Proxy
Catalog - Catalog of remote definitions used to register proxy handlers.
- Proxy
Client - Shared proxy client wrapper for handler reuse.
- Read
Resource Params - resources/read request params.
- Read
Resource Result - resources/read response result.
- Region
Id - A unique identifier for a region in the runtime.
- Resource
- Resource definition.
- Resource
Content - Resource content in a message.
- Resource
Template - Resource template definition.
- Resources
Capability - Resource capabilities.
- Router
- Routes MCP requests to the appropriate handlers.
- Scope
- A scope for spawning work within a region.
- Server
- An MCP server instance.
- Server
Builder - Builder for configuring an MCP server.
- Server
Capabilities - Server capabilities advertised during initialization.
- Server
Info - Server information.
- Session
- An MCP session between client and server.
- Static
Token Verifier - Static token verifier backed by an in-memory token map.
- Stdio
Transport - Stdio transport implementation.
- Subscribe
Resource Params - resources/subscribe request params.
- TaskId
- A unique identifier for a task in the runtime.
- Task
Manager - Background task manager.
- Token
Auth Provider - Token-based authentication provider.
- Tool
- Tool definition.
- Tools
Capability - Tool capabilities.
- Unsubscribe
Resource Params - resources/unsubscribe request params.
Enums§
- Content
- Content types in MCP messages.
- Json
RpcMessage - A JSON-RPC message (request, response, or notification).
- LogLevel
- Log level.
- McpError
Code - Standard MCP/JSON-RPC error codes.
- Outcome
- The four-valued outcome of a concurrent operation.
- Role
- Role in prompt messages.
- Transport
Error - Transport error types.
Constants§
- AUTH_
STATE_ KEY - Session state key used to store authentication context.
- PROTOCOL_
VERSION - MCP protocol version.
Traits§
- Auth
Provider - Authentication provider interface.
- Into
Outcome - Extension trait for converting MCP results to asupersync Outcome.
- Outcome
Ext - Extension trait for converting Outcomes to MCP-friendly forms.
- Prompt
Handler - Handler for a prompt.
- Proxy
Backend - Backend interface used by proxy handlers.
- Resource
Handler - Handler for a resource.
- Result
Ext - Extension trait for converting Results to Outcomes.
- Token
Verifier - Token verifier interface used by token-based auth providers.
- Tool
Handler - Handler for a tool.
- Transport
- Transport trait for cancel-correct message passing.
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.
Type Aliases§
- McpOutcome
- Outcome type alias for MCP operations with 4-valued returns.
- McpResult
- Result type alias for MCP operations.
- Shared
Task Manager - Thread-safe handle to a TaskManager.
Attribute Macros§
Derive Macros§
- Json
Schema - Derives JSON Schema for a type.