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, 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, PromptHandler, ProxyBackend, ProxyCatalog,
112 ProxyClient, ResourceHandler, Router, Server, ServerBuilder, Session, SharedTaskManager,
113 StaticTokenVerifier, TaskManager, TokenAuthProvider, TokenVerifier, ToolHandler,
114};
115
116// Re-export server middleware modules
117pub use fastmcp_server::{caching, docket, oauth, oidc, rate_limiting, transform};
118
119// Re-export client types
120pub use fastmcp_client::{Client, ClientBuilder, ClientSession};
121
122// Re-export client configuration module
123pub use fastmcp_client::mcp_config;
124
125// Re-export macros
126pub use fastmcp_derive::{JsonSchema, prompt, resource, tool};
127
128// Testing module
129pub mod testing;
130
131/// Prelude module for convenient imports.
132///
133/// ```ignore
134/// use fastmcp_rust::prelude::*;
135/// ```
136pub mod prelude {
137 pub use crate::{
138 // Context and errors
139 AccessToken,
140 AuthContext,
141 // Client
142 Client,
143 // Protocol types
144 Content,
145 JsonSchema,
146 McpContext,
147 McpError,
148 McpOutcome,
149 McpResult,
150 // Outcome types (4-valued result)
151 Outcome,
152 OutcomeExt,
153 Prompt,
154 PromptArgument,
155 PromptMessage,
156 // Server
157 ProxyBackend,
158 ProxyCatalog,
159 ProxyClient,
160 Resource,
161 ResourceContent,
162 ResultExt,
163 Role,
164 Server,
165 StaticTokenVerifier,
166 TokenAuthProvider,
167 TokenVerifier,
168 Tool,
169 cancelled,
170 err,
171 ok,
172 // Macros
173 prompt,
174 resource,
175 tool,
176 };
177}