Skip to main content
Component: 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

  1. Agent Wrapping
    • Accept any MCPAgent subclass
    • Initialize agent with custom parameters
    • Validate agent inheritance
  2. 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
  3. Parameter Mapping
    • Handle VSCodeโ€™s nested kwargs wrapper
    • Parse stringified JSON
    • Map parameter name variations (app_dir โ†’ appPath)
    • Log parameter transformations
  4. 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
Configuration:

Implementation Details

Dynamic Tool Registration

Parameter Mapping

Problem: VSCode/Copilot wraps parameters differently than agents expect. Solutions:
  1. Nested kwargs wrapper:
  1. 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 of MCPAgent 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

Usage:


AgentMCPServer Technical Specification