Feat/swarm mcp tools#142
Conversation
Thread operator-resolved AgentConfig into swarm runtimes and workers, build per-worker registries that merge local tools with allowlisted remote MCP tools, and add M1-M5 regression coverage for config plumbing, registry filtering, boot wiring, event metadata, and trust boundaries. Co-Authored-By: Claude Code <noreply@anthropic.com> AI-Model: <synthetic> Co-Authored-By: opencode <noreply@ai-tool.com> AI-Contributed/Feature: 250/250 AI-Contributed/UT: 1647/1647
Add the README SWARM external MCP tools section, mark the roadmap implemented, and fill the TDD status matrix with commit-backed M1-M6 coverage. Co-Authored-By: Claude Code <noreply@anthropic.com> AI-Model: <synthetic> AI-Contributed/Feature: 301/301 AI-Contributed/UT: 0/0
There was a problem hiding this comment.
Pull request overview
This PR extends the SWARM execution path (run_swarm workers) to use operator-approved external MCP tools while preserving the trust boundary (callers cannot inject MCP server config via variables). It threads an optional AgentConfig through SwarmRuntime into run_worker, builds a swarm-specific tool registry that merges local + remote MCP tools, and adds extensive regression coverage plus documentation for the rollout.
Changes:
- Add SWARM-side MCP config resolution (
VIBE_TRADING_SWARM_AGENT_CONFIG→swarm-agent.json→agent.json→ empty config) and wire it into MCP server, API server, CLI, and in-processSwarmTool. - Introduce
build_swarm_registry(...)and update workers to use it; emitserver/remote_toolmetadata for remote tool calls intool_call/tool_resultevents. - Add M1–M6 regression tests (plumbing, registry assembly, boot wiring, e2e, trust model) and new docs/README section.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Document SWARM external MCP tools and link to roadmap/TDD docs. |
| docs/2026-05-25_swarm_mcp_tools_tdd.md | Add TDD matrix with requirements/scenarios/tests and status tracking. |
| docs/2026-05-25_swarm_mcp_tools_roadmap.md | Add/mark implemented roadmap for SWARM external MCP tools and trust model. |
| agent/tests/test_swarm_m5_trust_model.py | Add trust-boundary regression tests for run_swarm schema and variable handling. |
| agent/tests/test_swarm_m4_e2e.py | Add end-to-end worker tests covering remote MCP calls, metadata, redaction, and failure handling. |
| agent/tests/test_swarm_m3_boot_wiring.py | Add tests for SWARM agent config path resolution and loader behavior. |
| agent/tests/test_swarm_m2_registry_assembly.py | Add tests for merging/filtering local + remote MCP tools via build_swarm_registry. |
| agent/tests/test_swarm_m1_config_plumbing.py | Add tests ensuring agent_config plumbing and lazy behavior at construction time. |
| agent/src/tools/swarm_tool.py | Load SWARM agent config for in-process swarm tool execution. |
| agent/src/tools/init.py | Add build_swarm_registry and refactor filtered registry projection helper. |
| agent/src/swarm/worker.py | Use build_swarm_registry and emit remote MCP metadata in events. |
| agent/src/swarm/runtime.py | Thread optional agent_config through runtime into worker execution. |
| agent/src/config/loader.py | Implement SWARM config resolution + loader helper. |
| agent/src/config/init.py | Export load_swarm_agent_config. |
| agent/mcp_server.py | Load SWARM agent config before constructing SwarmRuntime in MCP run_swarm. |
| agent/cli/_legacy.py | Load SWARM agent config before constructing runtime in CLI live runner. |
| agent/api_server.py | Load SWARM agent config before constructing cached runtime in API server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prune SWARM MCP discovery to only servers implied by each worker whitelist and remove an unused pytest import flagged by review. Co-Authored-By: Claude Code <noreply@anthropic.com> AI-Model: <synthetic> AI-Contributed/Feature: 30/30 AI-Contributed/UT: 41/41
warren618
left a comment
There was a problem hiding this comment.
Thanks for the quick update. I don't think this is mergeable yet.
The new pruning path in build_swarm_registry() breaks the existing MCP server-name collision handling. _prune_agent_config_for_swarm_tools() computes the local server-name segments from the full config, but then returns a new AgentConfig containing only the selected servers. build_registry() recomputes resolve_mcp_server_tool_name_segments() on that pruned config, so a colliding server such as foo-bar / foo_bar loses its hash suffix after pruning.
Example: the full config may expose mcp_foo_bar_db7329d5_ping, but after pruning build_registry() rebuilds it as mcp_foo_bar_ping, so the worker whitelist no longer matches and the tool is dropped as unavailable.
Could you preserve the original resolved local server-name mapping when pruning, or skip pruning for collision groups, and add a regression test with two colliding server names?
Preserve full-config MCP server-name resolution when pruning SWARM worker registries so collision hash suffixes remain stable after narrowing discovery. Also redact nested sensitive values from tool event previews, including remote MCP result previews. Co-Authored-By: Claude Code <noreply@anthropic.com> AI-Model: GitHub Copilot Co-Authored-By: github-copilot <noreply@ai-tool.com> AI-Contributed/Feature: 71/71 AI-Contributed/UT: 53/53
|
@warren618 good catch — fixed in c4e107f. The fix preserves the original resolved server-name mapping rather than skipping pruning:
All 27 M-series tests pass locally on c4e107f. PTAL. |
Summary
run_swarmto use operator-approved external MCP tools.Why
SWARM analyst workers could previously only use local Vibe-Trading tools, even when Vibe-Trading itself was exposed through MCP. This prevented enterprise/internal workflows from letting analysts query approved knowledge bases, data lakes, compliance tools, or other MCP-backed data sources.
This PR adds server-side, operator-controlled MCP tool access for SWARM workers while keeping caller-provided
variablesas template data only.Changes
AgentConfigthroughSwarmRuntimeintorun_worker.build_swarm_registry(...)to merge local tools with configured remote MCP wrappers, then filter by each agent'stools:whitelist.VIBE_TRADING_SWARM_AGENT_CONFIG~/.vibe-trading/swarm-agent.json~/.vibe-trading/agent.jsonSwarmTool.tool_call/tool_resultevents viaserverandremote_tool, while keeping sensitive args redacted.run_swarmdoes not expose MCP config injection fields and does not derive MCP config from caller variables.Test Plan
pytest --ignore=agent/tests/e2e_backtest --tb=short -q)Checklist
src/agent/,src/session/,src/providers/) without prior discussion