Source Code:
src/gaia/mcp/agent_mcp_server.pyComponent: AgentMCPServer - Generic MCP Server for MCPAgent Subclasses
Module:
gaia.mcp.agent_mcp_server
Protocol: Model Context Protocol (MCP) via MCPServer (mcp 2.x)
Transport: Streamable HTTP (SSE)Overview
AgentMCPServer is a generic wrapper that exposes any MCPAgent subclass as an MCP server using the MCP Python SDK’sMCPServer class. It dynamically registers tools from the agent and handles parameter mapping between MCP clients (like VSCode) and agent implementations.
Key Features:
- Generic wrapper for any MCPAgent
- Dynamic tool registration from agent
- Parameter mapping (VSCode ↔ Agent)
- Streamable HTTP transport (SSE)
- Verbose logging for debugging
- Zero-config for agents
Requirements
Functional Requirements
-
Agent Wrapping
- Accept any MCPAgent subclass
- Initialize agent with custom parameters
- Validate agent inheritance
-
Tool Registration
- Dynamically register tools from
get_mcp_tool_definitions() - Create async wrapper functions
- Map MCP schemas to Python functions
- Handle **kwargs for flexible parameter passing
- Dynamically register tools from
-
Parameter Mapping
- Handle VSCode’s nested
kwargswrapper - Parse stringified JSON
- Map parameter name variations (app_dir → appPath)
- Log parameter transformations
- Handle VSCode’s nested
-
Server Management
- Start MCPServer with streamable-http
- Configure host/port
- Display startup banner
- Handle graceful shutdown
API Specification
AgentMCPServer Class
MCP Transport
Protocol: Streamable HTTP (industry standard) Endpoint:http://{host}:{port}/mcp
Methods:
- HTTP POST: Request/response
- SSE: Server-sent events for streaming
Implementation Details
Dynamic Tool Registration
Parameter Mapping
Problem: VSCode/Copilot wraps parameters differently than agents expect. Solutions:- Nested kwargs wrapper:
- Parameter name variations:
Startup Banner
Testing Requirements
Unit Tests
Integration Tests
Dependencies
Usage Examples
Example 1: Start an MCP Server for Your Agent
Example 2: Wrap a Custom MCPAgent
Any subclass ofMCPAgent can be served — agent_class is validated against
MCPAgent at construction, so the agent must implement
get_mcp_tool_definitions() and execute_mcp_tool().
Example 3: CLI Wrapper
Related Specifications
- mcp-agent - MCPAgent interface
- electron-integration - Electron MCP client
AgentMCPServer Technical Specification