Expand description
MCP Server with bidirectional async communication.
This module provides a transport-agnostic McpServer core that communicates
via channels. Transport-specific servers (McpStdioServer, McpHttpServer)
wrap this core and handle the actual I/O.
§Architecture
┌─────────────────────────────────────────────────────────────────┐
│ McpServer (core) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Inbound │ │ Message │ │ Outbound │ │
│ │ Receiver │────▶│ Loop │────▶│ Sender │ │
│ │ (ClientIn) │ │ (Task) │ │ (ServerOut) │ │
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
│ ▲ │ │ │
│ │ │ ▼ │
│ │ ┌─────┴─────┐ ┌──────────────┐ │
│ │ │ Pending │ │ Channels │ │
│ │ │ Requests │ │ Handle │ │
│ │ │ (oneshot) │ └──────────────┘ │
│ │ └───────────┘ │ │
└─────────┼──────────────────────────────────────────┼────────────┘
│ │
│ ▼
┌─────────┴──────────────────────────────────────────────────────┐
│ Transport Server │
│ (McpStdioServer / McpHttpServer) │
│ │
│ ┌──────────────┐ ┌──────────────────┐ │
│ │ I/O │ │ I/O │ │
│ │ Reader │ │ Writer │ │
│ │ (stdin/HTTP)│ │ (stdout/HTTP) │ │
│ └──────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────────┘§Example
ⓘ
use mcp::server::{McpServer, McpServerConfig};
use mcp::server::stdio::McpStdioServer;
let config = McpServerConfig::builder()
.name("my-server")
.version("1.0.0")
.with_tool(MyTool)
.build();
// Run via stdio transport
McpStdioServer::run(config).await?;Modules§
Structs§
- McpServer
- MCP Server with bidirectional async communication.
- McpServer
Channels - Channel handles for communicating with the McpServer.
- McpServer
Config - Configuration for an MCP server.
- McpServer
Config Builder - Builder for creating MCP server configurations.
Enums§
- Server
Error - Errors that can occur when running an MCP server.
- Server
Status - Server status indicator.