MCPcopy
hub / github.com/codeaashu/claude-code / registerMcpAddCommand

Function registerMcpAddCommand

src/commands/mcp/addCommand.ts:33–280  ·  view source on GitHub ↗
(mcp: Command)

Source from the content-addressed store, hash-verified

31 * Registers the `mcp add` subcommand on the given Commander command.
32 */
33export function registerMcpAddCommand(mcp: Command): void {
34 mcp
35 .command('add <name> <commandOrUrl> [args...]')
36 .description(
37 'Add an MCP server to Claude Code.\n\n' +
38 'Examples:\n' +
39 ' # Add HTTP server:\n' +
40 ' claude mcp add --transport http sentry https://mcp.sentry.dev/mcp\n\n' +
41 ' # Add HTTP server with headers:\n' +
42 ' claude mcp add --transport http corridor https://app.corridor.dev/api/mcp --header "Authorization: Bearer ..."\n\n' +
43 ' # Add stdio server with environment variables:\n' +
44 ' claude mcp add -e API_KEY=xxx my-server -- npx my-mcp-server\n\n' +
45 ' # Add stdio server with subprocess flags:\n' +
46 ' claude mcp add my-server -- my-command --some-flag arg1',
47 )
48 .option(
49 '-s, --scope <scope>',
50 'Configuration scope (local, user, or project)',
51 'local',
52 )
53 .option(
54 '-t, --transport <transport>',
55 'Transport type (stdio, sse, http). Defaults to stdio if not specified.',
56 )
57 .option(
58 '-e, --env <env...>',
59 'Set environment variables (e.g. -e KEY=value)',
60 )
61 .option(
62 '-H, --header <header...>',
63 'Set WebSocket headers (e.g. -H "X-Api-Key: abc123" -H "X-Custom: value")',
64 )
65 .option('--client-id <clientId>', 'OAuth client ID for HTTP/SSE servers')
66 .option(
67 '--client-secret',
68 'Prompt for OAuth client secret (or set MCP_CLIENT_SECRET env var)',
69 )
70 .option(
71 '--callback-port <port>',
72 'Fixed port for OAuth callback (for servers requiring pre-registered redirect URIs)',
73 )
74 .helpOption('-h, --help', 'Display help for command')
75 .addOption(
76 new Option(
77 '--xaa',
78 "Enable XAA (SEP-990) for this server. Requires 'claude mcp xaa setup' first. Also requires --client-id and --client-secret (for the MCP server's AS).",
79 ).hideHelp(!isXaaEnabled()),
80 )
81 .action(async (name, commandOrUrl, args, options) => {
82 // Commander.js handles -- natively: it consumes -- and everything after becomes args
83 const actualCommand = commandOrUrl
84 const actualArgs = args
85
86 // If no name is provided, error
87 if (!name) {
88 cliError(
89 'Error: Server name is required.\n' +
90 'Usage: claude mcp add <name> <command> [args...]',

Callers 1

runFunction · 0.85

Calls 15

isXaaEnabledFunction · 0.85
cliErrorFunction · 0.85
ensureConfigScopeFunction · 0.85
ensureTransportFunction · 0.85
getXaaIdpSettingsFunction · 0.85
logEventFunction · 0.85
parseHeadersFunction · 0.85
readClientSecretFunction · 0.85
addMcpConfigFunction · 0.85
saveMcpClientSecretFunction · 0.85
jsonStringifyFunction · 0.85
parseEnvVarsFunction · 0.85

Tested by

no test coverage detected