Expand description
FlyMCPRust: high-performance MCP server SDK for Rust. An ergonomic, safe and fast way to build Model Context Protocol servers, targeting specification revision 2026-07-28 (stateless).
use flymcprust::prelude::*;
/// Adds two numbers.
///
/// # Arguments
/// * `a` - First operand.
/// * `b` - Second operand.
#[tool(read_only, idempotent)]
async fn add(a: f64, b: f64) -> f64 {
a + b
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::builder("calculator", "1.0.0")
.tool::<add>()
.build()?
.serve_stdio()
.await?;
Ok(())
}§Features
| Feature | Default | Description |
|---|---|---|
macros | yes | The tool, resource and prompt attribute macros. |
stdio | no | stdio transport (Server::serve_stdio). |
http | no | Streamable HTTP transport (transport::http). |
oauth | no | auth::JwtVerifier for OAuth access tokens (implies http). |
auto-register | no | ServerBuilder::auto_tools (and auto_resources, auto_prompts) collect every annotated item. |
logging | no | logging::init() writes the log, with fix-it hints, to stderr. |
test-client | no | In-process testing::TestClient for tests. |
See the repository’s docs/ARCHITECTURE.md for design decisions.
Modules§
- apps
- MCP Apps (
io.modelcontextprotocol/ui): tools that render an interactive HTML interface in the host. - auth
- Authorization: the authenticated caller (
Principal), access-token verification (TokenVerifier) and scope checks. - jsonrpc
- JSON-RPC 2.0 envelope parsing and response serialization.
- logging
- Logging setup (feature
logging). - message
- Builders for prompt messages.
- prelude
- The most common imports.
- security
- Helpers for handling untrusted client input safely.
- spec
- Protocol types of the targeted revision.
Protocol types for MCP specification revision
2026-07-28. - testing
- In-process test client (feature
test-client). - transport
- Transports. Each one only moves bytes; all protocol logic lives in
Server.
Structs§
- AppUi
- How the host should sandbox a UI resource (
_meta.ui). - Completion
- Completion values. Results longer than
MAX_COMPLETION_VALUESare truncated, withtotalandhasMoreset accordingly. - Completion
Request - What the client asked to complete.
- Ctx
- Context of the request being handled. Declare a
Ctxparameter in a tool to receive it; it is excluded from the tool’s input schema. - Json
- Wraps a value returned as structured content. The tool’s
outputSchemais generated fromT, and the result carries bothstructuredContentand the serialized JSON as text, as the specification recommends. - Limits
- Resource limits applied to every request.
- McpError
- A JSON-RPC error returned to the client.
- McpRequest
- A parsed message plus transport-provided context.
- Mirrored
Param - A tool parameter mirrored into an
Mcp-Param-{name}header. - Principal
- The caller authenticated by an access token.
- Prompt
Arguments - The arguments of a
prompts/getrequest. - Prompt
Def - A registered prompt: its protocol description plus its entry point.
- Resource
Def - A registered resource or resource template.
- Server
- A built MCP server. Cheap to clone; all clones share one registry.
- Server
Builder - Builds a
Server. - State
- Shared application state registered with
ServerBuilder::state. Declare aState<T>parameter in a tool to receive it; it is excluded from the tool’s input schema. A tool that needs a state type that was never registered makesServerBuilder::buildfail. - Token
Error - Why a token was rejected. The reason is logged on the server; clients only learn that the token is invalid.
- ToolDef
- A registered tool: its protocol description plus its entry point.
- Tool
Error - An error raised by a tool, resource or prompt handler.
- Transport
Context - Values attached by the transport to a request (for example, authenticated claims or HTTP headers). Tower middleware can populate it before the request reaches the server.
- UriTemplate
- A parsed URI template.
- UriTemplate
Error - A template that cannot be parsed or is not supported.
- UriVars
- Variable values extracted from a URI by
UriTemplate::matches.
Enums§
- Build
Error - Errors detected while building a server.
- Elicitation
- The outcome of an elicitation.
- Error
Kind - How an error relates to the request, independent of transport. HTTP uses it to pick a status code (400, 404, 200 or 500).
- Param
Kind - JSON Schema primitive type of a mirrored parameter.
- Permission
- A browser capability a UI asks the host for. Hosts may refuse.
- Tool
Output - What a tool produced.
- Visibility
- Who may call a tool.
Constants§
- MIN_
REQUEST_ STATE_ KEY_ BYTES - Minimum length of a
requestStatesigning key.
Traits§
- Extension
- A protocol extension supported by the server.
- Into
Content - Content that can appear in a message:
&str,String(as text) and the specification’s content types. - Into
Prompt Result - Conversion of a prompt’s return value into a result.
- Into
Resource Contents - Conversion of a resource handler’s return value into contents.
- Into
Tool Error - Conversion of tool errors. Implemented for
ToolErrorand for everystd::error::Error(treated as internal). - Into
Tool Result - Conversion of a tool’s return value into a result.
- Prompt
- A prompt that can be registered with
ServerBuilder::prompt. - Resource
- A resource that can be registered with
ServerBuilder::resource. - Token
Verifier - Checks an access token and identifies its holder.
- Tool
- A tool that can be registered with
ServerBuilder::tool.
Type Aliases§
- Complete
Fn - A completion provider. Completion runs synchronously and must be fast.
- Resource
Contents - One item of a
resources/readresult. - Tool
Result - The outcome of a tool invocation.