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::messages::CallToolRequest;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::extract::Extension;pub use server::extract::Json;pub use server::extract::State;pub use server::handler::IntoToolResult;pub use server::handler::ToolHandler;pub use server::session::Session;pub use transport::stdio::ServeStdioExt;pub use transport::stdio::StdioTransport;pub use transport::sse::ServeSseExt;pub use transport::sse::SseTransport;pub use schemars;pub use serde_json;pub use tokio;
Modules§
- error
- 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.
- Json
Schema - 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 amcp::PromptDef. - resource
- Marks an async function as an MCP resource handler and generates a companion
{fn_name}_resource_def()function that returns amcp::ResourceDef. - tool
- Marks an async function as an MCP tool and generates a companion
{fn_name}_tool_def()function that returns amcp::ToolDef.