Skip to content

Commit 49dee3a

Browse files
committed
feat: record client name in telemetry.
1 parent 41ff9bf commit 49dee3a

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export async function createMcpServer(
5757
return {};
5858
});
5959

60+
server.server.oninitialized = () => {
61+
const clientName = server.server.getClientVersion()?.name;
62+
if (clientName) {
63+
clearcutLogger?.setClientName(clientName);
64+
}
65+
};
66+
6067
let context: McpContext;
6168
async function getContext(): Promise<McpContext> {
6269
const chromeArgs: string[] = (serverArgs.chromeArg ?? []).map(String);

src/telemetry/ClearcutLogger.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {logger} from '../logger.js';
1010

1111
import type {LocalState, Persistence} from './persistence.js';
1212
import {FilePersistence} from './persistence.js';
13-
import {type FlagUsage, WatchdogMessageType, OsType} from './types.js';
13+
import { McpClient, type FlagUsage, WatchdogMessageType, OsType } from './types.js';
1414
import {WatchdogClient} from './WatchdogClient.js';
1515

1616
const MS_PER_DAY = 24 * 60 * 60 * 1000;
@@ -31,6 +31,7 @@ function detectOsType(): OsType {
3131
export class ClearcutLogger {
3232
#persistence: Persistence;
3333
#watchdog: WatchdogClient;
34+
#mcpClient: McpClient;
3435

3536
constructor(options: {
3637
appVersion: string;
@@ -53,6 +54,18 @@ export class ClearcutLogger {
5354
clearcutForceFlushIntervalMs: options.clearcutForceFlushIntervalMs,
5455
clearcutIncludePidHeader: options.clearcutIncludePidHeader,
5556
});
57+
this.#mcpClient = McpClient.MCP_CLIENT_UNSPECIFIED;
58+
}
59+
60+
setClientName(clientName: string): void {
61+
const lowerName = clientName.toLowerCase();
62+
if (lowerName.includes('claude')) {
63+
this.#mcpClient = McpClient.MCP_CLIENT_CLAUDE_CODE;
64+
} else if (lowerName.includes('gemini')) {
65+
this.#mcpClient = McpClient.MCP_CLIENT_GEMINI_CLI;
66+
} else {
67+
this.#mcpClient = McpClient.MCP_CLIENT_OTHER;
68+
}
5669
}
5770

5871
async logToolInvocation(args: {
@@ -63,6 +76,7 @@ export class ClearcutLogger {
6376
this.#watchdog.send({
6477
type: WatchdogMessageType.LOG_EVENT,
6578
payload: {
79+
mcp_client: this.#mcpClient,
6680
tool_invocation: {
6781
tool_name: args.toolName,
6882
success: args.success,
@@ -76,6 +90,7 @@ export class ClearcutLogger {
7690
this.#watchdog.send({
7791
type: WatchdogMessageType.LOG_EVENT,
7892
payload: {
93+
mcp_client: this.#mcpClient,
7994
server_start: {
8095
flag_usage: flagUsage,
8196
},
@@ -99,6 +114,7 @@ export class ClearcutLogger {
99114
this.#watchdog.send({
100115
type: WatchdogMessageType.LOG_EVENT,
101116
payload: {
117+
mcp_client: this.#mcpClient,
102118
daily_active: {
103119
days_since_last_active: daysSince,
104120
},

src/telemetry/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export enum McpClient {
7575
MCP_CLIENT_UNSPECIFIED = 0,
7676
MCP_CLIENT_CLAUDE_CODE = 1,
7777
MCP_CLIENT_GEMINI_CLI = 2,
78+
MCP_CLIENT_OTHER = 3,
7879
}
7980

8081
// IPC types for messages between the main process and the

tests/telemetry/ClearcutLogger.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ describe('ClearcutLogger', () => {
5454
});
5555
});
5656

57+
describe('setClientName', () => {
58+
it('appends mapped mcp_client to payload', async () => {
59+
const logger = new ClearcutLogger({
60+
persistence: mockPersistence,
61+
appVersion: '1.0.0',
62+
watchdogClient: mockWatchdogClient,
63+
});
64+
65+
logger.setClientName('gemini-cli-mcp-client');
66+
await logger.logServerStart({ headless: true });
67+
68+
assert(mockWatchdogClient.send.calledOnce);
69+
const msg = mockWatchdogClient.send.firstCall.args[0];
70+
assert.strictEqual(msg.type, WatchdogMessageType.LOG_EVENT);
71+
assert.strictEqual(msg.payload.mcp_client, 2); // 2 is MCP_CLIENT_GEMINI_CLI
72+
});
73+
});
74+
5775
describe('logServerStart', () => {
5876
it('logs flag usage', async () => {
5977
const logger = new ClearcutLogger({

0 commit comments

Comments
 (0)