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

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

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.
ConsoleConfig
Comprehensive configuration for FastMCP console output
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.
ProxyCatalog
Catalog of remote definitions used to register proxy handlers.
ProxyClient
Shared proxy client wrapper for handler reuse.
Router
Routes MCP requests to the appropriate handlers.
RouterResourceReader
A wrapper that implements ResourceReader for a shared Router.
RouterToolCaller
A wrapper that implements ToolCaller for a shared Router.
Server
An MCP server instance.
ServerBuilder
Builder for configuring an MCP server.
ServerStats
Thread-safe server statistics collector.
Session
An MCP session between client and server.
StaticTokenVerifier
Static token verifier backed by an in-memory token map.
StatsSnapshot
Point-in-time snapshot of server statistics.
TagFilters
Tag filtering parameters for list operations.
TaskManager
Background task manager.
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.
MiddlewareDecision
Result of middleware request interception.
TrafficVerbosity
Verbosity levels for traffic logging

Traits§

AuthProvider
Authentication provider interface.
Middleware
Middleware hook trait for request/response interception.
PromptHandler
Handler for a prompt.
ProxyBackend
Backend interface used by proxy handlers.
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.

Type Aliases§

BoxFuture
A boxed future for async handler results.
NotificationSender
Type alias for a notification sender callback.
SharedTaskManager
Thread-safe handle to a TaskManager.
ShutdownHook
Type alias for shutdown hook function.
StartupHook
Type alias for startup hook function.