Source Code:
Import:
from gaia.mcp import MCPClientMixin, MCPClient, MCPClientManagerWhat is MCP?
MCP (Model Context Protocol) is a universal connector that lets any AI application talk to any tool — a standard created by Anthropic. Instead of building custom integrations for each service, agents connect to MCP servers that expose tools likeread_file, create_issue, or query_database.
MCPClientMixin adds this capability to any GAIA agent — mix it in, point it at a server, and that server’s tools become available automatically.
Architecture
Quick Start
Connect Multiple Servers
Connect to as many servers as needed. GAIA prefixes each tool with the server name (e.g.,mcp_filesystem_read_file, mcp_github_create_issue) so tools from different servers never collide.
Load from Config
A configuration file lets you manage MCP servers without changing agent code. On startup, GAIA automatically stacks two config files — one global default, one project-specific — so you never have to choose between them.Config stacking
GAIA loads configs in order of increasing priority:| Priority | File | Purpose |
|---|---|---|
| 1 (base) | ~/.gaia/mcp_servers.json | Global defaults — shared across all agents |
| 2 (override) | ./mcp_servers.json | Project-specific — wins on any key conflict |
Config file format
Using config in your agent
By default,MCPClientMixin.__init__() auto-loads both config files:
config_file is provided, only that file is loaded — global and local stacking are disabled. Loading is always triggered when config_file is set, regardless of the auto_load_config flag.
Popular Servers
- Filesystem
- GitHub
- Python Servers
Direct Client Usage
MCPClient is the lower-level building block for use outside of agents — in standalone scripts, test suites, or custom pipelines.
MCPClient only supports stdio transport (subprocess-based). HTTP and SSE transports are not supported at this time.Error Handling
GAIA’s MCP client uses a return-value error model rather than raising exceptions for expected failures.API Reference
MCPClientMixin
| Method | Description |
|---|---|
connect_mcp_server(name, config) | Connect and register tools. Returns bool. |
disconnect_mcp_server(name) | Disconnect and unregister |
list_mcp_servers() | List connected server names. Returns list[str]. |
get_mcp_client(name) | Get client instance. Returns MCPClient or None. |
load_mcp_servers_from_config() | Load from config file. Returns int (count). |
MCPClient
| Method | Description |
|---|---|
from_config(name, config) | Create client from config dict |
from_command(name, command) | Create client (legacy, shell string) |
connect() | Connect to server. Returns bool. |
disconnect() | Disconnect |
list_tools() | List available tools (cached). Returns list[MCPTool]. |
call_tool(name, args) | Execute a tool. Returns dict. |
CLI Commands
Security
- Review the source — Only use servers from trusted sources with public repositories
- Check permissions — Understand what system access the server requires
- Limit scope — Restrict filesystem servers to specific directories rather than
/ - Audit environment variables — Never pass secrets to servers you haven’t reviewed
Troubleshooting
Connection fails with 'command not found'
Connection fails with 'command not found'
The MCP server command (like
npx or uvx) isn’t in your PATH.Config file not found
Config file not found
load_mcp_servers_from_config() returns 0 servers. GAIA merges two config files at startup:~/.gaia/mcp_servers.json— global config, always checked./mcp_servers.json— local config, checked in the current working directory
Tools not appearing in agent
Tools not appearing in agent
- Verify connection:
print(agent.list_mcp_servers()) - List tools:
gaia mcp tools <server-name> - Enable debug:
import logging; logging.basicConfig(level=logging.DEBUG)
Server process hangs or times out
Server process hangs or times out
Some servers need initialization time:Test directly:
gaia mcp test-client <server-name>Related
- API Specification — Complete API reference
- Windows System Health Agent — Example MCP agent
- CLI Reference — CLI commands