Skip to main content

Crate fastmcp_rust

Crate fastmcp_rust 

Source
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 integration
  • fastmcp-protocol: MCP protocol types and JSON-RPC
  • fastmcp-transport: Transport implementations (stdio, SSE)
  • fastmcp-server: Server implementation
  • fastmcp-client: Client implementation
  • fastmcp-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-server and fastmcp-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§

AccessToken
Parsed access token (scheme + token value).
AllowAllAuthProvider
Default allow-all provider (returns anonymous auth context).
AuthContext
Authentication context stored for a request/session.
AuthRequest
Authentication request view used by providers.
Budget
A budget constraining resource usage for a task or region.
CallToolParams
tools/call request params.
CallToolResult
tools/call response result.
CancelledError
Error returned when a request has been cancelled.
CancelledParams
Cancelled notification params.
Client
An MCP client instance.
ClientBuilder
Builder for configuring an MCP client.
ClientCapabilities
Client capabilities.
ClientInfo
Client information.
ClientSession
Client-side session state.
Codec
Codec for encoding/decoding JSON-RPC messages.
Cx
The capability context for a task.
GetPromptParams
prompts/get request params.
GetPromptResult
prompts/get response result.
InitializeParams
Initialize request params.
InitializeResult
Initialize response result.
JsonRpcError
JSON-RPC 2.0 error object.
JsonRpcRequest
JSON-RPC 2.0 request.
JsonRpcResponse
JSON-RPC 2.0 response.
LabConfig
Configuration for the lab runtime.
LabRuntime
The deterministic lab runtime.
ListPromptsParams
prompts/list request params.
ListPromptsResult
prompts/list response result.
ListResourceTemplatesParams
resources/templates/list request params.
ListResourceTemplatesResult
resources/templates/list response result.
ListResourcesParams
resources/list request params.
ListResourcesResult
resources/list response result.
ListToolsParams
tools/list request params.
ListToolsResult
tools/list response result.
McpContext
MCP context that wraps asupersync’s capability context.
McpError
An MCP error response.
Prompt
Prompt definition.
PromptArgument
Prompt argument definition.
PromptMessage
A message in a prompt.
ProxyCatalog
Catalog of remote definitions used to register proxy handlers.
ProxyClient
Shared proxy client wrapper for handler reuse.
ReadResourceParams
resources/read request params.
ReadResourceResult
resources/read response result.
RegionId
A unique identifier for a region in the runtime.
Resource
Resource definition.
ResourceContent
Resource content in a message.
ResourceTemplate
Resource template definition.
ResourcesCapability
Resource capabilities.
Router
Routes MCP requests to the appropriate handlers.
Scope
A scope for spawning work within a region.
Server
An MCP server instance.
ServerBuilder
Builder for configuring an MCP server.
ServerCapabilities
Server capabilities advertised during initialization.
ServerInfo
Server information.
Session
An MCP session between client and server.
StaticTokenVerifier
Static token verifier backed by an in-memory token map.
StdioTransport
Stdio transport implementation.
SubscribeResourceParams
resources/subscribe request params.
TaskId
A unique identifier for a task in the runtime.
TaskManager
Background task manager.
TokenAuthProvider
Token-based authentication provider.
Tool
Tool definition.
ToolsCapability
Tool capabilities.
UnsubscribeResourceParams
resources/unsubscribe request params.

Enums§

Content
Content types in MCP messages.
JsonRpcMessage
A JSON-RPC message (request, response, or notification).
LogLevel
Log level.
McpErrorCode
Standard MCP/JSON-RPC error codes.
Outcome
The four-valued outcome of a concurrent operation.
Role
Role in prompt messages.
TransportError
Transport error types.

Constants§

AUTH_STATE_KEY
Session state key used to store authentication context.
PROTOCOL_VERSION
MCP protocol version.

Traits§

AuthProvider
Authentication provider interface.
IntoOutcome
Extension trait for converting MCP results to asupersync Outcome.
OutcomeExt
Extension trait for converting Outcomes to MCP-friendly forms.
PromptHandler
Handler for a prompt.
ProxyBackend
Backend interface used by proxy handlers.
ResourceHandler
Handler for a resource.
ResultExt
Extension trait for converting Results to Outcomes.
TokenVerifier
Token verifier interface used by token-based auth providers.
ToolHandler
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.
SharedTaskManager
Thread-safe handle to a TaskManager.

Attribute Macros§

prompt
Defines a prompt handler.
resource
Defines a resource handler.
tool
Defines a tool handler.

Derive Macros§

JsonSchema
Derives JSON Schema for a type.