feat(skill): add MCP adapter for external tools #434

Merged
aditya merged 6 commits from feature/m3-mcp-adapter into master 2026-02-27 07:28:15 +00:00
Member

Summary

Implement MCP adapter runtime (issue #159) that connects to external MCP servers, enumerates their tools, and registers them in ToolRegistry with source=mcp.

Changes

Core Implementation (src/cleveragents/tool/mcp_adapter.py)

  • McpAdapter: manages connection lifecycle (connect, disconnect, reconnect) for stdio, SSE, and streamable-http transports with configurable timeouts
  • McpToolInstance: implements the four-stage ToolInstance protocol (discover, activate, execute, deactivate) for MCP-sourced tools
  • McpToolDescriptor: intermediate mapping from MCP SDK Tool objects to internal schema, extracting capability flags from MCP ToolAnnotations (readOnlyHint → read_only, destructiveHint → writes, idempotentHint → idempotent)
  • map_mcp_tool_to_spec: converts descriptors to ToolSpec with source="mcp" and populated source_metadata
  • register_mcp_tools: end-to-end pipeline that discovers, filters (include/exclude), and registers tools
  • Error hierarchy: McpAdapterError → McpConnectionError, McpToolNotFoundError, McpInvocationError, McpTimeoutError
  • _AsyncBridge: background daemon thread for bridging async MCP SDK to sync ToolInstance protocol

Dependency

  • Added mcp>=1.0.0 to pyproject.toml

Tests

  • Behave: 23 scenarios in features/mcp_adapter.feature covering connection lifecycle, tool discovery, annotation mapping, invocation, error handling, filtering, ToolSpec mapping, ToolInstance protocol, and registry integration
  • Robot: 10 E2E test cases in robot/mcp_adapter.robot with robot/helper_mcp_adapter.py helper
  • ASV: 6 benchmark suites in benchmarks/mcp_runtime_bench.py

Documentation

  • docs/reference/mcp_adapter.md: architecture, configuration, lifecycle, transports, schema mapping, invocation, error handling, async bridge

Closes #159

## Summary Implement MCP adapter runtime (issue #159) that connects to external MCP servers, enumerates their tools, and registers them in ToolRegistry with `source=mcp`. ## Changes ### Core Implementation (`src/cleveragents/tool/mcp_adapter.py`) - **McpAdapter**: manages connection lifecycle (connect, disconnect, reconnect) for stdio, SSE, and streamable-http transports with configurable timeouts - **McpToolInstance**: implements the four-stage ToolInstance protocol (discover, activate, execute, deactivate) for MCP-sourced tools - **McpToolDescriptor**: intermediate mapping from MCP SDK Tool objects to internal schema, extracting capability flags from MCP ToolAnnotations (readOnlyHint → read_only, destructiveHint → writes, idempotentHint → idempotent) - **map_mcp_tool_to_spec**: converts descriptors to ToolSpec with source="mcp" and populated source_metadata - **register_mcp_tools**: end-to-end pipeline that discovers, filters (include/exclude), and registers tools - **Error hierarchy**: McpAdapterError → McpConnectionError, McpToolNotFoundError, McpInvocationError, McpTimeoutError - **_AsyncBridge**: background daemon thread for bridging async MCP SDK to sync ToolInstance protocol ### Dependency - Added `mcp>=1.0.0` to `pyproject.toml` ### Tests - **Behave**: 23 scenarios in `features/mcp_adapter.feature` covering connection lifecycle, tool discovery, annotation mapping, invocation, error handling, filtering, ToolSpec mapping, ToolInstance protocol, and registry integration - **Robot**: 10 E2E test cases in `robot/mcp_adapter.robot` with `robot/helper_mcp_adapter.py` helper - **ASV**: 6 benchmark suites in `benchmarks/mcp_runtime_bench.py` ### Documentation - `docs/reference/mcp_adapter.md`: architecture, configuration, lifecycle, transports, schema mapping, invocation, error handling, async bridge ## Closes #159
aditya added this to the v3.1.0 milestone 2026-02-25 14:24:16 +00:00
Implement MCPToolAdapter to connect to external MCP servers, enumerate
tools, and register them in ToolRegistry with source="mcp". Includes
connect/reconnect/disconnect lifecycle with timeout enforcement, input
validation on invoke, capability inference, Behave/Robot/ASV tests, and
docs/reference/mcp_adapter.md.

ISSUES CLOSED: #159
refactor(mcp): fix mock placement, type annotation, and constructor validation
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / build (pull_request) Successful in 16s
CI / typecheck (pull_request) Successful in 30s
CI / quality (pull_request) Successful in 32s
CI / security (pull_request) Successful in 34s
CI / integration_tests (pull_request) Successful in 3m24s
CI / unit_tests (pull_request) Successful in 10m40s
CI / docker (pull_request) Successful in 1m4s
CI / benchmark-regression (pull_request) Successful in 19m50s
CI / coverage (pull_request) Successful in 28m33s
2f9707cfdf
- Extract MockMCPTransport to features/mocks/mock_mcp_transport.py
- Use ToolRegistry type with TYPE_CHECKING in register_tools()
- Move transport config validation into __init__ via _validate_config()
CoreRasurae approved these changes 2026-02-25 15:07:21 +00:00
Dismissed
CoreRasurae left a comment

All tests passing, approved!

All tests passing, approved!
freemo changed title from feature/m3-mcp-adapter to feat(skill): add MCP adapter for external tools 2026-02-25 18:12:28 +00:00
Merge branch 'master' into feature/m3-mcp-adapter
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / quality (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 21s
CI / build (pull_request) Successful in 21s
CI / security (pull_request) Successful in 50s
CI / typecheck (pull_request) Successful in 59s
CI / integration_tests (pull_request) Successful in 4m18s
CI / unit_tests (pull_request) Successful in 10m11s
CI / docker (pull_request) Successful in 59s
CI / benchmark-regression (pull_request) Successful in 20m36s
CI / coverage (pull_request) Successful in 36m7s
519e26fb02
aditya dismissed CoreRasurae's review 2026-02-26 06:50:17 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

Merge branch 'master' into feature/m3-mcp-adapter
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / quality (pull_request) Successful in 18s
CI / build (pull_request) Successful in 16s
CI / lint (pull_request) Successful in 21s
CI / typecheck (pull_request) Successful in 37s
CI / security (pull_request) Successful in 53s
CI / integration_tests (pull_request) Successful in 5m11s
CI / unit_tests (pull_request) Successful in 20m32s
CI / docker (pull_request) Successful in 1m2s
CI / benchmark-regression (pull_request) Successful in 22m28s
CI / coverage (pull_request) Successful in 54m49s
595cfd172f
CoreRasurae approved these changes 2026-02-26 16:05:52 +00:00
Dismissed
CoreRasurae left a comment

Tests passing, changelog updated, documentation updated. Looks good. Approving

Tests passing, changelog updated, documentation updated. Looks good. Approving
brent.edwards force-pushed feature/m3-mcp-adapter from 595cfd172f
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / quality (pull_request) Successful in 18s
CI / build (pull_request) Successful in 16s
CI / lint (pull_request) Successful in 21s
CI / typecheck (pull_request) Successful in 37s
CI / security (pull_request) Successful in 53s
CI / integration_tests (pull_request) Successful in 5m11s
CI / unit_tests (pull_request) Successful in 20m32s
CI / docker (pull_request) Successful in 1m2s
CI / benchmark-regression (pull_request) Successful in 22m28s
CI / coverage (pull_request) Successful in 54m49s
to 9221dcadc3
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 22s
CI / build (pull_request) Successful in 27s
CI / quality (pull_request) Successful in 28s
CI / typecheck (pull_request) Successful in 30s
CI / security (pull_request) Successful in 46s
CI / integration_tests (pull_request) Successful in 3m23s
CI / benchmark-regression (pull_request) Successful in 25m7s
CI / unit_tests (pull_request) Successful in 28m35s
CI / docker (pull_request) Successful in 53s
CI / coverage (pull_request) Failing after 1h0m37s
2026-02-26 19:56:37 +00:00
Compare
brent.edwards dismissed CoreRasurae's review 2026-02-26 19:56:37 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aditya force-pushed feature/m3-mcp-adapter from 9221dcadc3
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 22s
CI / build (pull_request) Successful in 27s
CI / quality (pull_request) Successful in 28s
CI / typecheck (pull_request) Successful in 30s
CI / security (pull_request) Successful in 46s
CI / integration_tests (pull_request) Successful in 3m23s
CI / benchmark-regression (pull_request) Successful in 25m7s
CI / unit_tests (pull_request) Successful in 28m35s
CI / docker (pull_request) Successful in 53s
CI / coverage (pull_request) Failing after 1h0m37s
to a0f56228e2
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 18s
CI / security (pull_request) Successful in 29s
CI / typecheck (pull_request) Successful in 33s
CI / integration_tests (pull_request) Successful in 3m10s
CI / unit_tests (pull_request) Successful in 9m49s
CI / docker (pull_request) Successful in 40s
CI / benchmark-regression (pull_request) Successful in 27m20s
CI / coverage (pull_request) Successful in 38m36s
2026-02-27 06:46:38 +00:00
Compare
aditya merged commit ab9732c2a1 into master 2026-02-27 07:28:15 +00:00
aditya deleted branch feature/m3-mcp-adapter 2026-02-27 07:28:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
Reference
cleveragents/cleveragents-core!434
No description provided.