fastmcp_rust/lib.rs
1//! FastMCP: Fast, cancel-correct MCP framework for Rust.
2//!
3//! FastMCP is a Rust implementation of the Model Context Protocol (MCP),
4//! providing a high-performance, cancel-correct framework for building
5//! MCP servers and clients.
6//!
7//! # Features
8//!
9//! - **Fast**: Zero-copy parsing, minimal allocations
10//! - **Cancel-correct**: Built on asupersync for structured concurrency
11//! - **Simple**: Familiar API inspired by FastMCP (Python)
12//! - **Complete**: Tools, resources, prompts, and all MCP features
13//!
14//! # Quick Start
15//!
16//! ```ignore
17//! use fastmcp_rust::prelude::*;
18//!
19//! #[tool]
20//! async fn greet(ctx: &McpContext, name: String) -> String {
21//! format!("Hello, {name}!")
22//! }
23//!
24//! fn main() {
25//! Server::new("my-server", "1.0.0")
26//! .tool(greet)
27//! .run_stdio();
28//! }
29//! ```
30//!
31//! # Architecture
32//!
33//! FastMCP is organized into focused crates:
34//!
35//! - `fastmcp-core`: Core types and asupersync integration
36//! - `fastmcp-protocol`: MCP protocol types and JSON-RPC
37//! - `fastmcp-transport`: Transport implementations (stdio, SSE)
38//! - `fastmcp-server`: Server implementation
39//! - `fastmcp-client`: Client implementation
40//! - `fastmcp-derive`: Procedural macros (#[tool], #[resource], #[prompt])
41//!
42//! # Role in the System
43//!
44//! This crate is the **public façade** of the workspace. It is published as
45//! `fastmcp-rust` on crates.io and imported as `fastmcp_rust`. It re-exports the
46//! pieces you need for day-to-day server and client development so that most
47//! applications can depend on a single crate and write `use fastmcp_rust::prelude::*;`.
48//!
49//! Concretely, `fastmcp_rust` glues together:
50//! - **Core runtime + context** from `fastmcp-core`
51//! - **Protocol models** from `fastmcp-protocol`
52//! - **Transports** from `fastmcp-transport`
53//! - **Server/client** APIs from `fastmcp-server` and `fastmcp-client`
54//! - **Macros** from `fastmcp-derive`
55//!
56//! # When to Use `fastmcp_rust`
57//!
58//! - **You are building an MCP server or client** and want the canonical,
59//! batteries-included API surface.
60//! - **You want a single dependency** rather than wiring the sub-crates
61//! yourself.
62//!
63//! Use the sub-crates directly only when you need a narrower dependency surface
64//! (for example, a custom transport that depends on `fastmcp-transport` but not
65//! the full server stack).
66//!
67//! # Asupersync Integration
68//!
69//! FastMCP uses [asupersync](https://github.com/Dicklesworthstone/asupersync) for:
70//!
71//! - **Structured concurrency**: All tasks belong to regions
72//! - **Cancel-correctness**: Graceful cancellation via checkpoints
73//! - **Budgeted timeouts**: Resource limits for requests
74//! - **Deterministic testing**: Lab runtime for reproducible tests
75
76#![forbid(unsafe_code)]
77#![allow(dead_code)]
78
79// Re-export core types
80pub use fastmcp_core::{
81 AUTH_STATE_KEY, AccessToken, AuthContext, Budget, CancelledError, Cx, IntoOutcome, LabConfig,
82 LabRuntime, McpContext, McpError, McpErrorCode, McpOutcome, McpResult, Outcome, OutcomeExt,
83 RegionId, ResultExt, Scope, TaskId, cancelled, err, ok,
84};
85
86// Re-export logging module
87pub use fastmcp_core::logging;
88
89// Re-export protocol types
90pub use fastmcp_protocol::{
91 CallToolParams, CallToolResult, CancelledParams, ClientCapabilities, ClientInfo, Content,
92 GetPromptParams, GetPromptResult, InitializeParams, InitializeResult, JsonRpcError,
93 JsonRpcMessage, JsonRpcRequest, JsonRpcResponse, ListPromptsParams, ListPromptsResult,
94 ListResourceTemplatesParams, ListResourceTemplatesResult, ListResourcesParams,
95 ListResourcesResult, ListToolsParams, ListToolsResult, LogLevel, PROTOCOL_VERSION, Prompt,
96 PromptArgument, PromptMessage, ReadResourceParams, ReadResourceResult, Resource,
97 ResourceContent, ResourceTemplate, ResourcesCapability, Role, ServerCapabilities, ServerInfo,
98 SubscribeResourceParams, Tool, ToolAnnotations, ToolsCapability, UnsubscribeResourceParams,
99};
100
101// Re-export transport types
102pub use fastmcp_transport::{Codec, StdioTransport, Transport, TransportError};
103
104// Re-export transport modules
105pub use fastmcp_transport::{event_store, http, memory};
106
107// Re-export server types
108#[cfg(feature = "jwt")]
109pub use fastmcp_server::JwtTokenVerifier;
110pub use fastmcp_server::{
111 AllowAllAuthProvider, AuthProvider, AuthRequest, HttpServerConfig, NotificationSender,
112 PendingRequests, PromptHandler, ProxyBackend, ProxyCatalog, ProxyClient, RequestSender,
113 ResourceHandler, Router, Server, ServerBuilder, Session, SharedTaskManager,
114 StaticTokenVerifier, TaskManager, TokenAuthProvider, TokenVerifier, ToolHandler,
115 TransportElicitationSender, TransportRootsProvider, TransportSamplingSender,
116};
117
118// Re-export bidirectional module for namespaced access (e.g. bidirectional::RequestSender)
119pub use fastmcp_server::bidirectional;
120
121// Re-export server middleware modules
122pub use fastmcp_server::{caching, docket, oauth, oidc, rate_limiting, transform};
123
124// Re-export client types
125pub use fastmcp_client::{Client, ClientBuilder, ClientSession};
126
127// Re-export client configuration module
128pub use fastmcp_client::mcp_config;
129
130// Re-export macros
131pub use fastmcp_derive::{JsonSchema, prompt, resource, tool};
132
133// Testing module
134pub mod testing;
135
136/// Prelude module for convenient imports.
137///
138/// ```ignore
139/// use fastmcp_rust::prelude::*;
140/// ```
141pub mod prelude {
142 pub use crate::{
143 // Context and errors
144 AccessToken,
145 AuthContext,
146 // Client
147 Client,
148 // Protocol types
149 Content,
150 JsonSchema,
151 McpContext,
152 McpError,
153 McpOutcome,
154 McpResult,
155 // Outcome types (4-valued result)
156 Outcome,
157 OutcomeExt,
158 Prompt,
159 PromptArgument,
160 PromptMessage,
161 // Server
162 ProxyBackend,
163 ProxyCatalog,
164 ProxyClient,
165 Resource,
166 ResourceContent,
167 ResultExt,
168 Role,
169 Server,
170 StaticTokenVerifier,
171 TokenAuthProvider,
172 TokenVerifier,
173 Tool,
174 cancelled,
175 err,
176 ok,
177 // Macros
178 prompt,
179 resource,
180 tool,
181 };
182}