Files
AutoGPT/autogpt_platform/backend/MCP_BLOCK_IMPLEMENTATION.md
Zamil Majdy 19b3373052 fix(mcp): Address PR review comments
- Fix get_missing_input/get_mismatch_error to validate tool_arguments
  dict instead of the entire BlockInput data (critical bug)
- Add type check for non-dict JSON-RPC error field in client.py
- Add try/catch for non-JSON responses in client.py
- Add raise_for_status and error payload checks to OAuth token requests
- Remove hardcoded placeholder skip-list from _extract_auth_token
- Fix server start timeout check in integration tests
- Remove unused MCPTool import, move execute_block_test to top-level
- Update tests to match fixed validation behavior
- Fix MCP_BLOCK_IMPLEMENTATION.md (remove duplicate section, local path)
- Soften PKCE comment in oauth.py
2026-02-08 19:34:28 +04:00

2.8 KiB

MCP Block Implementation Plan

Overview

Create a single MCPBlock that dynamically integrates with any MCP (Model Context Protocol) server. Users provide a server URL, the block discovers available tools, presents them as a dropdown, and dynamically adjusts input/output schema based on the selected tool — exactly like AgentExecutorBlock handles dynamic schemas.

Architecture

User provides MCP server URL + credentials
         ↓
MCPBlock fetches tools via MCP protocol (tools/list)
         ↓
User selects tool from dropdown (stored in constantInput)
         ↓
Input schema dynamically updates based on selected tool's inputSchema
         ↓
On execution: MCPBlock calls the tool via MCP protocol (tools/call)
         ↓
Result yielded as block output

Design Decisions

  1. Single block, not many blocks — One MCPBlock handles all MCP servers/tools
  2. Dynamic schema via AgentExecutorBlock pattern — Override get_input_schema(), get_input_defaults(), get_missing_input() on the Input class
  3. Auth via API key or OAuth2 credentials — Use existing APIKeyCredentials or OAuth2Credentials with ProviderName.MCP provider. API keys are sent as Bearer tokens; OAuth2 uses the access token.
  4. HTTP-based MCP client — Use aiohttp (already a dependency) to implement MCP Streamable HTTP transport directly. No need for the mcp Python SDK — the protocol is simple JSON-RPC over HTTP. Handles both JSON and SSE response formats.
  5. No new DB tables — Everything fits in existing AgentBlock + AgentNode tables

Implementation Files

New Files

  • backend/blocks/mcp/ — MCP block package
    • __init__.py
    • block.py — MCPToolBlock implementation
    • client.py — MCP HTTP client (list_tools, call_tool)
    • oauth.py — MCP OAuth handler for dynamic endpoint discovery
    • test_mcp.py — Unit tests
    • test_oauth.py — OAuth handler tests
    • test_integration.py — Integration tests with local test server
    • test_e2e.py — E2E tests against real MCP servers

Modified Files

  • backend/integrations/providers.py — Add MCP = "mcp" to ProviderName

Dev Loop

cd autogpt_platform/backend
poetry run pytest backend/blocks/mcp/test_mcp.py -xvs        # Unit tests
poetry run pytest backend/blocks/mcp/test_oauth.py -xvs       # OAuth tests
poetry run pytest backend/blocks/mcp/test_integration.py -xvs  # Integration tests
poetry run pytest backend/blocks/mcp/ -xvs                     # All MCP tests

Status

  • Research & Design
  • Add ProviderName.MCP
  • Implement MCP client (client.py)
  • Implement MCPToolBlock (block.py)
  • Add OAuth2 support (oauth.py)
  • Write unit tests
  • Write integration tests
  • Write E2E tests
  • Run tests & fix issues
  • Create PR