Skip to main content

Module mcp

Module mcp 

Source
Expand description

MCP (Model Context Protocol) server framework.

Provides a JSON-RPC 2.0 dispatch layer for building MCP servers in Rust. Supports both stdio and HTTP transports.

§Quick start

use llm_kernel::mcp::{McpServer, ToolDescription, JsonRpcDispatcher};

let mut server = McpServer::new("my-server", "1.0.0");

server.register_tool(ToolDescription {
    name: "greet".into(),
    description: "Say hello".into(),
    input_schema: serde_json::json!({
        "type": "object",
        "properties": {
            "name": { "type": "string" }
        }
    }),
});

server.set_handler("greet", |_params| {
    Ok(serde_json::json!({ "greeting": "Hello!" }))
});

// Route a JSON-RPC request through the stdio dispatcher.
let dispatcher = JsonRpcDispatcher::new(&server);
let response = dispatcher
    .dispatch(r#"{"jsonrpc":"2.0","id":1,"method":"tools/list"}"#)
    .unwrap();
assert!(response.contains("greet"));

Re-exports§

pub use auth::BearerAuth;
pub use schema::PromptArgument;
pub use schema::PromptDescription;
pub use schema::ResourceDescription;
pub use schema::ToolDescription;
pub use server::AsyncToolHandler;
pub use server::Handler;
pub use server::LATEST_PROTOCOL_VERSION;
pub use server::McpServer;
pub use server::SUPPORTED_PROTOCOL_VERSIONS;
pub use transport::JsonRpcDispatcher;
pub use http::HttpTransport;
pub use http::serve;

Modules§

auth
Bearer token authentication for MCP servers.
http
HTTP/SSE remote transport for MCP (axum + tokio). HTTP/SSE remote transport for MCP.
schema
Tool, resource, and prompt schema definitions for MCP.
server
MCP server core — tool registration, initialization, and dispatch logic.
transport
JSON-RPC 2.0 transport and dispatch for MCP.

Enums§

McpNotification
MCP notification types for server-initiated messages.