feat: add support for claude code as an MCP client#122
Conversation
jonathanlab
left a comment
There was a problem hiding this comment.
Very nice, works on my end as well!
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Claude Code as an MCP (Model Context Protocol) client, expanding the list of supported clients beyond the existing Cursor and Claude clients. The changes enable users to add and remove MCP servers through Claude Code using its CLI interface.
- Implements a new
ClaudeCodeMCPClientclass that integrates with Claude Code's MCP commands - Updates the supported clients list to include Claude Code
- Changes the default server type from 'streamable-http' to 'sse' for all clients
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/steps/add-mcp-server-to-clients/index.ts | Adds Claude Code client to the list of supported MCP clients |
| src/steps/add-mcp-server-to-clients/clients/claude-code.ts | Implements the Claude Code MCP client with CLI integration |
| src/steps/add-mcp-server-to-clients/MCPClient.ts | Changes default server type from 'streamable-http' to 'sse' |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| stdio: 'pipe', | ||
| }); | ||
|
|
||
| if (output.toString().includes('posthog')) { |
There was a problem hiding this comment.
Hard-coding 'posthog' as the server name makes this check specific to one server type. Consider making this configurable or using a more generic approach to detect installed servers.
| if (output.toString().includes('posthog')) { | |
| if (output.toString().includes(this.serverName)) { |
| } | ||
|
|
||
| getConfigPath(): Promise<string> { | ||
| throw new Error('Not implemented'); |
There was a problem hiding this comment.
The getConfigPath method throws 'Not implemented' but this method is part of the MCPClient interface. Either implement this method or mark it as optional in the interface if it's not needed for Claude Code.
| throw new Error('Not implemented'); | |
| // Assuming Claude Code stores config at ~/.claude/config.json | |
| const configPath = `${process.env.HOME || process.env.USERPROFILE}/.claude/config.json`; | |
| return Promise.resolve(configPath); |
| addServer(apiKey: string): Promise<{ success: boolean }> { | ||
| const config = getDefaultServerConfig(apiKey, 'sse'); | ||
|
|
||
| const command = `claude mcp add-json posthog -s user '${JSON.stringify( |
There was a problem hiding this comment.
Hard-coding 'posthog' as the server name in the command makes this client specific to PostHog servers. Consider parameterizing the server name to make this more generic.
| const command = `claude mcp add-json posthog -s user '${JSON.stringify( | |
| const command = `claude mcp add-json ${this.serverName} -s user '${JSON.stringify( |
| } | ||
|
|
||
| removeServer(): Promise<{ success: boolean }> { | ||
| const command = `claude mcp remove --scope user posthog`; |
There was a problem hiding this comment.
Hard-coding 'posthog' as the server name in the remove command creates the same maintainability issue as in addServer. Consider making the server name configurable.
| const command = `claude mcp remove --scope user posthog`; | |
| const command = `claude mcp remove --scope user ${this.serverName}`; |
| )}'`; | ||
|
|
||
| execSync(command); | ||
|
|
There was a problem hiding this comment.
Using execSync with a command that includes JSON.stringify(config) could be vulnerable to command injection if the config contains malicious content. Consider using safer command execution methods or proper escaping.
| // Use argument array to avoid command injection | |
| execSync( | |
| 'claude', | |
| [ | |
| 'mcp', | |
| 'add-json', | |
| 'posthog', | |
| '-s', | |
| 'user', | |
| JSON.stringify(config), | |
| ], | |
| { stdio: 'ignore', shell: false } | |
| ); |
|
|
||
| async addServer(apiKey: string): Promise<{ success: boolean }> { | ||
| return this._addServerType(apiKey, 'streamable-http'); | ||
| return this._addServerType(apiKey, 'sse'); |
There was a problem hiding this comment.
Changing the default server type from 'streamable-http' to 'sse' is a breaking change that affects all existing MCP clients. This should be documented and may require version migration logic.
Add Claude Code as an MCP client for the mcp add / remove commands.
Tested it locally. It is requiring the /sse endpoint to get working for me.