Skip to content

Commit 81ea213

Browse files
joehanblidd-google
authored andcommitted
Add metrics for MCP (#8497)
* Add metrics for MCP * check iserror field as well * format * format
1 parent b56e6e0 commit 81ea213

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/mcp/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { requireAuth } from "../requireAuth.js";
1818
import { Options } from "../options.js";
1919
import { getProjectId } from "../projectUtils.js";
2020
import { mcpAuthError, NO_PROJECT_ERROR } from "./errors.js";
21+
import { trackGA4 } from "../track.js";
2122
import { Config } from "../config.js";
2223

2324
const SERVER_VERSION = "0.0.1";
@@ -62,6 +63,7 @@ export class FirebaseMcpServer {
6263

6364
async mcpListTools(): Promise<ListToolsResult> {
6465
const hasActiveProject = !!(await this.getProjectId());
66+
await trackGA4("mcp_list_tools", {});
6567
return {
6668
tools: this.availableTools.map((t) => t.mcp),
6769
_meta: {
@@ -117,8 +119,15 @@ export class FirebaseMcpServer {
117119

118120
try {
119121
const config = Config.load({ cwd: this.projectRoot });
120-
return tool.fn(toolArgs, { projectId: await this.getProjectId(), host: this, config });
122+
const res = await tool.fn(toolArgs, {
123+
projectId: await this.getProjectId(),
124+
host: this,
125+
config,
126+
});
127+
await trackGA4("mcp_tool_call", { tool_name: toolName, error: res.isError ? 1 : 0 });
128+
return res;
121129
} catch (err: unknown) {
130+
await trackGA4("mcp_tool_call", { tool_name: toolName, error: 1 });
122131
return mcpError(err);
123132
}
124133
}

src/track.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ type cliEventNames =
1818
| "extensions_emulated"
1919
| "function_deploy"
2020
| "codebase_deploy"
21-
| "function_deploy_group";
21+
| "function_deploy_group"
22+
| "mcp_tool_call"
23+
| "mcp_list_tools";
2224
type GA4Property = "cli" | "emulator" | "vscode";
2325
interface GA4Info {
2426
measurementId: string;

0 commit comments

Comments
 (0)