Skip to content

Commit a06c460

Browse files
committed
address comments: update tools
1 parent bbc49be commit a06c460

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

src/tools/atlas/atlasTool.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ToolBase, ToolCategory } from "../tool.js";
1+
import { ToolBase, ToolCategory, TelemetryToolMetadata } from "../tool.js";
2+
import { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
3+
import logger, { LogId } from "../../logger.js";
4+
import { z } from "zod";
25

36
export abstract class AtlasToolBase extends ToolBase {
47
protected category: ToolCategory = "atlas";
@@ -9,4 +12,46 @@ export abstract class AtlasToolBase extends ToolBase {
912
}
1013
return super.verifyAllowed();
1114
}
15+
16+
/**
17+
*
18+
* Resolves the tool metadata from the arguments passed to the tool
19+
*
20+
* @param args - The arguments passed to the tool
21+
* @returns The tool metadata
22+
*/
23+
protected resolveTelemetryMetadata(
24+
...args: Parameters<ToolCallback<typeof this.argsShape>>
25+
): TelemetryToolMetadata {
26+
const toolMetadata: TelemetryToolMetadata = {};
27+
if (!args.length) {
28+
return toolMetadata;
29+
}
30+
31+
// Create a typed parser for the exact shape we expect
32+
const argsShape = z.object(this.argsShape);
33+
const parsedResult = argsShape.safeParse(args[0]);
34+
35+
if (!parsedResult.success) {
36+
logger.debug(
37+
LogId.telemetryMetadataError,
38+
"tool",
39+
`Error parsing tool arguments: ${parsedResult.error.message}`
40+
);
41+
return toolMetadata;
42+
}
43+
44+
const data = parsedResult.data;
45+
46+
// Extract projectId using type guard
47+
if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
48+
toolMetadata.projectId = data.projectId;
49+
}
50+
51+
// Extract orgId using type guard
52+
if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
53+
toolMetadata.orgId = data.orgId;
54+
}
55+
return toolMetadata;
56+
}
1257
}

src/tools/mongodb/mongodbTool.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { z } from "zod";
22
import { ToolArgs, ToolBase, ToolCategory, TelemetryToolMetadata } from "../tool.js";
33
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
4-
import { CallToolResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
4+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
55
import { ErrorCodes, MongoDBError } from "../../errors.js";
66
import logger, { LogId } from "../../logger.js";
7-
import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
87

98
export const DbOperationArgs = {
109
database: z.string().describe("Database name"),
@@ -76,10 +75,10 @@ export abstract class MongoDBToolBase extends ToolBase {
7675
}
7776

7877
protected resolveTelemetryMetadata(
79-
args: ToolArgs<typeof this.argsShape>,
80-
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
78+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
79+
args: ToolArgs<typeof this.argsShape>
8180
): TelemetryToolMetadata {
82-
const metadata = super.resolveTelemetryMetadata(args, extra);
81+
const metadata: TelemetryToolMetadata = {};
8382

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

src/tools/tool.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -132,47 +132,9 @@ export abstract class ToolBase {
132132
};
133133
}
134134

135-
/**
136-
*
137-
* Resolves the tool metadata from the arguments passed to the tool
138-
*
139-
* @param args - The arguments passed to the tool
140-
* @returns The tool metadata
141-
*/
142-
protected resolveTelemetryMetadata(
135+
protected abstract resolveTelemetryMetadata(
143136
...args: Parameters<ToolCallback<typeof this.argsShape>>
144-
): TelemetryToolMetadata {
145-
const toolMetadata: TelemetryToolMetadata = {};
146-
if (!args.length) {
147-
return toolMetadata;
148-
}
149-
150-
// Create a typed parser for the exact shape we expect
151-
const argsShape = z.object(this.argsShape);
152-
const parsedResult = argsShape.safeParse(args[0]);
153-
154-
if (!parsedResult.success) {
155-
logger.debug(
156-
LogId.telemetryMetadataError,
157-
"tool",
158-
`Error parsing tool arguments: ${parsedResult.error.message}`
159-
);
160-
return toolMetadata;
161-
}
162-
163-
const data = parsedResult.data;
164-
165-
// Extract projectId using type guard
166-
if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
167-
toolMetadata.projectId = data.projectId;
168-
}
169-
170-
// Extract orgId using type guard
171-
if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
172-
toolMetadata.orgId = data.orgId;
173-
}
174-
return toolMetadata;
175-
}
137+
): TelemetryToolMetadata;
176138

177139
/**
178140
* Creates and emits a tool telemetry event

0 commit comments

Comments
 (0)