mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
- 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
2.8 KiB
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
- Single block, not many blocks — One
MCPBlockhandles all MCP servers/tools - Dynamic schema via AgentExecutorBlock pattern — Override
get_input_schema(),get_input_defaults(),get_missing_input()on the Input class - Auth via API key or OAuth2 credentials — Use existing
APIKeyCredentialsorOAuth2CredentialswithProviderName.MCPprovider. API keys are sent as Bearer tokens; OAuth2 uses the access token. - HTTP-based MCP client — Use
aiohttp(already a dependency) to implement MCP Streamable HTTP transport directly. No need for themcpPython SDK — the protocol is simple JSON-RPC over HTTP. Handles both JSON and SSE response formats. - No new DB tables — Everything fits in existing
AgentBlock+AgentNodetables
Implementation Files
New Files
backend/blocks/mcp/— MCP block package__init__.pyblock.py— MCPToolBlock implementationclient.py— MCP HTTP client (list_tools, call_tool)oauth.py— MCP OAuth handler for dynamic endpoint discoverytest_mcp.py— Unit teststest_oauth.py— OAuth handler teststest_integration.py— Integration tests with local test servertest_e2e.py— E2E tests against real MCP servers
Modified Files
backend/integrations/providers.py— AddMCP = "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