Skip to main content

Crate flymcprust

Crate flymcprust 

Source
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

FeatureDefaultDescription
macrosyesThe tool, resource and prompt attribute macros.
stdionostdio transport (Server::serve_stdio).
httpnoStreamable HTTP transport (transport::http).
oauthnoauth::JwtVerifier for OAuth access tokens (implies http).
auto-registernoServerBuilder::auto_tools (and auto_resources, auto_prompts) collect every annotated item.
loggingnologging::init() writes the log, with fix-it hints, to stderr.
test-clientnoIn-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_VALUES are truncated, with total and hasMore set accordingly.
CompletionRequest
What the client asked to complete.
Ctx
Context of the request being handled. Declare a Ctx parameter 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 outputSchema is generated from T, and the result carries both structuredContent and 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.
MirroredParam
A tool parameter mirrored into an Mcp-Param-{name} header.
Principal
The caller authenticated by an access token.
PromptArguments
The arguments of a prompts/get request.
PromptDef
A registered prompt: its protocol description plus its entry point.
ResourceDef
A registered resource or resource template.
Server
A built MCP server. Cheap to clone; all clones share one registry.
ServerBuilder
Builds a Server.
State
Shared application state registered with ServerBuilder::state. Declare a State<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 makes ServerBuilder::build fail.
TokenError
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.
ToolError
An error raised by a tool, resource or prompt handler.
TransportContext
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.
UriTemplateError
A template that cannot be parsed or is not supported.
UriVars
Variable values extracted from a URI by UriTemplate::matches.

Enums§

BuildError
Errors detected while building a server.
Elicitation
The outcome of an elicitation.
ErrorKind
How an error relates to the request, independent of transport. HTTP uses it to pick a status code (400, 404, 200 or 500).
ParamKind
JSON Schema primitive type of a mirrored parameter.
Permission
A browser capability a UI asks the host for. Hosts may refuse.
ToolOutput
What a tool produced.
Visibility
Who may call a tool.

Constants§

MIN_REQUEST_STATE_KEY_BYTES
Minimum length of a requestState signing key.

Traits§

Extension
A protocol extension supported by the server.
IntoContent
Content that can appear in a message: &str, String (as text) and the specification’s content types.
IntoPromptResult
Conversion of a prompt’s return value into a result.
IntoResourceContents
Conversion of a resource handler’s return value into contents.
IntoToolError
Conversion of tool errors. Implemented for ToolError and for every std::error::Error (treated as internal).
IntoToolResult
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.
TokenVerifier
Checks an access token and identifies its holder.
Tool
A tool that can be registered with ServerBuilder::tool.

Type Aliases§

CompleteFn
A completion provider. Completion runs synchronously and must be fast.
ResourceContents
One item of a resources/read result.
ToolResult
The outcome of a tool invocation.

Attribute Macros§

prompt
Turns a free function (sync or async) into an MCP prompt.
resource
Turns a free function (sync or async) into an MCP resource or resource template.
tool
Turns a free function (sync or async) into an MCP tool.