Skip to content

Commit 118950f

Browse files
committed
reshuffle the types a bit
1 parent 902c24a commit 118950f

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

src/telemetry/types.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ export type ToolEventProperties = {
2828
command: string;
2929
error_code?: string;
3030
error_type?: string;
31-
project_id?: string;
32-
org_id?: string;
3331
cluster_name?: string;
3432
is_atlas?: boolean;
35-
atlas_local_deployment_id?: string;
36-
};
33+
} & TelemetryToolMetadata;
3734

3835
export type ToolEvent = TelemetryEvent<ToolEventProperties>;
36+
3937
/**
4038
* Interface for server events
4139
*/
@@ -137,3 +135,23 @@ export type CommonProperties = {
137135
*/
138136
hosting_mode?: string;
139137
} & CommonStaticProperties;
138+
139+
/**
140+
* Telemetry metadata that can be provided by tools when emitting telemetry events.
141+
* For MongoDB tools, this is typically empty, while for Atlas tools, this should include
142+
* the project and organization IDs if available.
143+
*/
144+
export type TelemetryToolMetadata = AtlasLocalToolMetadata | AtlasToolMetadata | PerfAdvisorToolMetadata;
145+
146+
export type AtlasLocalToolMetadata = {
147+
atlas_local_deployment_id?: string;
148+
};
149+
150+
export type AtlasToolMetadata = {
151+
project_id?: string;
152+
org_id?: string;
153+
};
154+
155+
export type PerfAdvisorToolMetadata = AtlasToolMetadata & {
156+
operations: string[];
157+
};

src/tools/atlas/atlasTool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2-
import { ToolBase, type ToolArgs, type ToolCategory, type TelemetryToolMetadata } from "../tool.js";
2+
import type { AtlasToolMetadata } from "../../telemetry/types.js";
3+
import { ToolBase, type ToolArgs, type ToolCategory } from "../tool.js";
34
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
45
import { LogId } from "../../common/logger.js";
56
import { z } from "zod";
@@ -84,8 +85,8 @@ For more information on Atlas API access roles, visit: https://www.mongodb.com/d
8485
protected resolveTelemetryMetadata(
8586
result: CallToolResult,
8687
...args: Parameters<ToolCallback<typeof this.argsShape>>
87-
): TelemetryToolMetadata {
88-
const toolMetadata: TelemetryToolMetadata = {};
88+
): AtlasToolMetadata {
89+
const toolMetadata: AtlasToolMetadata = {};
8990
if (!args.length) {
9091
return toolMetadata;
9192
}

src/tools/atlas/read/getPerformanceAdvisor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { AtlasToolBase } from "../atlasTool.js";
33
import type { CallToolResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
4-
import type { OperationType, TelemetryToolMetadata, ToolArgs } from "../../tool.js";
4+
import type { OperationType, ToolArgs } from "../../tool.js";
55
import { formatUntrustedData } from "../../tool.js";
66
import {
77
getSuggestedIndexes,
@@ -14,6 +14,7 @@ import {
1414
} from "../../../common/atlas/performanceAdvisorUtils.js";
1515
import { AtlasArgs } from "../../args.js";
1616
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
17+
import type { PerfAdvisorToolMetadata } from "../../../telemetry/types.js";
1718

1819
const PerformanceAdvisorOperationType = z.enum([
1920
"suggestedIndexes",
@@ -136,9 +137,10 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase {
136137
result: CallToolResult,
137138
args: ToolArgs<typeof this.argsShape>,
138139
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
139-
): TelemetryToolMetadata {
140-
const baseMetadata = super.resolveTelemetryMetadata(result, args, extra);
141-
baseMetadata.operations = args.operations;
142-
return baseMetadata;
140+
): PerfAdvisorToolMetadata {
141+
return {
142+
...super.resolveTelemetryMetadata(result, args, extra),
143+
operations: args.operations,
144+
};
143145
}
144146
}

src/tools/atlasLocal/atlasLocalTool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import type { TelemetryToolMetadata, ToolArgs, ToolCategory } from "../tool.js";
2+
import type { ToolArgs, ToolCategory } from "../tool.js";
33
import { ToolBase } from "../tool.js";
44
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
55
import type { Client } from "@mongodb-js/atlas-local";
66
import { LogId } from "../../common/logger.js";
7+
import type { AtlasLocalToolMetadata } from "../../telemetry/types.js";
78

89
export const AtlasLocalToolMetadataDeploymentIdKey = "deploymentId";
910

@@ -118,8 +119,8 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
118119
return super.handleError(error, args);
119120
}
120121

121-
protected resolveTelemetryMetadata(result: CallToolResult): TelemetryToolMetadata {
122-
const toolMetadata: TelemetryToolMetadata = {};
122+
protected resolveTelemetryMetadata(result: CallToolResult): AtlasLocalToolMetadata {
123+
const toolMetadata: AtlasLocalToolMetadata = {};
123124

124125
// Atlas Local tools set the deployment ID in the result metadata for telemetry
125126
// If the deployment ID is set, we use it for telemetry

src/tools/mongodb/mongodbTool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { z } from "zod";
2-
import type { ToolArgs, ToolCategory, TelemetryToolMetadata } from "../tool.js";
2+
import type { ToolArgs, ToolCategory } from "../tool.js";
33
import { ToolBase } from "../tool.js";
44
import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
55
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
66
import { ErrorCodes, MongoDBError } from "../../common/errors.js";
77
import { LogId } from "../../common/logger.js";
88
import type { Server } from "../../server.js";
9+
import type { AtlasToolMetadata } from "../../telemetry/types.js";
910

1011
export const DbOperationArgs = {
1112
database: z.string().describe("Database name"),
@@ -115,8 +116,8 @@ export abstract class MongoDBToolBase extends ToolBase {
115116
result: CallToolResult,
116117
// eslint-disable-next-line @typescript-eslint/no-unused-vars
117118
args: ToolArgs<typeof this.argsShape>
118-
): TelemetryToolMetadata {
119-
const metadata: TelemetryToolMetadata = {};
119+
): AtlasToolMetadata {
120+
const metadata: AtlasToolMetadata = {};
120121

121122
// Add projectId to the metadata if running a MongoDB operation to an Atlas cluster
122123
if (this.session.connectedAtlasCluster?.projectId) {

src/tools/tool.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CallToolResult, ToolAnnotations } from "@modelcontextprotocol/sdk/
55
import type { Session } from "../common/session.js";
66
import { LogId } from "../common/logger.js";
77
import type { Telemetry } from "../telemetry/telemetry.js";
8-
import { type ToolEvent } from "../telemetry/types.js";
8+
import type { TelemetryToolMetadata, ToolEvent } from "../telemetry/types.js";
99
import type { PreviewFeature, UserConfig } from "../common/config.js";
1010
import type { Server } from "../server.js";
1111
import type { Elicitation } from "../elicitation.js";
@@ -38,17 +38,6 @@ export type OperationType = "metadata" | "read" | "create" | "delete" | "update"
3838
*/
3939
export type ToolCategory = "mongodb" | "atlas" | "atlas-local";
4040

41-
/**
42-
* Telemetry metadata that can be provided by tools when emitting telemetry events.
43-
* For MongoDB tools, this is typically empty, while for Atlas tools, this should include
44-
* the project and organization IDs if available.
45-
*/
46-
export type TelemetryToolMetadata = {
47-
project_id?: string;
48-
org_id?: string;
49-
atlas_local_deployment_id?: string;
50-
} & Record<string, string | number | string[]>;
51-
5241
export type ToolConstructorParams = {
5342
session: Session;
5443
config: UserConfig;

0 commit comments

Comments
 (0)