Expand description
MCP server implementation for FastMCP.
This crate provides the server-side implementation:
- Server builder pattern
- Tool, resource, and prompt registration
- Request routing and dispatching
- Session management
§Example
ⓘ
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();
}§Role in the System
fastmcp-server is the execution engine for MCP servers. It ties
together:
- Protocol types (
fastmcp-protocol) for requests and responses - Transports (
fastmcp-transport) for stdio/SSE/WebSocket I/O - Core context + cancellation (
fastmcp-core) for budgets and checkpoints - Console output (
fastmcp-console) for human-friendly stderr rendering
The façade crate fastmcp re-exports this API, so most users interact with
Server via fastmcp_rust::prelude::*.
Re-exports§
pub use bidirectional::PendingRequests;pub use bidirectional::RequestSender;pub use bidirectional::TransportElicitationSender;pub use bidirectional::TransportRootsProvider;pub use bidirectional::TransportSamplingSender;
Modules§
- bidirectional
- Bidirectional request handling for server-to-client communication.
- caching
- Response caching middleware for MCP servers.
- docket
- Docket: Distributed task queue for FastMCP.
- oauth
- OAuth 2.0/2.1 Authorization Server for MCP.
- oidc
- OpenID Connect (OIDC) Provider for MCP.
- providers
- Built-in resource providers for common use cases.
- rate_
limiting - Rate limiting middleware for protecting FastMCP servers from abuse.
- transform
- Tool transformations for dynamic schema modification.
Structs§
- Allow
AllAuth Provider - Default allow-all provider (returns anonymous auth context).
- Auth
Request - Authentication request view used by providers.
- Bidirectional
Senders - Configuration for bidirectional senders to attach to context.
- Console
Config - Comprehensive configuration for FastMCP console output
- Lifespan
Hooks - Lifecycle hooks for server startup and shutdown.
- Logging
Config - Logging configuration for the server.
- Mount
Result - Result of a mount operation.
- Progress
Notification Sender - A notification sender that sends progress notifications via a callback.
- Proxy
Catalog - Catalog of remote definitions used to register proxy handlers.
- Proxy
Client - Shared proxy client wrapper for handler reuse.
- Router
- Routes MCP requests to the appropriate handlers.
- Router
Resource Reader - A wrapper that implements
ResourceReaderfor a sharedRouter. - Router
Tool Caller - A wrapper that implements
ToolCallerfor a sharedRouter. - Server
- An MCP server instance.
- Server
Builder - Builder for configuring an MCP server.
- Server
Stats - Thread-safe server statistics collector.
- Session
- An MCP session between client and server.
- Static
Token Verifier - Static token verifier backed by an in-memory token map.
- Stats
Snapshot - Point-in-time snapshot of server statistics.
- TagFilters
- Tag filtering parameters for list operations.
- Task
Manager - Background task manager.
- Token
Auth Provider - Token-based authentication provider.
Enums§
- Banner
Style - Style variants for the startup banner
- Duplicate
Behavior - Behavior when registering a component with a name that already exists.
- Middleware
Decision - Result of middleware request interception.
- Traffic
Verbosity - Verbosity levels for traffic logging
Traits§
- Auth
Provider - Authentication provider interface.
- Middleware
- Middleware hook trait for request/response interception.
- Prompt
Handler - Handler for a prompt.
- Proxy
Backend - Backend interface used by proxy handlers.
- Resource
Handler - Handler for a resource.
- Token
Verifier - Token verifier interface used by token-based auth providers.
- Tool
Handler - Handler for a tool.
Functions§
- create_
context_ with_ progress - Helper to create an McpContext with optional progress reporting and session state.
- create_
context_ with_ progress_ and_ senders - Helper to create an McpContext with optional progress reporting, session state, and bidirectional senders.
Type Aliases§
- BoxFuture
- A boxed future for async handler results.
- Notification
Sender - Type alias for a notification sender callback.
- Shared
Task Manager - Thread-safe handle to a TaskManager.
- Shutdown
Hook - Type alias for shutdown hook function.
- Startup
Hook - Type alias for startup hook function.