Branch: 015-server-management-cli | Date: 2025-12-26 | Spec: spec.md
Input: Feature specification from /specs/015-server-management-cli/spec.md
Implement CLI commands for adding and removing MCP servers with Claude Code-style syntax. The system provides:
mcpproxy upstream add <name> <url>for HTTP serversmcpproxy upstream add <name> -- <command> [args...]for stdio serversmcpproxy upstream remove <name>with confirmation promptsmcpproxy upstream add-json <name> '<json>'for complex configurations- Idempotent operations via
--if-not-existsand--if-existsflags
Current state: Server add/remove is already implemented in the MCP upstream_servers tool. This spec exposes that functionality via CLI commands with proper flag parsing, validation, and output formatting.
Language/Version: Go 1.24 (toolchain go1.24.10) Primary Dependencies: Cobra CLI framework, existing storage/config packages Storage: ~/.mcpproxy/mcp_config.json (config file), BoltDB (persistence) Testing: go test, ./scripts/test-api-e2e.sh Target Platform: macOS (darwin), Linux, Windows Project Type: CLI application (single binary) Performance Goals: Add/remove completes in <1s including config persistence Constraints: Backward compatible with existing config format, quarantine by default Scale/Scope: 3 new CLI commands, HTTP API endpoints, cliclient methods
GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.
| Principle | Status | Notes |
|---|---|---|
| I. Performance at Scale | ✅ PASS | Single server operations, O(1) |
| II. Actor-Based Concurrency | ✅ PASS | Uses existing management service layer |
| III. Configuration-Driven | ✅ PASS | Config file + quarantine by default |
| IV. Security by Default | ✅ PASS | New servers quarantined, validation for inputs |
| V. TDD | ✅ PASS | Unit tests for parsing, E2E tests for commands |
| VI. Documentation Hygiene | ✅ PASS | Update docs/ with add/remove examples |
| Separation of Concerns | ✅ PASS | CLI → cliclient → HTTP API → management service |
| Event-Driven Updates | ✅ PASS | EmitServersChanged on add/remove |
| DDD Layering | ✅ PASS | CLI is presentation, management is domain |
| Upstream Client Modularity | ✅ PASS | Uses existing upstream manager |
Gate Result: ✅ PASS - No violations, proceed to implementation
specs/015-server-management-cli/
├── plan.md # This file
├── spec.md # Feature specification
└── checklists/ # Quality checklists
cmd/mcpproxy/ # MODIFY: Add new commands
├── upstream_cmd.go # Add 'add', 'add-json', 'remove' subcommands
internal/cliclient/ # MODIFY: Add client methods
└── client.go # AddServer, RemoveServer methods
internal/httpapi/ # MODIFY: Add REST endpoints
├── handlers.go # POST /servers, DELETE /servers/{name}
└── routes.go # Register new routes
docs/ # UPDATE: Documentation
└── cli-management-commands.md # Add examples for add/remove
Structure Decision: Extend existing files. No new packages needed - CLI commands go in existing upstream_cmd.go, HTTP endpoints in existing httpapi handlers.
No violations - all gates passed. No complexity justification needed.
-
Add
upstreamAddCmdwith flag parsing:- Positional:
<name>(required),<url>(optional for HTTP) --separator for stdio command--transport http|stdio(auto-detect if not specified)--env KEY=value(repeatable)--header "Name: value"(repeatable)--working-dir <path>--if-not-exists
- Positional:
-
Add
upstreamAddJSONCmd:- Positional:
<name>,<json> - Validate JSON structure
- Positional:
-
Add
upstreamRemoveCmd:- Positional:
<name> --yesto skip confirmation--if-existsfor idempotent removal
- Positional:
-
Add HTTP endpoints for daemon mode:
POST /api/v1/servers- Add serverDELETE /api/v1/servers/{name}- Remove server
-
Add cliclient methods:
AddServer(ctx, config)- POST to /serversRemoveServer(ctx, name, force)- DELETE /servers/{name}
- Server name validation (alphanumeric, hyphens, underscores, 1-64 chars)
- URL validation for HTTP servers
- ENV format validation (KEY=value)
- Output using spec 014 formatters
- Spec 014: CLI Output Formatting (for consistent output) - ✅ Merged
- Existing Components:
internal/management/service.go: Management serviceinternal/storage/manager.go: AddUpstream, RemoveUpstreaminternal/upstream/manager.go: AddServer, RemoveServercmd/mcpproxy/upstream_cmd.go: Existing upstream commands
Proceed with implementation in this order:
- T001-T010: CLI command parsing and validation
- T011-T015: HTTP API endpoints
- T016-T020: cliclient methods
- T021-T025: Integration and testing