docs/plans/2025-11-19-cli-management-commands-design.md
Date: 2025-11-19 Status: Validated Design Goal: Add CLI commands for managing MCPProxy upstream servers and monitoring system health
Add two command groups to the MCPProxy CLI for server management and health monitoring:
mcpproxy upstream - Manage upstream MCP servers (list, logs, enable, disable, restart)mcpproxy doctor - Health checks and diagnostics (overall health + drill-down subcommands)All commands support both daemon mode (fast, via socket) and standalone mode (direct connection fallback).
mcpproxy upstream - Server Management# List all servers with connection status
mcpproxy upstream list [--output=table|json]
# View server logs
mcpproxy upstream logs <name> [--tail=N] [--follow]
# Enable/disable servers
mcpproxy upstream enable <name|--all> [--force]
mcpproxy upstream disable <name|--all> [--force]
# Restart servers
mcpproxy upstream restart <name|--all>
Output Format:
--output=table (default) - Tabular display with columns: NAME, ENABLED, PROTOCOL, CONNECTED, TOOLS, STATUS--output=json - JSON format for scriptingBulk Operations:
--all flag for operating on all serversenable --all and disable --all require interactive confirmation or --force flagrestart --all operates without confirmation (non-destructive)mcpproxy doctor - Health Checks# Run all health checks (default)
mcpproxy doctor [--output=pretty|json]
# Drill down into specific checks
mcpproxy doctor docker # Docker isolation status
mcpproxy doctor oauth # OAuth authentication issues
mcpproxy doctor secrets # Missing secrets
mcpproxy doctor upstream # Upstream connection errors
Output Format:
--output=pretty (default) - Rich formatted output with emojis and sections (like Homebrew doctor)--output=json - JSON format for scriptingHealth Checks:
upstream (not server)Rationale: Clear distinction from mcpproxy serve command (which starts the daemon). "Upstream" matches internal terminology and config structure.
Rejected alternatives:
server - Too similar to serve, confusingservers - Still similar, less precisemcp - Less intuitive for users unfamiliar with protocoldoctor (not diagnostics)Rationale: Follows Homebrew convention (brew doctor), more approachable than "diagnostics".
Pattern: One command to check everything, subcommands for drill-down.
Rationale: More discoverable via --help, follows CLI conventions, extensible.
mcpproxy doctor docker # Subcommand (chosen)
mcpproxy doctor --docker # Flag (rejected)
--all Flag PatternRationale: All server actions support --all for consistency and flexibility.
mcpproxy upstream enable --all
mcpproxy upstream disable --all
mcpproxy upstream restart --all
Safety: Bulk enable/disable require confirmation (see below).
Commands requiring confirmation:
mcpproxy upstream enable --allmcpproxy upstream disable --allBehavior:
Interactive mode (TTY detected):
$ mcpproxy upstream disable --all
⚠️ This will disable 12 servers. Continue? [y/N]: _
y, yes (case-insensitive)n, no, Enter, or anything elseNon-interactive mode (pipe, script, CI):
$ echo "y" | mcpproxy upstream disable --all
Error: --all requires --force flag in non-interactive mode
Exit code: 2
--forceForce flag (skips prompt):
$ mcpproxy upstream disable --all --force
✅ Successfully disabled 12 servers
Single-server operations (no prompt):
$ mcpproxy upstream disable github-server
✅ Successfully disabled server 'github-server'
Rationale: Both enable and disable can be disruptive. Enable might trigger unwanted connections/API calls. Disable stops services. Both warrant confirmation for bulk operations.
Follow existing patterns from codebase:
Tabular data: --output=table|json (like tools list)
upstream listRich formatted output: --output=pretty|json (like call tool)
doctor, doctor docker, etc.Rationale: Semantic consistency - tables for tabular data, pretty for rich diagnostic output.
All commands auto-detect running daemon via socket availability:
socketPath := socket.DetectSocketPath(dataDir)
isDaemonRunning := socket.IsSocketAvailable(socketPath)
Daemon mode (preferred):
Standalone mode (fallback):
Commands requiring daemon:
upstream enable/disable/restartupstream logs --followdoctor (all subcommands)CLAUDE.md (brief summary):
docs/cli-management-commands.md (comprehensive):
Rationale: Keep CLAUDE.md lean and maintainable while providing complete reference separately.
cmd/mcpproxy/
upstream_cmd.go # New: upstream command group
doctor_cmd.go # New: doctor command group
main.go # Modified: register new commands
internal/cliclient/
client.go # Modified: add API methods
internal/httpapi/
server.go # Modified: ensure endpoints exist
Following existing conventions from tools_cmd.go and call_cmd.go:
socket.DetectSocketPath() and socket.IsSocketAvailable()cliclient.NewClient(socketPath, logger)New shared function in upstream_cmd.go:
func confirmBulkAction(action string, count int, force bool) (bool, error)
term.IsTerminal(int(os.Stdin.Fd()))--force in non-interactive modeExisting endpoints in internal/httpapi/server.go:
GET /api/v1/servers - List serversGET /api/v1/servers/{name}/logs?tail=N - Server logsPOST /api/v1/servers/{name}/enable - Enable serverPOST /api/v1/servers/{name}/disable - Disable serverPOST /api/v1/servers/{name}/restart - Restart serverNew endpoints needed:
GET /api/v1/diagnostics - Run all health checksGET /api/v1/diagnostics/docker - Docker statusGET /api/v1/diagnostics/oauth - OAuth issuesGET /api/v1/diagnostics/secrets - Missing secretsGET /api/v1/diagnostics/upstream - Connection errors$ mcpproxy doctor
Error: This command requires running daemon. Start with: mcpproxy serve
Exit code: 1
$ mcpproxy upstream restart nonexistent-server
Error: server 'nonexistent-server' not found
Exit code: 1
--all Operations$ mcpproxy upstream disable --all
⚠️ No servers to disable
Exit code: 0
$ mcpproxy upstream logs github-server
Error: log file not found: ~/.mcpproxy/logs/server-github-server.log
(daemon may not have run yet)
Exit code: 1
$ mcpproxy upstream logs github-server --follow
Error: --follow requires running daemon
Exit code: 1
# Build
go build -o mcpproxy ./cmd/mcpproxy
# Test with daemon running
./mcpproxy serve &
sleep 2
./mcpproxy upstream list
./mcpproxy doctor
# Test without daemon
pkill mcpproxy
./mcpproxy upstream list # Should show standalone mode
# Test confirmations
./mcpproxy upstream disable --all # Should prompt
echo "n" | ./mcpproxy upstream disable --all # Should error
./mcpproxy upstream disable --all --force # Should succeed
# Test output formats
./mcpproxy upstream list --output=json
./mcpproxy doctor --output=json
# Test follow mode
./mcpproxy upstream logs github-server --follow
| Command | Daemon Mode | Standalone Mode | Notes |
|---|---|---|---|
upstream list | ✅ Full status | ✅ Config only | Standalone shows "unknown" |
upstream logs | ✅ Via API | ✅ File read | Follow requires daemon |
upstream enable | ✅ | ❌ | Requires daemon |
upstream disable | ✅ | ❌ | Requires daemon |
upstream restart | ✅ | ❌ | Requires daemon |
doctor | ✅ | ❌ | Requires daemon |
Add brief "CLI Management Commands" section after "Development Commands":
### CLI Management Commands
MCPProxy provides CLI commands for managing upstream servers and monitoring health:
```bash
mcpproxy upstream list # List all servers
mcpproxy upstream logs <name> # View logs (--tail, --follow)
mcpproxy upstream restart <name> # Restart server (supports --all)
mcpproxy doctor # Run health checks
Common workflow:
mcpproxy doctor # Check overall health
mcpproxy upstream list # Identify issues
mcpproxy upstream logs failing-srv # View logs
mcpproxy upstream restart failing-srv
See docs/cli-management-commands.md for complete reference.
### 2. New File: docs/cli-management-commands.md
Comprehensive reference including:
- Full command reference with all flags
- Output format examples
- Daemon vs standalone mode explanation
- Common workflows and troubleshooting
- Safety warnings for `--all` flag
- Implementation notes for contributors
### 3. Update Existing "Debugging Guide" in CLAUDE.md
Update to reference new `doctor` command:
```markdown
## Debugging Guide
### Quick Diagnostics
Run this first when debugging any issue:
```bash
mcpproxy doctor
See docs/cli-management-commands.md for detailed workflows.
### 4. Rename Implementation Plan
Rename `docs/plans/2025-11-19-cli-debugging-commands.md` to `docs/plans/2025-11-19-cli-management-commands.md` to match new framing.
---
## Safety Considerations
### Bulk Operations Documentation
Add prominent warning in documentation:
```markdown
⚠️ **Safety Warning: Bulk Operations**
The `--all` flag affects all servers simultaneously:
- `disable --all` - Stops all upstream connections (reversible with `enable --all`)
- `enable --all` - Activates all servers (may trigger API calls, OAuth flows)
- `restart --all` - Reconnects all servers (may cause brief service disruption)
**Best practices:**
- Use `upstream list` first to see affected servers
- Test with single server before using `--all`
- Use `--force` in automation only when appropriate
Confirmation prompt shows count:
⚠️ This will disable 12 servers. Continue? [y/N]:
Shows what will be affected before proceeding.
Not in scope for initial implementation:
Filtering for bulk operations
mcpproxy upstream restart --protocol=stdio
mcpproxy upstream disable --tag=experimental
Server groups
mcpproxy upstream restart @production
Watch mode
mcpproxy upstream list --watch
Batch operations from file
mcpproxy upstream restart --from-file=servers.txt
This design provides comprehensive CLI management for MCPProxy:
✅ Clear naming - upstream and doctor avoid confusion with existing commands
✅ Consistent patterns - --all flag, output formats, daemon detection
✅ Safety first - Interactive confirmation for bulk operations
✅ Progressive disclosure - Brief docs in CLAUDE.md, detailed reference separate
✅ Automation-friendly - --force flag, JSON output, exit codes
✅ Discoverable - Subcommands over flags, clear help text
Ready for implementation.