Skip to main content

Module mcp_server

Module mcp_server 

Source
Expand description

MCP server lifecycle management.

This module provides McpServerManager, which handles spawning MCP servers (stdio or HTTP+SSE), discovering their tools, and registering them into the agent’s ToolRegistry. Each MCP tool is wrapped in a thin adapter that delegates execution to the corresponding server.

§Architecture

┌─────────────────────────────────────────────┐
│              McpServerManager               │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  │
│  │ Server A │  │ Server B │  │ Server C │  │
│  │ (stdio)  │  │ (SSE)    │  │ (stdio)  │  │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘  │
│       │              │              │        │
│  ┌────▼──────────────▼──────────────▼────┐  │
│  │          ToolRegistry                 │  │
│  │  mcp__A__tool1  mcp__B__tool2  ...    │  │
│  └───────────────────────────────────────┘  │
└─────────────────────────────────────────────┘

Structs§

JsonRpcError
A JSON-RPC 2.0 error object.
JsonRpcRequest
A JSON-RPC 2.0 request.
JsonRpcResponse
A JSON-RPC 2.0 response.
McpServerManager
Manages the lifecycle of one or more MCP servers and their tools.
McpServerRunner
Runs the MCP server stdio loop: reads JSON-RPC from stdin, dispatches, and writes responses to stdout.

Functions§

dispatch_request
Dispatch a parsed JSON-RPC request and return a response. Returns None for notifications (no response needed).