Skip to main content

Crate mcp_kit

Crate mcp_kit 

Source
Expand description

§mcp — Rust library for building MCP servers

A high-quality, type-safe, async-first library for the Model Context Protocol.

§Quick start

use mcp_kit::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    McpServer::builder()
        .name("my-server")
        .version("1.0.0")
        .tool(
            Tool::new("greet", "Say hello", serde_json::json!({
                "type": "object",
                "properties": { "name": { "type": "string" } },
                "required": ["name"]
            })),
            |args: serde_json::Value| async move {
                CallToolResult::text(format!("Hello, {}!", args["name"]))
            },
        )
        .build()
        .serve_stdio()
        .await?;
    Ok(())
}

Re-exports§

pub use error::ErrorCode;
pub use error::ErrorData;
pub use error::McpError;
pub use error::McpResult;
pub use protocol::JsonRpcError;
pub use protocol::JsonRpcMessage;
pub use protocol::JsonRpcNotification;
pub use protocol::JsonRpcRequest;
pub use protocol::JsonRpcResponse;
pub use protocol::ProgressToken;
pub use protocol::RequestId;
pub use protocol::JSONRPC_VERSION;
pub use protocol::MCP_PROTOCOL_VERSION;
pub use types::content::AudioContent;
pub use types::content::BlobResourceContents;
pub use types::content::Content;
pub use types::content::EmbeddedResource;
pub use types::content::ImageContent;
pub use types::content::ResourceContents;
pub use types::content::TextContent;
pub use types::content::TextResourceContents;
pub use types::elicitation::ElicitAction;
pub use types::elicitation::ElicitRequest;
pub use types::elicitation::ElicitResult;
pub use types::elicitation::ElicitSchema;
pub use types::messages::CallToolRequest;
pub use types::messages::CompleteRequest;
pub use types::messages::CompleteResult;
pub use types::messages::CompletionArgument;
pub use types::messages::CompletionReference;
pub use types::messages::GetPromptRequest;
pub use types::messages::GetPromptResult;
pub use types::messages::InitializeRequest;
pub use types::messages::InitializeResult;
pub use types::messages::ListPromptsResult;
pub use types::messages::ListResourcesResult;
pub use types::messages::ListToolsResult;
pub use types::messages::ReadResourceRequest;
pub use types::messages::ReadResourceResult;
pub use types::prompt::Prompt;
pub use types::prompt::PromptArgument;
pub use types::prompt::PromptMessage;
pub use types::prompt::PromptMessageRole;
pub use types::resource::Resource;
pub use types::resource::ResourceTemplate;
pub use types::sampling::CreateMessageRequest;
pub use types::sampling::CreateMessageResult;
pub use types::sampling::ModelPreferences;
pub use types::sampling::SamplingMessage;
pub use types::tool::CallToolResult;
pub use types::tool::Tool;
pub use types::tool::ToolAnnotations;
pub use types::ClientCapabilities;
pub use types::ClientInfo;
pub use types::Implementation;
pub use types::LoggingLevel;
pub use types::ServerCapabilities;
pub use types::ServerInfo;
pub use server::builder::McpServerBuilder;
pub use server::builder::PromptDef;
pub use server::builder::ResourceDef;
pub use server::builder::ToolDef;
pub use server::core::McpServer;
pub use server::elicitation::ChannelElicitationClient;
pub use server::elicitation::ElicitationClient;
pub use server::elicitation::ElicitationClientExt;
pub use server::elicitation::ElicitationError;
pub use server::elicitation::ElicitationRequestBuilder;
pub use server::extract::Extension;
pub use server::extract::Json;
pub use server::extract::State;
pub use server::handler::CompletionHandler;
pub use server::handler::IntoToolResult;
pub use server::handler::ToolHandler;
pub use server::notification::NotificationReceiver;
pub use server::notification::NotificationSender;
pub use server::notification::SendError;
pub use server::notification::SharedNotificationSender;
pub use server::progress::ProgressTokenExt;
pub use server::progress::ProgressTracker;
pub use server::session::Session;
pub use server::Auth;
pub use server::AuthenticatedMarker;
pub use auth::AuthProvider;
pub use auth::AuthenticatedIdentity;
pub use auth::CompositeAuthProvider;
pub use auth::Credentials;
pub use auth::DynAuthProvider;
pub use auth::IntoDynProvider;
pub use auth::BearerTokenProvider;
pub use auth::ApiKeyProvider;
pub use auth::BasicAuthProvider;
pub use auth::CustomHeaderProvider;
pub use transport::stdio::ServeStdioExt;
pub use transport::stdio::StdioTransport;
pub use transport::sse::ServeSseExt;
pub use transport::sse::SseTransport;
pub use transport::streamable::ServeStreamableExt;
pub use transport::streamable::StreamableTransport;
pub use transport::websocket::ServeWebSocketExt;
pub use transport::websocket::WebSocketTransport;
pub use schemars;
pub use serde_json;
pub use tokio;

Modules§

auth
Authentication support for MCP servers.
error
plugin
Plugin system for dynamically loading and managing MCP tools, resources, and prompts.
prelude
Everything you need to build an MCP server — import with use mcp_kit::prelude::*.
protocol
server
transport
types

Traits§

Deserialize
A data structure that can be deserialized from any data format supported by Serde.
JsonSchema
A type which can be described as a JSON Schema document.
Serialize
A data structure that can be serialized into any data format supported by Serde.

Attribute Macros§

prompt
Marks an async function as an MCP prompt handler and generates a companion {fn_name}_prompt_def() function that returns a mcp::PromptDef.
resource
Marks an async function as an MCP resource handler and generates a companion {fn_name}_resource_def() function that returns a mcp::ResourceDef.
tool
Marks an async function as an MCP tool and generates a companion {fn_name}_tool_def() function that returns a mcp::ToolDef.

Derive Macros§

Deserialize
JsonSchema
Serialize