Skip to content

feat(cli): add mcp subcommand for managing MCP servers#361

Merged
christso merged 2 commits intomainfrom
feat/346-mcp-subcommand
Apr 10, 2026
Merged

feat(cli): add mcp subcommand for managing MCP servers#361
christso merged 2 commits intomainfrom
feat/346-mcp-subcommand

Conversation

@christso
Copy link
Copy Markdown
Contributor

Closes #346

Summary

Adds an allagents mcp subcommand surface with five operations for managing MCP servers independently of full plugin installs. Mirrors the claude mcp command surface and persists servers in a new top-level mcpServers: field in workspace.yaml (parallel to mcpProxy:).

New commands

Command Description
allagents mcp add <name> <commandOrUrl> Add a server to workspace.yaml and sync to all configured clients
allagents mcp remove <name> Remove a server from workspace.yaml and unsync from clients
allagents mcp list List MCP servers defined in workspace.yaml
allagents mcp get <name> Show the workspace definition for a server
allagents mcp update Sync MCP servers only, without touching other artifacts

mcp add supports:

  • --transport http|stdio (auto-detected from URL if omitted)
  • --arg <value> (repeatable, stdio only)
  • -e/--env KEY=VALUE (repeatable, stdio only)
  • --header KEY=VALUE (repeatable, http only)
  • --client <csv> — limit which clients receive the server
  • --force / -f — replace an existing server with the same name (used for updates)

Architecture

  • src/models/workspace-config.ts — new McpServerConfigSchema + top-level mcpServers: field.
  • src/core/vscode-mcp.tscollectMcpServers now accepts workspace-level servers and merges them with plugin-supplied servers (workspace overrides plugin, with a warning).
  • src/core/mcp-sync.ts — new module containing syncMcpServers (the per-client MCP sync loop, extracted from sync.ts::syncWorkspace) and syncMcpOnly (standalone MCP-only pipeline used by mcp update and by add/remove auto-sync).
  • src/core/sync.tssyncWorkspace now delegates to the shared syncMcpServers. Removes ~100 lines of duplicated per-client MCP blocks.
  • src/core/mcp-servers.ts — new module with CRUD helpers for the top-level mcpServers: field, plus buildMcpServerConfigFromFlags for translating CLI flags into an McpServerConfig.
  • src/cli/commands/mcp.ts / src/cli/metadata/mcp.ts — new CLI commands with agent-help metadata.

Ownership model

Honors the existing MCP ownership rule per CLAUDE.md: only servers AllAgents added are tracked via trackedServers in sync state and can be modified or removed. Pre-existing user-managed servers in .mcp.json / .copilot/mcp-config.json are preserved untouched (verified in E2E).

Tests

  • 20 new unit tests in tests/unit/core/mcp-servers.test.ts covering add/remove/get/list, config building from flags, and KEY=VALUE parsing.
  • Full suite: 1178 pass, 4 skip, 0 fail.

Test plan

  • bun test — all tests pass
  • bunx tsc --noEmit — clean
  • bun run lint — clean
  • Red E2E: confirmed baseline (mcp subcommand did not exist on main)
  • Green E2E: ran in /tmp/mcp-test-e2e with claude,copilot clients
    • mcp add deepwiki <https-url> → writes to workspace.yaml, syncs to .mcp.json and .copilot/mcp-config.json
    • mcp add gh-server npx --arg=-y --arg=@modelcontextprotocol/server-github -e GH_TOKEN=... → stdio with args and env
    • mcp add deepwiki ... --force --header Authorization=Bearer-token → replaces existing server (update workflow)
    • mcp list → shows both servers with transport details
    • mcp get deepwiki → prints YAML dump
    • mcp add claude-only ... --client claude → synced only to .mcp.json, not to copilot
    • mcp remove gh-server → removes from workspace.yaml and both client configs
    • mcp update → sync-only, shows "No MCP server changes." when nothing changed
    • Duplicate add without --force → exit 1 with clear error
    • mcp add bad https://... --transport stdio → exit 1 ("stdio transport requires a command, not a URL")
    • mcp get nonexistent → exit 1 with clear error
    • Ownership: pre-existing user-managed server in .mcp.json survived mcp remove of a different server

Closes #346

Adds a new `allagents mcp` subcommand surface with five operations:

- `mcp add <name> <commandOrUrl>` — add a server to workspace.yaml and
  sync to all configured clients. Supports --transport, --arg, -e/--env,
  --header, --client, --force.
- `mcp remove <name>` — remove a server from workspace.yaml and unsync
  from clients.
- `mcp list` — list MCP servers defined in workspace.yaml.
- `mcp get <name>` — show the workspace definition for a server.
- `mcp update` — sync MCP servers only, without touching other artifacts.

Extends WorkspaceConfigSchema with a top-level `mcpServers:` field (parallel
to `mcpProxy:`) and plumbs workspace-level servers through the sync pipeline
via `collectMcpServers`. Extracts the per-client MCP sync loop from
`sync.ts::syncWorkspace` into a shared `mcp-sync.ts::syncMcpServers`
function, and adds `syncMcpOnly` for the standalone `mcp update` command.

Honors the existing MCP ownership model: only servers AllAgents added are
tracked and can be modified or removed. Pre-existing user-managed servers
in `.mcp.json` / `.copilot/mcp-config.json` are preserved untouched.

Auto-detects HTTP vs stdio transport from the commandOrUrl argument and
rejects inconsistent flags (e.g. `--transport stdio` with a URL, or
`--arg` with HTTP).

Adds 20 unit tests in `tests/unit/core/mcp-servers.test.ts`. All 1178
tests pass.
- docs/reference/cli.mdx: add "MCP Commands" section covering
  add/remove/list/get/update with flags, examples, transport
  auto-detection notes, and the ownership model.
- docs/reference/configuration.mdx: document the top-level
  mcpServers: field in workspace.yaml with field reference and
  example covering http, stdio, and per-server client filters.
- README.md: add mcp add/list to the commands summary table.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying allagents with  Cloudflare Pages  Cloudflare Pages

Latest commit: ee4380b
Status: ✅  Deploy successful!
Preview URL: https://ef66f5b0.allagents.pages.dev
Branch Preview URL: https://feat-346-mcp-subcommand.allagents.pages.dev

View logs

@christso christso merged commit 0b25391 into main Apr 10, 2026
1 check passed
@christso christso deleted the feat/346-mcp-subcommand branch April 10, 2026 07:23
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.

feat: mcp subcommand for managing MCP servers independently

1 participant