Skip to main content

Module server

Module server 

Source
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§

httphttp-server
HTTP transport for MCP Server.
stdiostdio-server
Stdio transport for MCP Server.

Structs§

McpServer
MCP Server with bidirectional async communication.
McpServerChannels
Channel handles for communicating with the McpServer.
McpServerConfig
Configuration for an MCP server.
McpServerConfigBuilder
Builder for creating MCP server configurations.

Enums§

ServerError
Errors that can occur when running an MCP server.
ServerStatus
Server status indicator.