Skip to content

Commit 0419a7d

Browse files
authored
feat: add support for claude code as an MCP client (#122)
1 parent 1b942a4 commit 0419a7d

4 files changed

Lines changed: 74 additions & 3 deletions

File tree

src/steps/add-mcp-server-to-clients/MCPClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export abstract class DefaultMCPClient extends MCPClient {
3636
}
3737

3838
async addServer(apiKey: string): Promise<{ success: boolean }> {
39-
return this._addServerType(apiKey, 'streamable-http');
39+
return this._addServerType(apiKey, 'sse');
4040
}
4141

4242
async _addServerType(

src/steps/add-mcp-server-to-clients/clients/__tests__/claude.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ describe('ClaudeMCPClient', () => {
326326

327327
expect(getDefaultServerConfigMock).toHaveBeenCalledWith(
328328
mockApiKey,
329-
'streamable-http',
329+
'sse',
330330
);
331331
});
332332
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { DefaultMCPClient } from '../MCPClient';
2+
import { DefaultMCPClientConfig, getDefaultServerConfig } from '../defaults';
3+
import { z } from 'zod';
4+
import { execSync } from 'child_process';
5+
6+
export const ClaudeCodeMCPConfig = DefaultMCPClientConfig;
7+
8+
export type ClaudeCodeMCPConfig = z.infer<typeof DefaultMCPClientConfig>;
9+
10+
export class ClaudeCodeMCPClient extends DefaultMCPClient {
11+
name = 'Claude Code';
12+
13+
constructor() {
14+
super();
15+
}
16+
17+
isClientSupported(): Promise<boolean> {
18+
try {
19+
execSync('claude --version', { stdio: 'ignore' });
20+
return Promise.resolve(true);
21+
} catch {
22+
return Promise.resolve(false);
23+
}
24+
}
25+
26+
isServerInstalled(): Promise<boolean> {
27+
try {
28+
// check if posthog in output
29+
const output = execSync('claude mcp list', {
30+
stdio: 'pipe',
31+
});
32+
33+
if (output.toString().includes('posthog')) {
34+
return Promise.resolve(true);
35+
}
36+
} catch {
37+
//
38+
}
39+
40+
return Promise.resolve(false);
41+
}
42+
43+
getConfigPath(): Promise<string> {
44+
throw new Error('Not implemented');
45+
}
46+
47+
addServer(apiKey: string): Promise<{ success: boolean }> {
48+
const config = getDefaultServerConfig(apiKey, 'sse');
49+
50+
const command = `claude mcp add-json posthog -s user '${JSON.stringify(
51+
config,
52+
)}'`;
53+
54+
execSync(command);
55+
56+
return Promise.resolve({ success: true });
57+
}
58+
59+
removeServer(): Promise<{ success: boolean }> {
60+
const command = `claude mcp remove --scope user posthog`;
61+
62+
execSync(command);
63+
64+
return Promise.resolve({ success: true });
65+
}
66+
}

src/steps/add-mcp-server-to-clients/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import { CursorMCPClient } from './clients/cursor';
1212
import { ClaudeMCPClient } from './clients/claude';
1313
import { getPersonalApiKey } from '../../mcp';
1414
import type { CloudRegion } from '../../utils/types';
15+
import { ClaudeCodeMCPClient } from './clients/claude-code';
1516

1617
export const getSupportedClients = async (): Promise<MCPClient[]> => {
17-
const allClients = [new CursorMCPClient(), new ClaudeMCPClient()];
18+
const allClients = [
19+
new CursorMCPClient(),
20+
new ClaudeMCPClient(),
21+
new ClaudeCodeMCPClient(),
22+
];
1823
const supportedClients: MCPClient[] = [];
1924

2025
for (const client of allClients) {

0 commit comments

Comments
 (0)