Skip to content

MCP Client Support: Connect GAIA agents to any MCP server#277

Merged
itomek merged 75 commits intoamd:mainfrom
itomek:203-mcp-client-support-connect-gaia-agents-to-any-mcp-server
Feb 10, 2026
Merged

MCP Client Support: Connect GAIA agents to any MCP server#277
itomek merged 75 commits intoamd:mainfrom
itomek:203-mcp-client-support-connect-gaia-agents-to-any-mcp-server

Conversation

@itomek
Copy link
Collaborator

@itomek itomek commented Jan 28, 2026

Summary

Adds MCP (Model Context Protocol) client support to GAIA, enabling agents to connect to and consume tools from external MCP servers.

Key Features

  • MCPClientMixin: New mixin for agents to connect to MCP servers via stdio or HTTP transports
  • CLI Commands: gaia mcp client add/remove/list/test for managing MCP server connections
  • Configuration-based workflows: JSON config files for declarative MCP server management
  • Transport Layer: Support for stdio (subprocess) and HTTP (SSE) transports
  • Enhanced Error Handling: Detailed validation errors and user-friendly messages
  • Documentation: Complete guides, SDK reference, and specifications

Changes

  • New src/gaia/mcp/client/ module with MCPClient, MCPClientManager, and transport implementations
  • New src/gaia/agents/base/mcp_client_mixin.py for agent integration
  • CLI commands in src/gaia/cli.py for MCP client management
  • Examples: examples/mcp_config_based_agent.py and examples/mcp_multi_server_agent.py
  • Comprehensive test coverage in tests/unit/mcp/client/ and tests/mcp/
  • Documentation in docs/guides/mcp-client.mdx, docs/sdk/infrastructure/mcp-client.mdx, and docs/spec/mcp-client.mdx
  • Added Mintlify dev dependency for documentation development

Test Plan

  • Unit tests for MCP client, manager, and transports
  • Integration tests for CLI to agent workflows
  • SDK integration tests
  • Manual testing with real MCP servers (filesystem, memory, etc.)
  • Verify documentation renders correctly on amd-gaia.ai
  • Test error handling with invalid configurations
  • Test concurrent multi-server connections

🤖 Generated with Claude Code

@itomek itomek linked an issue Jan 28, 2026 that may be closed by this pull request
@github-actions github-actions bot added documentation Documentation changes agents Agent system changes mcp MCP integration changes cli CLI changes tests Test changes dependencies Dependency updates labels Jan 28, 2026
@itomek itomek self-assigned this Jan 29, 2026
@itomek itomek added this to the v0.15.4 milestone Jan 29, 2026
@itomek itomek marked this pull request as ready for review January 29, 2026 19:51
@kovtcharov
Copy link
Collaborator

@claude review this PR.

@github-actions
Copy link

github-actions bot commented Jan 29, 2026

Claude finished @kovtcharov's task —— View job


PR Review in Progress

  • Read PR diff and changed files
  • Review MCP client core implementation
  • Review transport layer (stdio, HTTP)
  • Review MCPClientMixin for agent integration
  • Review CLI commands
  • Review tests
  • Review documentation
  • Provide comprehensive review feedback

@itomek itomek enabled auto-merge January 29, 2026 22:21
@itomek itomek disabled auto-merge February 2, 2026 17:40
@itomek itomek marked this pull request as draft February 2, 2026 17:40
@github-actions github-actions bot added the devops DevOps/infrastructure changes label Feb 4, 2026
itomek and others added 12 commits February 3, 2026 20:56
Implemented Option 2 (enhanced error messages) with TDD approach and
fixed documentation issues in MCP client guide and CLI reference.

Features:
- Enhanced MCP validation error messages (TDD approach)
  * Detects JSON-RPC validation errors (code -32602)
  * Shows complete tool schema in error output
  * Shows arguments that were provided
  * Helps LLM self-correct input validation issues
  * No new dependencies required

- Documentation improvements
  * Updated Quick Start to use 'time' server (cross-platform)
  * Added explanation of 'gaia mcp add' command
  * Clarified command format with quotes
  * Added --config flag documentation throughout
  * Added MCP Client commands section to CLI reference
  * Verified all documentation links work

Changes:
- src/gaia/mcp/client/mcp_client.py: Enhanced error formatting
- tests/unit/mcp/client/test_mcp_client.py: 5 new tests
- docs/guides/mcp-client.mdx: Updated examples and CLI commands
- docs/reference/cli.mdx: Added MCP Client commands section

Testing:
- All 49 unit tests pass
- All 8 integration tests pass
- Both examples verified working
- No regressions

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Update docs package.json to use mintlify dev server for local development.
The start script now runs `mintlify dev` instead of the Node.js proxy server.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Update title from "MCP Client Guide" to "MCP Client" for consistency
- Add example links at top of guide for quick reference
- Fix footer format to match other guides (standard copyright)
- Add database-mixin to SDK navigation (Mixins & Utilities)
- Document gaia mcp test-client CLI command in reference
- Clean up spec file formatting and footer

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Provide single-file, copy-pasteable example matching working patterns
- Include proper initialization (skip_lemonade, explicit __init__ calls)
- Add system prompt rebuilding for MCP tool registration
- Show expected output for better user experience
- Use process_query instead of run for consistency with examples
- Add tip pointing to production config-based pattern

Fixes incomplete Quick Start that caused NameError when users tried to
follow the guide. Now provides a fully working example users can run
immediately without modifications.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
The previous Quick Start was broken because it lacked the JSON response
format instructions that the Agent base class requires for tool calling.
Without these instructions, the LLM outputs tool calls as text instead
of executing them.

Changes:
- Add complete response format instructions to _rebuild_system_prompt
- Include tool calling JSON schema and rules
- Update expected output to show actual tool execution
- Make it clear this is a complete, working example

This matches the pattern used in working examples like
mcp_multi_server_agent.py and mcp_config_based_agent.py.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Simplified mcp_config_based_agent.py from 195 to 64 lines
  - Reduced docstring from 43 to 3 lines
  - Removed verbose print statements and status output
  - Added silent_mode=True for clean console output

- Changed MCP client logging from INFO to DEBUG
  - mcp_client_manager.py: 8 log level changes
  - mcp_client.py: 4 log level changes
  - mcp_client_mixin.py: 5 log level changes
  - Now only shows essential output by default

- Updated MCP client guide documentation
  - Replaced verbose examples with actual clean output
  - Fixed prerequisites to require [mcp] extra
  - Added [mcp,dev] option for development

- Fixed setup.py missing packages
  - Added gaia.mcp.client
  - Added gaia.mcp.client.transports

Example now produces clean output:
Connected: memory, thinking, time
Agent: The current time in Tokyo is 11:59 PM...
- Added Step 2 to setup.mdx for Node.js installation via NVM
  - Windows: winget or manual download from GitHub
  - Linux: curl script from nvm-sh/nvm
  - Version: 20.20.0 (latest LTS with January 2026 security fixes)

- Updated system requirements table with Node.js as optional

- Added .nvmrc file with v20.20.0

- Updated MCP client guide prerequisites
  - Added example of npm-based MCP server command
  - Links to setup guide for NVM installation

- Added prerequisites table to MCP client spec
  - Documents GAIA [mcp] and Node.js dependencies
Phase 0: File Reorganization
- Move mcp_client_mixin.py to src/gaia/mcp/mixin.py (follows database mixin pattern)
- Update imports across codebase (examples, tests, docs)
- Reorganize docs.json navigation:
  - SDK Reference: Move mcp-client to SDKs group
  - Specifications: Move mcp-agent to Core Framework
  - Specifications: Move mcp-server to SDKs group
  - Specifications: Move mcp-client to Tool Mixins, rename to "MCP Tool Mixin"

Phase 1: Automatic System Prompt Rebuild
- Add rebuild_system_prompt() method to Agent base class
- Automatically called in Agent.__init__ after tool registration
- MCPClientMixin auto-calls rebuild after connecting MCP servers
- ChatAgent simplified to use base class method
- Remove manual _rebuild_system_prompt() from examples and tests

This eliminates the need for users to manually rebuild system prompts when
dynamically adding MCP tools or indexing documents.

Changes: 20 files, -406/+160 lines
Tests: 49/49 unit, 9/9 integration pass

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
High priority fixes:
- Clarify only stdio transport is currently supported (HTTP exists but not integrated)
- Add missing load_mcp_servers_from_config() method documentation
- Document call_tool() error response format

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Following patterns from chat.mdx and llm.mdx:
- Add quick reference header with navigation links
- Add source code info box (updated to src/gaia/mcp/mixin.py)
- Add import statement note
- Add development badge
- Add comprehensive code examples:
  - Connect multiple servers
  - Load servers from config
  - Direct client usage (without agent)
  - Using MCPClientManager
  - Enhanced error handling
  - Enhanced debug mode
- Add copyright footer

Expanded from 160 to 332 lines.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Navigation fixes (docs.json):
- Add MCP Client SDK to SDK Reference → Mixins & Utilities
- Move spec/mcp-agent from Core Framework to Agents & Apps
- Move spec/routing-agent from Infrastructure to Agents & Apps

Spec fixes (spec/mcp-client.mdx):
- Remove icon: "plug" (no other tool mixins have icons)

Guide fixes (guides/mcp-client.mdx):
- Rename "For Team Projects" → "Example 1: Project-Level Config"
- Rename "For Personal Use" → "Example 2: User-Level Config"
- Remove team/personal labels from benefits section
- Remove manual _rebuild_system_prompt() calls (automated in Phase 1)
- Add comments about automatic system prompt updates

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Removed sections (moved to SDK reference):
- Python SDK Examples (~100 lines) - Multiple code patterns
- Configuration (~58 lines) - Agent-level and global config

Kept sections:
- Complete Examples - Tutorial-style setup guide (recently cleaned up)

Result: 711 → 553 lines (trimmed 158 lines)

The guide now focuses on getting started, concepts, and step-by-step
tutorials. Detailed SDK patterns belong in docs/sdk/infrastructure/mcp-client.mdx.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@kovtcharov-amd
Copy link
Collaborator

kovtcharov-amd commented Feb 10, 2026

Please revert docs/package-lock.json when you get the chance to avoid checking in 14k LoCs. Going to approve now to unblock you.

@kovtcharov-amd
Copy link
Collaborator

kovtcharov-amd commented Feb 10, 2026

@claude review the comments and code but avoid reviewing anything related to docs/package-lock.json.

@github-actions
Copy link

github-actions bot commented Feb 10, 2026

Claude finished @kovtcharov-amd's task —— View job


PR Review Complete

  • Read PR diff and review comments
  • Review MCP client core implementation
  • Review transport layer (stdio, HTTP)
  • Review MCPClientMixin for agent integration
  • Review CLI commands
  • Review tests
  • Review documentation (excluding package-lock.json)
  • Provide comprehensive review feedback

Summary

This is a well-structured PR that adds MCP client support to GAIA. The implementation follows GAIA patterns well and has good test coverage. Most of the previous review comments from @kovtcharov have been addressed.

Code Quality: 🟢 Good

Strengths

  1. Clean Architecture - Clear separation between transport layer, client, manager, and mixin
  2. Good Error Handling - Validation errors include schema context for debugging (_format_validation_error in mcp_client.py:226-259)
  3. GAIA Pattern Compliance - Tool responses are wrapped in standard GAIA format with status/message/data/instruction fields (mixin.py:217-240)
  4. Comprehensive Tests - Unit tests cover schema conversion, connection handling, tool registration/unregistration

Minor Issues

🟡 HTTP Transport Not Exposed (src/gaia/mcp/client/transports/http.py)

  • HTTP transport is implemented but the mixin explicitly blocks non-stdio transports (mixin.py:84-90)
  • The documentation says "only stdio is supported" but HTTP is ready
  • Recommendation: Either expose HTTP transport or document it as "coming soon" in the spec

🟡 Hardcoded Version (mcp_client.py:151)

"version": "0.15.2"
  • Consider importing version from a central location

🟢 Console Print Fallback (mixin.py:48-59)

  • Good defensive coding with _console_print() fallback to logger

Outstanding Review Comments

Based on the review thread, these items from @kovtcharov may still need attention:

  1. docs/package-lock.json - Per @kovtcharov-amd's comment, this should be reverted to avoid adding 14k+ LoC

  2. Documentation structure - @kovtcharov suggested creating an MCP subfolder in guides (which was done: docs/guides/mcp/) ✅

  3. CLI SDK for examples (examples/mcp_config_based_agent.py:40-47) - @kovtcharov suggested building a CLI SDK for interactive examples, but this is likely a future enhancement

  4. HTTP transport documentation - @kovtcharov asked why HTTP transport exists but isn't supported. The code shows HTTP is implemented but blocked. Should either:

    • Enable HTTP support in the mixin
    • Or clearly document it as "stdio only, HTTP coming soon"
  5. Security warning for MCP servers - @kovtcharov requested a security section warning users about adding untrusted MCP servers. Worth adding to the user guide.

Test Coverage: 🟢 Good

  • tests/unit/mcp/client/test_mcp_client.py - Schema conversion, factory methods, connection handling
  • tests/unit/mcp/client/test_mcp_client_mixin.py - Tool registration, multi-server namespacing
  • tests/unit/mcp/client/test_transports.py - Transport layer tests
  • tests/mcp/test_mcp_cli_to_agent_workflow.py - End-to-end CLI integration

Documentation: 🟢 Well-Documented

  • User guide (docs/guides/mcp/client.mdx) - Clear quickstart with mermaid diagrams
  • SDK reference (docs/sdk/sdks/mcp.mdx) - API snippets
  • Specification (docs/spec/mcp-client.mdx) - Complete technical reference

The ASCII diagram in the spec (mcp-client.mdx:43-79) should be converted to mermaid per @kovtcharov's review comment.

Recommendation

Approve with minor suggestions:

  1. Revert docs/package-lock.json (per @kovtcharov-amd)
  2. Consider enabling HTTP transport or updating docs to clarify its status
  3. Add security warning section about untrusted MCP servers

@itomek itomek added this pull request to the merge queue Feb 10, 2026
Merged via the queue into amd:main with commit 290fb13 Feb 10, 2026
43 checks passed
@itomek itomek deleted the 203-mcp-client-support-connect-gaia-agents-to-any-mcp-server branch February 10, 2026 21:55
kovtcharov-amd pushed a commit that referenced this pull request Feb 10, 2026
## Summary
- Add release notes for v0.15.4 documenting MCP client support and other
enhancements
- Bump version from 0.15.3.2 to 0.15.4

## Context
The release notes commit was made after PR #277 (MCP Client Support) was
merged and needs to be brought into main separately.

## Changes
- `docs/releases/v0.15.4.mdx` — new release notes page
- `docs/docs.json` — add v0.15.4 to navigation
- `src/gaia/version.py` — bump version to 0.15.4

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent system changes cli CLI changes dependencies Dependency updates devops DevOps/infrastructure changes documentation Documentation changes mcp MCP integration changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP Client Support: Connect GAIA agents to any MCP server

3 participants