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
MCP 2026-07-28 support is under implementation and remains unverified. The
public protocol constant is still 2024-11-05; server source presence is
not aggregate conformance or release evidence.
§Example
use fastmcp_rust::prelude::*;
#[tool]
async fn greet(ctx: &McpContext, name: String) -> McpResult<String> {
ctx.checkpoint()?;
Ok(format!("Hello, {name}!"))
}
fn main() {
Server::new("my-server", "1.0.0")
.tool(Greet)
.build()
.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/HTTP/memory I/O - Core context + cancellation (
fastmcp-core) for budgets and checkpoints - Console output (
fastmcp-console) for human-friendly stderr rendering
The façade package fastmcp-rust re-exports this API, so most users
interact with Server via fastmcp_rust::prelude::*.
§Extension panic-containment boundary
Unwinding extension callback panics (including handler, auth, middleware, and lifecycle callbacks) are caught at their framework boundaries. Request-path failures are mapped to a fixed payload-free peer error. FastMCP also installs a redacting panic hook for local diagnostics, but Rust’s hook is process-global and replaceable: an embedding application that installs another hook afterward controls subsequent panic diagnostics. Such replacement does not change the fixed peer error, but FastMCP cannot promise payload-free local diagnostics after its hook has been replaced.
Re-exports§
pub use extensions::ExtensionHandler;pub use extensions::ExtensionHandlerInvocationError;pub use extensions::ExtensionHandlerKey;pub use extensions::ExtensionHandlerLookupError;pub use extensions::ExtensionHandlerRegistrationError;pub use extensions::ExtensionHandlerRegistry;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.
- extensions
- Typed server handlers for negotiated MCP extensions.
- http_
admission - HTTP-02 A: modern server HTTP admission and validation pipeline.
- legacy_
2024 - Exact MCP 2024-11-05 server lifecycle adapter.
- oauth
- OAuth 2.0/2.1 authorization-server implementation code 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.
- Bound
Http Server - A bound, caller-owned HTTP server lifecycle.
- Console
Config - Shared configuration for FastMCP console output and host integrations.
- Final
Elicitation - One final-era elicitation request that a handler returns as MRTR input.
- Final
Roots - One final-era roots request that a handler returns as MRTR input.
- Final
Sampling - One final-era sampling request that a handler returns as MRTR input.
- Http
Nonquiescent Shutdown - Caller-owned settlement authority for a bounded, nonquiescent HTTP stop.
- Http
Server Config - Configuration for the live HTTP listener used by
Server::run_http. - Inbound
Request Context - Sanitized, immutable ingress facts for one server dispatch.
- 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.
- Router
- Routes MCP requests to the appropriate handlers.
- Server
- An MCP server instance.
- Server
Builder - Builder for configuring an MCP server.
- Server
Http Endpoint - A live server composition over a bounded HTTP endpoint.
- Server
Http Request Cancellation - Cancellation view shared by one public HTTP response body and its MCP request authority.
- Server
Http Session - A server-owned session opened through
ServerHttpEndpoint. - Server
Http SseResponse - A server-bound modern SSE response body.
- Server
Stats - Thread-safe server statistics collector.
- Session
- An MCP session between client and server.
- Static
Token Verifier - Static token verifier backed by fixed-width token digests.
- Stats
Snapshot - Point-in-time snapshot of server statistics.
- Subscription
Listen Handle - Caller-owned in-process
subscriptions/listenstream. - TagFilters
- Tag filtering parameters for list operations.
- 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.
- Final
Method Outcome - One application-authored result of a final method that may require input.
- Final
Resource Read Cache Hint Provenance - Identifies who selected a complete final resource-read cache policy.
- Final
Tool Outcome - One application-authored outcome of a final
tools/callhandler. - Final
Tool Schema Authority - Legacy diagnostic label for an exact-final tool’s schema ownership.
- Http
Server Shutdown - The complete outcome of
BoundHttpServer::serve. - Http
Shutdown Settlement - The state of a caller-owned nonquiescent HTTP shutdown handle.
- Inbound
Request Transport - Allowlisted transport provenance attached to a sanitized inbound request.
- Middleware
Decision - Result of middleware request interception.
- Server
Extension Configuration Error - Failure while installing the server-owned extension registry.
- Server
Extension Negotiation Error - Failure while deriving a current-exchange extension capability set.
- Server
Http Endpoint Error - Failure while constructing or operating a public server HTTP endpoint.
- Server
Http Endpoint Response - A response emitted by
ServerHttpSession::handle. - Server
Launch Policy Error - The selected launch policy is malformed, not valid Unicode, or unavailable in the compiled server feature set.
- Tool
Error Kind - Closed framework error classes that an output-schema tool must represent.
- Traffic
Verbosity - Verbosity levels for traffic logging
Traits§
- Auth
Provider - Authentication provider interface.
- Completion
Handler - Handler for
completion/completein both supported protocol eras. - Final
Elicitation Context Ext - Final-only elicitation construction for
McpContext. - Final
Roots Context Ext - Final-only roots construction for
McpContext. - Final
Sampling Context Ext - Final-only sampling construction for
McpContext. - Middleware
- Middleware hook trait for request/response interception.
- Prompt
Handler - Handler for a prompt.
- 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.
- promote_
legacy_ prompt_ messages - Promotes legacy prompt messages for a final handler default.
- promote_
legacy_ resource_ contents - Promotes legacy resource contents for a final handler default.
- promote_
legacy_ tool_ content - Promotes an exact legacy tool payload into the final complete-result algebra.
Type Aliases§
- BoxFuture
- A boxed future for async handler results.
- Notification
Sender - Type alias for a notification sender callback.
- Shutdown
Hook - Type alias for shutdown hook function.
- Startup
Hook - Type alias for startup hook function.