|
| 1 | +# AI Agent Friendly CLI Implementation Plan for MCPM |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +This document outlines a comprehensive plan to make every MCPM feature accessible via pure parameterized CLI commands, eliminating the need for interactive TUI interfaces when used by AI agents or automation scripts. |
| 6 | + |
| 7 | +## Current State Analysis |
| 8 | + |
| 9 | +### ✅ Already AI-Agent Friendly (70% of commands) |
| 10 | +- **Core operations**: `search`, `info`, `ls`, `run`, `doctor`, `usage` |
| 11 | +- **Profile operations**: `profile ls`, `profile create`, `profile run`, `profile rm` (with `--force`) |
| 12 | +- **Configuration**: `config ls`, `config unset`, `config clear-cache` |
| 13 | +- **Client listing**: `client ls` |
| 14 | +- **Installation**: `install` (with env vars), `uninstall` (with `--force`) |
| 15 | + |
| 16 | +### ❌ Needs Parameterized Alternatives (30% of commands) |
| 17 | +- **Server creation**: `new`, `edit` |
| 18 | +- **Configuration**: `config set` |
| 19 | +- **Client management**: `client edit`, `client import` |
| 20 | +- **Profile management**: `profile edit`, `profile inspect` |
| 21 | +- **Migration**: `migrate` (partial) |
| 22 | + |
| 23 | +## Implementation Phases |
| 24 | + |
| 25 | +### Phase 1: Server Management (High Priority) |
| 26 | + |
| 27 | +#### 1.1 `mcpm new` - Non-interactive server creation |
| 28 | +**Current**: Interactive form only |
| 29 | +```bash |
| 30 | +mcpm new # Prompts for all server details |
| 31 | +``` |
| 32 | + |
| 33 | +**Proposed**: Full CLI parameter support |
| 34 | +```bash |
| 35 | +mcpm new <server_name> \ |
| 36 | + --type {stdio|remote} \ |
| 37 | + --command "python -m server" \ |
| 38 | + --args "arg1 arg2" \ |
| 39 | + --env "KEY1=value1,KEY2=value2" \ |
| 40 | + --url "http://example.com" \ |
| 41 | + --headers "Authorization=Bearer token" \ |
| 42 | + --force |
| 43 | +``` |
| 44 | + |
| 45 | +**Implementation Requirements**: |
| 46 | +- Add CLI parameters to `src/mcpm/commands/new.py` |
| 47 | +- Create parameter validation logic |
| 48 | +- Implement non-interactive server creation flow |
| 49 | +- Maintain backward compatibility with interactive mode |
| 50 | + |
| 51 | +#### 1.2 `mcpm edit` - Non-interactive server editing |
| 52 | +**Current**: Interactive form or external editor |
| 53 | +```bash |
| 54 | +mcpm edit <server> # Interactive form |
| 55 | +mcpm edit <server> -e # External editor |
| 56 | +``` |
| 57 | + |
| 58 | +**Proposed**: Field-specific updates |
| 59 | +```bash |
| 60 | +mcpm edit <server> --name "new_name" |
| 61 | +mcpm edit <server> --command "new command" |
| 62 | +mcpm edit <server> --args "new args" |
| 63 | +mcpm edit <server> --env "KEY=value" |
| 64 | +mcpm edit <server> --url "http://new-url.com" |
| 65 | +mcpm edit <server> --headers "Header=Value" |
| 66 | +mcpm edit <server> --force |
| 67 | +``` |
| 68 | + |
| 69 | +**Implementation Requirements**: |
| 70 | +- Add field-specific CLI parameters to `src/mcpm/commands/edit.py` |
| 71 | +- Create parameter-to-config mapping logic |
| 72 | +- Implement selective field updates |
| 73 | +- Support multiple field updates in single command |
| 74 | + |
| 75 | +### Phase 2: Profile Management (High Priority) |
| 76 | + |
| 77 | +#### 2.1 `mcpm profile edit` - Non-interactive profile editing |
| 78 | +**Current**: Interactive server selection |
| 79 | +```bash |
| 80 | +mcpm profile edit <profile> # Interactive checkbox selection |
| 81 | +``` |
| 82 | + |
| 83 | +**Proposed**: Server management via CLI |
| 84 | +```bash |
| 85 | +mcpm profile edit <profile> --add-server "server1,server2" |
| 86 | +mcpm profile edit <profile> --remove-server "server3,server4" |
| 87 | +mcpm profile edit <profile> --set-servers "server1,server2,server5" |
| 88 | +mcpm profile edit <profile> --rename "new_profile_name" |
| 89 | +mcpm profile edit <profile> --force |
| 90 | +``` |
| 91 | + |
| 92 | +**Implementation Requirements**: |
| 93 | +- Add server management parameters to `src/mcpm/commands/profile/edit.py` |
| 94 | +- Create server list parsing utilities |
| 95 | +- Implement server validation logic |
| 96 | +- Support multiple operations in single command |
| 97 | + |
| 98 | +#### 2.2 `mcpm profile inspect` - Non-interactive profile inspection |
| 99 | +**Current**: Interactive server selection |
| 100 | +```bash |
| 101 | +mcpm profile inspect <profile> # Interactive server selection |
| 102 | +``` |
| 103 | + |
| 104 | +**Proposed**: Direct server specification |
| 105 | +```bash |
| 106 | +mcpm profile inspect <profile> --server "server_name" |
| 107 | +mcpm profile inspect <profile> --all-servers |
| 108 | +mcpm profile inspect <profile> --port 3000 |
| 109 | +``` |
| 110 | + |
| 111 | +**Implementation Requirements**: |
| 112 | +- Add server selection parameters to `src/mcpm/commands/profile/inspect.py` |
| 113 | +- Implement direct server targeting |
| 114 | +- Support batch inspection of all servers |
| 115 | + |
| 116 | +### Phase 3: Client Management (Medium Priority) |
| 117 | + |
| 118 | +#### 3.1 `mcpm client edit` - Non-interactive client editing |
| 119 | +**Current**: Interactive server selection |
| 120 | +```bash |
| 121 | +mcpm client edit <client> # Interactive server/profile selection |
| 122 | +``` |
| 123 | + |
| 124 | +**Proposed**: Server management via CLI |
| 125 | +```bash |
| 126 | +mcpm client edit <client> --add-server "server1,server2" |
| 127 | +mcpm client edit <client> --remove-server "server3,server4" |
| 128 | +mcpm client edit <client> --set-servers "server1,server2,server5" |
| 129 | +mcpm client edit <client> --add-profile "profile1,profile2" |
| 130 | +mcpm client edit <client> --remove-profile "profile3" |
| 131 | +mcpm client edit <client> --config-path "/custom/path" |
| 132 | +mcpm client edit <client> --force |
| 133 | +``` |
| 134 | + |
| 135 | +**Implementation Requirements**: |
| 136 | +- Add server/profile management parameters to `src/mcpm/commands/client.py` |
| 137 | +- Create client configuration update logic |
| 138 | +- Support mixed server and profile operations |
| 139 | + |
| 140 | +#### 3.2 `mcpm client import` - Non-interactive client import |
| 141 | +**Current**: Interactive server selection |
| 142 | +```bash |
| 143 | +mcpm client import <client> # Interactive server selection |
| 144 | +``` |
| 145 | + |
| 146 | +**Proposed**: Automatic or specified import |
| 147 | +```bash |
| 148 | +mcpm client import <client> --all |
| 149 | +mcpm client import <client> --servers "server1,server2" |
| 150 | +mcpm client import <client> --create-profile "imported_profile" |
| 151 | +mcpm client import <client> --merge-existing |
| 152 | +mcpm client import <client> --force |
| 153 | +``` |
| 154 | + |
| 155 | +**Implementation Requirements**: |
| 156 | +- Add import control parameters to `src/mcpm/commands/client.py` |
| 157 | +- Implement automatic import logic |
| 158 | +- Support profile creation during import |
| 159 | + |
| 160 | +### Phase 4: Configuration Management (Medium Priority) |
| 161 | + |
| 162 | +#### 4.1 `mcpm config set` - Non-interactive configuration |
| 163 | +**Current**: Interactive prompts |
| 164 | +```bash |
| 165 | +mcpm config set # Interactive key/value prompts |
| 166 | +``` |
| 167 | + |
| 168 | +**Proposed**: Direct key-value setting |
| 169 | +```bash |
| 170 | +mcpm config set <key> <value> |
| 171 | +mcpm config set node_executable "/path/to/node" |
| 172 | +mcpm config set registry_url "https://custom-registry.com" |
| 173 | +mcpm config set analytics_enabled true |
| 174 | +mcpm config set --list # Show available config keys |
| 175 | +``` |
| 176 | + |
| 177 | +**Implementation Requirements**: |
| 178 | +- Add direct key-value parameters to `src/mcpm/commands/config.py` |
| 179 | +- Create configuration key validation |
| 180 | +- Add configuration key listing functionality |
| 181 | + |
| 182 | +### Phase 5: Migration Enhancement (Low Priority) |
| 183 | + |
| 184 | +#### 5.1 `mcpm migrate` - Enhanced non-interactive migration |
| 185 | +**Current**: Interactive choice prompt |
| 186 | +```bash |
| 187 | +mcpm migrate # Interactive choice: migrate/start fresh/ignore |
| 188 | +``` |
| 189 | + |
| 190 | +**Proposed**: Direct migration control |
| 191 | +```bash |
| 192 | +mcpm migrate --auto-migrate # Migrate automatically |
| 193 | +mcpm migrate --start-fresh # Start fresh |
| 194 | +mcpm migrate --ignore # Ignore v1 config |
| 195 | +mcpm migrate --backup-path "/path/to/backup" |
| 196 | +``` |
| 197 | + |
| 198 | +**Implementation Requirements**: |
| 199 | +- Add migration control parameters to `src/mcpm/commands/migrate.py` |
| 200 | +- Implement automatic migration logic |
| 201 | +- Add backup functionality |
| 202 | + |
| 203 | +## Technical Implementation Strategy |
| 204 | + |
| 205 | +### 1. Backwards Compatibility |
| 206 | +- All existing interactive commands remain unchanged |
| 207 | +- New CLI parameters are additive, not replacing |
| 208 | +- Interactive mode remains the default when parameters are missing |
| 209 | +- Add `--interactive` flag to force interactive mode when needed |
| 210 | + |
| 211 | +### 2. Flag Standards |
| 212 | +- `--force` - Skip all confirmations |
| 213 | +- `--json` - Machine-readable output where applicable |
| 214 | +- `--verbose` - Detailed output for debugging |
| 215 | +- `--dry-run` - Preview changes without applying |
| 216 | +- `--non-interactive` - Disable all prompts globally |
| 217 | + |
| 218 | +### 3. Parameter Validation |
| 219 | +- Comprehensive parameter validation before execution |
| 220 | +- Clear error messages for invalid combinations |
| 221 | +- Help text updates for all new parameters |
| 222 | +- Parameter conflict detection and resolution |
| 223 | + |
| 224 | +### 4. Environment Variable Support |
| 225 | +- Extend existing env var pattern to all commands |
| 226 | +- `MCPM_FORCE=true` - Global force flag |
| 227 | +- `MCPM_NON_INTERACTIVE=true` - Disable all prompts |
| 228 | +- `MCPM_JSON_OUTPUT=true` - JSON output by default |
| 229 | +- Server-specific env vars for sensitive data |
| 230 | + |
| 231 | +### 5. Output Standardization |
| 232 | +- Consistent JSON output format for programmatic use |
| 233 | +- Exit codes: 0 (success), 1 (error), 2 (validation error) |
| 234 | +- Structured error messages with error codes |
| 235 | +- Progress indicators for long-running operations |
| 236 | + |
| 237 | +## Code Structure Changes |
| 238 | + |
| 239 | +### 1. Utility Functions |
| 240 | +Create `src/mcpm/utils/non_interactive.py`: |
| 241 | +```python |
| 242 | +def is_non_interactive() -> bool: |
| 243 | + """Check if running in non-interactive mode.""" |
| 244 | + |
| 245 | +def parse_key_value_pairs(pairs: str) -> dict: |
| 246 | + """Parse comma-separated key=value pairs.""" |
| 247 | + |
| 248 | +def parse_server_list(servers: str) -> list: |
| 249 | + """Parse comma-separated server list.""" |
| 250 | + |
| 251 | +def validate_server_exists(server: str) -> bool: |
| 252 | + """Validate that server exists in global config.""" |
| 253 | +``` |
| 254 | + |
| 255 | +### 2. Command Parameter Enhancement |
| 256 | +For each command, add: |
| 257 | +- CLI parameter decorators |
| 258 | +- Parameter validation functions |
| 259 | +- Non-interactive execution paths |
| 260 | +- Parameter-to-config mapping logic |
| 261 | + |
| 262 | +### 3. Interactive Detection |
| 263 | +Implement detection logic: |
| 264 | +- Check for TTY availability |
| 265 | +- Check environment variables |
| 266 | +- Check for force flags |
| 267 | +- Graceful fallback when required parameters are missing |
| 268 | + |
| 269 | +## Testing Strategy |
| 270 | + |
| 271 | +### 1. Unit Tests |
| 272 | +- All new CLI parameters |
| 273 | +- Parameter validation logic |
| 274 | +- Non-interactive execution paths |
| 275 | +- Parameter parsing utilities |
| 276 | + |
| 277 | +### 2. Integration Tests |
| 278 | +- Full command workflows |
| 279 | +- Parameter combination testing |
| 280 | +- Error handling scenarios |
| 281 | +- Environment variable integration |
| 282 | + |
| 283 | +### 3. AI Agent Tests |
| 284 | +- Headless execution scenarios |
| 285 | +- Batch operation testing |
| 286 | +- Error recovery testing |
| 287 | +- Performance benchmarking |
| 288 | + |
| 289 | +### 4. Regression Tests |
| 290 | +- Ensure interactive modes still work |
| 291 | +- Backward compatibility verification |
| 292 | +- Help text accuracy |
| 293 | +- Exit code consistency |
| 294 | + |
| 295 | +## Benefits for AI Agents |
| 296 | + |
| 297 | +1. **Predictable Execution**: No interactive prompts to block automation |
| 298 | +2. **Scriptable**: All operations can be scripted and automated |
| 299 | +3. **Composable**: Commands can be chained and combined |
| 300 | +4. **Debuggable**: Verbose output and clear error messages |
| 301 | +5. **Stateless**: No dependency on terminal state or user presence |
| 302 | +6. **Batch Operations**: Support for multiple operations in single commands |
| 303 | +7. **Error Handling**: Structured error responses for programmatic handling |
| 304 | + |
| 305 | +## Success Metrics |
| 306 | + |
| 307 | +- **Coverage**: 100% of MCPM commands have non-interactive alternatives |
| 308 | +- **Compatibility**: 100% backward compatibility with existing workflows |
| 309 | +- **Performance**: Non-interactive commands execute ≤ 50ms faster than interactive |
| 310 | +- **Reliability**: 99.9% success rate for valid parameter combinations |
| 311 | +- **Usability**: Clear documentation and help text for all new parameters |
| 312 | + |
| 313 | +## Timeline |
| 314 | + |
| 315 | +- **Phase 1**: Server Management (1-2 weeks) |
| 316 | +- **Phase 2**: Profile Management (1-2 weeks) |
| 317 | +- **Phase 3**: Client Management (2-3 weeks) |
| 318 | +- **Phase 4**: Configuration Management (1 week) |
| 319 | +- **Phase 5**: Migration Enhancement (1 week) |
| 320 | +- **Testing & Documentation**: 1-2 weeks |
| 321 | + |
| 322 | +**Total Estimated Timeline**: 7-11 weeks |
| 323 | + |
| 324 | +## Implementation Order |
| 325 | + |
| 326 | +1. Create utility functions and infrastructure |
| 327 | +2. Implement server management commands (highest impact) |
| 328 | +3. Implement profile management commands |
| 329 | +4. Implement client management commands |
| 330 | +5. Implement configuration management commands |
| 331 | +6. Implement migration enhancements |
| 332 | +7. Add comprehensive testing |
| 333 | +8. Update documentation and help text |
| 334 | + |
| 335 | +This plan transforms MCPM from a user-centric tool with interactive elements into a fully AI-agent-friendly CLI tool while maintaining all existing functionality for human users. |
0 commit comments