Skip to main content

Crate fastmcp_server

Crate fastmcp_server 

Source
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§

AllowAllAuthProvider
Default allow-all provider (returns anonymous auth context).
AuthRequest
Authentication request view used by providers.
BidirectionalSenders
Configuration for bidirectional senders to attach to context.
BoundHttpServer
A bound, caller-owned HTTP server lifecycle.
ConsoleConfig
Shared configuration for FastMCP console output and host integrations.
FinalElicitation
One final-era elicitation request that a handler returns as MRTR input.
FinalRoots
One final-era roots request that a handler returns as MRTR input.
FinalSampling
One final-era sampling request that a handler returns as MRTR input.
HttpNonquiescentShutdown
Caller-owned settlement authority for a bounded, nonquiescent HTTP stop.
HttpServerConfig
Configuration for the live HTTP listener used by Server::run_http.
InboundRequestContext
Sanitized, immutable ingress facts for one server dispatch.
LifespanHooks
Lifecycle hooks for server startup and shutdown.
LoggingConfig
Logging configuration for the server.
MountResult
Result of a mount operation.
ProgressNotificationSender
A notification sender that sends progress notifications via a callback.
Router
Routes MCP requests to the appropriate handlers.
Server
An MCP server instance.
ServerBuilder
Builder for configuring an MCP server.
ServerHttpEndpoint
A live server composition over a bounded HTTP endpoint.
ServerHttpRequestCancellation
Cancellation view shared by one public HTTP response body and its MCP request authority.
ServerHttpSession
A server-owned session opened through ServerHttpEndpoint.
ServerHttpSseResponse
A server-bound modern SSE response body.
ServerStats
Thread-safe server statistics collector.
Session
An MCP session between client and server.
StaticTokenVerifier
Static token verifier backed by fixed-width token digests.
StatsSnapshot
Point-in-time snapshot of server statistics.
SubscriptionListenHandle
Caller-owned in-process subscriptions/listen stream.
TagFilters
Tag filtering parameters for list operations.
TokenAuthProvider
Token-based authentication provider.

Enums§

BannerStyle
Style variants for the startup banner
DuplicateBehavior
Behavior when registering a component with a name that already exists.
FinalMethodOutcome
One application-authored result of a final method that may require input.
FinalResourceReadCacheHintProvenance
Identifies who selected a complete final resource-read cache policy.
FinalToolOutcome
One application-authored outcome of a final tools/call handler.
FinalToolSchemaAuthority
Legacy diagnostic label for an exact-final tool’s schema ownership.
HttpServerShutdown
The complete outcome of BoundHttpServer::serve.
HttpShutdownSettlement
The state of a caller-owned nonquiescent HTTP shutdown handle.
InboundRequestTransport
Allowlisted transport provenance attached to a sanitized inbound request.
MiddlewareDecision
Result of middleware request interception.
ServerExtensionConfigurationError
Failure while installing the server-owned extension registry.
ServerExtensionNegotiationError
Failure while deriving a current-exchange extension capability set.
ServerHttpEndpointError
Failure while constructing or operating a public server HTTP endpoint.
ServerHttpEndpointResponse
A response emitted by ServerHttpSession::handle.
ServerLaunchPolicyError
The selected launch policy is malformed, not valid Unicode, or unavailable in the compiled server feature set.
ToolErrorKind
Closed framework error classes that an output-schema tool must represent.
TrafficVerbosity
Verbosity levels for traffic logging

Traits§

AuthProvider
Authentication provider interface.
CompletionHandler
Handler for completion/complete in both supported protocol eras.
FinalElicitationContextExt
Final-only elicitation construction for McpContext.
FinalRootsContextExt
Final-only roots construction for McpContext.
FinalSamplingContextExt
Final-only sampling construction for McpContext.
Middleware
Middleware hook trait for request/response interception.
PromptHandler
Handler for a prompt.
ResourceHandler
Handler for a resource.
TokenVerifier
Token verifier interface used by token-based auth providers.
ToolHandler
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.
NotificationSender
Type alias for a notification sender callback.
ShutdownHook
Type alias for shutdown hook function.
StartupHook
Type alias for startup hook function.