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 FastMCP
Transport: Streamable HTTP (SSE)Overview
AgentMCPServer is a generic wrapper that exposes any MCPAgent subclass as an MCP server using the MCP Python SDK (FastMCP). 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 FastMCP server 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 Docker MCP Server
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
- docker-agent - Example agent using MCP
- electron-integration - Electron MCP client
AgentMCPServer Technical Specification