|
5 | 5 | connectHttpTransport, |
6 | 6 | connectSSETransport |
7 | 7 | } from '../server/transport.js'; |
| 8 | +import { ClaudeConfigManager } from '../platform/claude/config.js'; |
| 9 | +import { VSCodeConfigManager } from '../platform/vscode/config.js'; |
8 | 10 |
|
9 | 11 | export const cmd = () => { |
10 | 12 | const exe = yargs(hideBin(process.argv)); |
@@ -40,5 +42,155 @@ export const cmd = () => { |
40 | 42 | ({ port }) => connectHttpTransport(port) |
41 | 43 | ); |
42 | 44 |
|
43 | | - exe.demandCommand().parseSync(); |
| 45 | + const validateUrl = (baseUrl?: string) => { |
| 46 | + // MCP servers do not have access to local env, it must be set in config |
| 47 | + // If flag was not set, fallback to env |
| 48 | + if (!baseUrl) { |
| 49 | + baseUrl = process.env.ARGOCD_BASE_URL; |
| 50 | + if (!baseUrl) { |
| 51 | + throw new Error( |
| 52 | + 'Argocd baseurl not provided and not in env, please provide it with the --url flag' |
| 53 | + ); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + // Validate url |
| 58 | + new URL(baseUrl); |
| 59 | + |
| 60 | + return baseUrl; |
| 61 | + }; |
| 62 | + |
| 63 | + const validateToken = (apiToken?: string) => { |
| 64 | + // MCP servers do not have access to local env, it must be set in config |
| 65 | + // If flag was not set, fallback to env |
| 66 | + if (!apiToken) { |
| 67 | + apiToken = process.env.ARGOCD_API_TOKEN; |
| 68 | + if (!apiToken) { |
| 69 | + throw new Error( |
| 70 | + 'Argocd token not provided and not in env, please provide it with the --token flag' |
| 71 | + ); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return apiToken; |
| 76 | + }; |
| 77 | + |
| 78 | + exe.command('claude', 'Manage Claude Desktop integration', (yargs) => { |
| 79 | + return yargs |
| 80 | + .command( |
| 81 | + 'enable', |
| 82 | + 'Enable ArgoCD MCP server in Claude Desktop', |
| 83 | + (yargs) => { |
| 84 | + return yargs |
| 85 | + .option('url', { |
| 86 | + type: 'string', |
| 87 | + description: 'ArgoCD base URL (falls back to ARGOCD_BASE_URL env var)' |
| 88 | + }) |
| 89 | + .option('token', { |
| 90 | + type: 'string', |
| 91 | + description: 'ArgoCD API token (falls back to ARGOCD_API_TOKEN env var)' |
| 92 | + }); |
| 93 | + }, |
| 94 | + async ({ url, token }) => { |
| 95 | + const manager = new ClaudeConfigManager(); |
| 96 | + try { |
| 97 | + console.log(`Configuration file: ${manager.getConfigPath()}`); |
| 98 | + const wasEnabled = await manager.enable(validateUrl(url), validateToken(token)); |
| 99 | + if (wasEnabled) { |
| 100 | + console.log('✓ ArgoCD MCP server configuration updated in Claude Desktop'); |
| 101 | + } else { |
| 102 | + console.log('✓ ArgoCD MCP server enabled in Claude Desktop'); |
| 103 | + } |
| 104 | + } catch (error) { |
| 105 | + console.error('Failed to enable ArgoCD MCP server:', (error as Error).message); |
| 106 | + process.exit(1); |
| 107 | + } |
| 108 | + } |
| 109 | + ) |
| 110 | + .command( |
| 111 | + 'disable', |
| 112 | + 'Disable ArgoCD MCP server in Claude Desktop', |
| 113 | + () => {}, |
| 114 | + async () => { |
| 115 | + const manager = new ClaudeConfigManager(); |
| 116 | + try { |
| 117 | + console.log(`Configuration file: ${manager.getConfigPath()}`); |
| 118 | + const wasEnabled = await manager.disable(); |
| 119 | + if (wasEnabled) { |
| 120 | + console.log('✓ ArgoCD MCP server disabled in Claude Desktop'); |
| 121 | + } else { |
| 122 | + console.log('ArgoCD MCP server was not enabled'); |
| 123 | + } |
| 124 | + } catch (error) { |
| 125 | + console.error('Failed to disable ArgoCD MCP server:', (error as Error).message); |
| 126 | + process.exit(1); |
| 127 | + } |
| 128 | + } |
| 129 | + ); |
| 130 | + }); |
| 131 | + |
| 132 | + exe.command('vscode', 'Manage VS Code integration', (yargs) => { |
| 133 | + return yargs |
| 134 | + .command( |
| 135 | + 'enable', |
| 136 | + 'Enable ArgoCD MCP server in VS Code', |
| 137 | + (yargs) => { |
| 138 | + return yargs |
| 139 | + .option('workspace', { |
| 140 | + type: 'boolean', |
| 141 | + description: 'Install in current workspace directory' |
| 142 | + }) |
| 143 | + .option('url', { |
| 144 | + type: 'string', |
| 145 | + description: 'ArgoCD base URL (falls back to ARGOCD_BASE_URL env var)' |
| 146 | + }) |
| 147 | + .option('token', { |
| 148 | + type: 'string', |
| 149 | + description: 'ArgoCD API token (falls back to ARGOCD_API_TOKEN env var)' |
| 150 | + }); |
| 151 | + }, |
| 152 | + async ({ workspace, url, token }) => { |
| 153 | + const manager = new VSCodeConfigManager(workspace); |
| 154 | + try { |
| 155 | + console.log(`Configuration file: ${manager.getConfigPath()}`); |
| 156 | + const wasEnabled = await manager.enable(validateUrl(url), validateToken(token)); |
| 157 | + if (wasEnabled) { |
| 158 | + console.log('✓ ArgoCD MCP server configuration updated in VS Code'); |
| 159 | + } else { |
| 160 | + console.log('✓ ArgoCD MCP server enabled in VS Code'); |
| 161 | + } |
| 162 | + } catch (error) { |
| 163 | + console.error('Failed to enable ArgoCD MCP server:', (error as Error).message); |
| 164 | + process.exit(1); |
| 165 | + } |
| 166 | + } |
| 167 | + ) |
| 168 | + .command( |
| 169 | + 'disable', |
| 170 | + 'Disable ArgoCD MCP server in VS Code', |
| 171 | + (yargs) => { |
| 172 | + return yargs.option('workspace', { |
| 173 | + type: 'boolean', |
| 174 | + description: 'Install in current workspace directory' |
| 175 | + }); |
| 176 | + }, |
| 177 | + async ({ workspace }) => { |
| 178 | + const manager = new VSCodeConfigManager(workspace); |
| 179 | + try { |
| 180 | + console.log(`Configuration file: ${manager.getConfigPath()}`); |
| 181 | + const wasEnabled = await manager.disable(); |
| 182 | + if (wasEnabled) { |
| 183 | + console.log('✓ ArgoCD MCP server disabled in VS Code'); |
| 184 | + } else { |
| 185 | + console.log('ArgoCD MCP server was not enabled'); |
| 186 | + } |
| 187 | + } catch (error) { |
| 188 | + console.error('Failed to disable ArgoCD MCP server:', (error as Error).message); |
| 189 | + process.exit(1); |
| 190 | + } |
| 191 | + } |
| 192 | + ); |
| 193 | + }); |
| 194 | + |
| 195 | + exe.demandCommand().strict().parse(); |
44 | 196 | }; |
0 commit comments