Skip to content

feat: unified MCP server configuration API#4

Merged
ScottRBK merged 2 commits into
mainfrom
feature/mcp-server-config
May 4, 2026
Merged

feat: unified MCP server configuration API#4
ScottRBK merged 2 commits into
mainfrom
feature/mcp-server-config

Conversation

@ScottRBK

@ScottRBK ScottRBK commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds add_mcp_server / remove_mcp_server / list_mcp_servers to AgentShell and the AgentAdapter protocol so callers stop hand-coding per-agent dispatch when wiring MCP servers (e.g. forgetful for evals).
  • Implements all three methods for Claude Code, OpenCode, and Copilot CLI. All adapters write user-scope config so registrations persist across execute/stream calls.
  • MCPServerSpec dataclass validates STDIO/HTTP exactly-one-of fields at construction time.

Per-adapter behaviour

Agent Mechanism Storage
Claude Code claude mcp add/remove --scope user subprocess ~/.claude.json (managed by CLI)
OpenCode direct JSON write ~/.config/opencode/opencode.json
Copilot CLI direct JSON write ~/.copilot/mcp-config.json

list_mcp_servers raises NotImplementedError for Claude Code — tracked in #3.

Semantics

  • Add is idempotent: existing entry with the same name is overwritten (Claude Code does pre-remove + add; file-based adapters overwrite the JSON key).
  • Remove warns rather than raises if the named server is not found (UserWarning).

Test plan

  • Unit: MCPServerSpec validation (9 tests covering all invalid combinations)
  • Unit: AgentShell passthrough delegation + exception propagation
  • Integration (Claude Code): mocked subprocess asserts claude mcp add/remove argv shape, -e/--header translation, error propagation, overwrite-via-pre-remove
  • Integration (OpenCode): real file I/O against monkeypatch HOME=tmp_path; preserve unrelated config keys, overwrite same-name, round-trip via list_mcp_servers, warn on missing remove
  • Integration (Copilot CLI): same pattern as OpenCode
  • Full CI suite: 192 passed (was 158)

Closes #2

🤖 Generated with Claude Code

Adds add_mcp_server / remove_mcp_server / list_mcp_servers to AgentShell
and the AgentAdapter protocol so callers no longer need per-agent
dispatch when registering MCP servers. All adapters write user-scope
configuration so registrations persist across execute/stream calls.

- Claude Code: shells out to `claude mcp add/remove --scope user`;
  list_mcp_servers raises NotImplementedError pending a follow-up
- OpenCode: read/write ~/.config/opencode/opencode.json
- Copilot CLI: read/write ~/.copilot/mcp-config.json
- MCPServerSpec validates STDIO/HTTP exactly-one-of fields
- Adds are idempotent (overwrite); removes warn when name missing

Closes #2

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ScottRBK

ScottRBK commented May 4, 2026

Copy link
Copy Markdown
Owner Author

I found one issue worth addressing:

list_mcp_servers() can now crash on malformed MCP config entries in both src/agent_shell/adapters/opencode_adapter.py and src/agent_shell/adapters/copilot_cli_adapter.py. The new parsing code builds MCPServerSpec directly from JSON using .get(...), so missing or empty required fields like command or url raise ValueError and abort the entire listing. Since these config files are user-editable, a single bad entry can break the whole method instead of skipping or reporting the malformed server cleanly.

It would be safer to catch ValueError per entry and either skip invalid servers with a warning or raise a more targeted error that identifies the bad entry.

PR #4 review feedback: a single bad entry in the user-editable
opencode.json or copilot mcp-config.json could abort the entire listing
because MCPServerSpec validation raises ValueError. Catch per-entry,
warn naming the offender, and continue so good entries still surface.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ScottRBK ScottRBK merged commit 4470195 into main May 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unified MCP server configuration API

1 participant