Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,31 @@
activeFeatures?: ServerFeature[];
detectedFeatures?: ServerFeature[];
fixedRoot?: boolean;
clientInfo?: { name?: string; version?: string };

constructor(options: { activeFeatures?: ServerFeature[]; projectRoot?: string }) {
this.activeFeatures = options.activeFeatures;
this.server = new Server({ name: "firebase", version: SERVER_VERSION });
this.server.registerCapabilities({ tools: { listChanged: true } });
this.server.setRequestHandler(ListToolsRequestSchema, this.mcpListTools.bind(this));
this.server.setRequestHandler(CallToolRequestSchema, this.mcpCallTool.bind(this));
this.server.oninitialized = () => {
const clientInfo = this.server.getClientVersion();
this.clientInfo = clientInfo;
if (clientInfo?.name) {
trackGA4("mcp_client_connected", {

Check warning on line 47 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
mcp_client_name: clientInfo.name,
mcp_client_version: clientInfo.version,
});
}
};
this.projectRoot =
options.projectRoot ??
(configstore.get(PROJECT_ROOT_KEY) as string) ??
process.env.PROJECT_ROOT ??
process.cwd();
if (options.projectRoot) this.fixedRoot = true;
this.detectActiveFeatures();

Check warning on line 59 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

async detectActiveFeatures(): Promise<ServerFeature[]> {
Expand Down Expand Up @@ -108,7 +119,10 @@
async mcpListTools(): Promise<ListToolsResult> {
if (!this.activeFeatures) await this.detectActiveFeatures();
const hasActiveProject = !!(await this.getProjectId());
await trackGA4("mcp_list_tools", {});
await trackGA4("mcp_list_tools", {
mcp_client_name: this.clientInfo?.name,
mcp_client_version: this.clientInfo?.version,
});
return {
tools: this.availableTools.map((t) => t.mcp),
_meta: {
Expand Down Expand Up @@ -142,10 +156,20 @@
};
try {
const res = await tool.fn(toolArgs, toolsCtx);
await trackGA4("mcp_tool_call", { tool_name: toolName, error: res.isError ? 1 : 0 });
await trackGA4("mcp_tool_call", {
tool_name: toolName,
error: res.isError ? 1 : 0,
mcp_client_name: this.clientInfo?.name,
mcp_client_version: this.clientInfo?.version,
});
return res;
} catch (err: unknown) {
await trackGA4("mcp_tool_call", { tool_name: toolName, error: 1 });
await trackGA4("mcp_tool_call", {
tool_name: toolName,
error: 1,
mcp_client_name: this.clientInfo?.name,
mcp_client_version: this.clientInfo?.version,
});
return mcpError(err);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { configstore } from "./configstore";
import { logger } from "./logger";
const pkg = require("../package.json");

Check warning on line 7 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 7 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

type cliEventNames =
| "command_execution"
Expand All @@ -20,7 +20,8 @@
| "codebase_deploy"
| "function_deploy_group"
| "mcp_tool_call"
| "mcp_list_tools";
| "mcp_list_tools"
| "mcp_client_connected";
type GA4Property = "cli" | "emulator" | "vscode";
interface GA4Info {
measurementId: string;
Expand Down Expand Up @@ -68,7 +69,7 @@
value: process.version,
},
cli_version: {
value: pkg.version,

Check warning on line 72 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .version on an `any` value

Check warning on line 72 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
},
firepit_version: {
value: process.env.FIREPIT_VERSION || "none",
Expand Down Expand Up @@ -106,10 +107,10 @@
[key: string]: string | number | undefined;
}

export async function trackGA4(

Check warning on line 110 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
eventName: cliEventNames,
params: AnalyticsParams,
duration: number = 1, // Default to 1ms duration so that events show up in realtime view.

Check warning on line 113 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type number trivially inferred from a number literal, remove type annotation
): Promise<void> {
const session = cliSession();
if (!session) {
Expand All @@ -125,7 +126,7 @@
}

/**
* Record an emulator-related event for Analytics.

Check warning on line 129 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param eventName the event name in snake_case. (Formal requirement:
* length <= 40, alpha-numeric characters and underscores only
Expand Down Expand Up @@ -159,7 +160,7 @@
}

/**
* Record a vscode-related event for Analytics.

Check warning on line 163 in src/track.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param eventName the event name in snake_case. (Formal requirement:
* length <= 40, alpha-numeric characters and underscores only
Expand Down
Loading