diff --git a/package-lock.json b/package-lock.json index 747320d19..19cde142b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,7 +75,7 @@ "node": "^20.19.0 || ^22.12.0 || >= 23.0.0" }, "optionalDependencies": { - "@mongodb-js-preview/atlas-local": "^0.0.0-preview.6", + "@mongodb-js-preview/atlas-local": "^0.0.0-preview.7", "kerberos": "^2.2.2" } }, @@ -2050,26 +2050,26 @@ } }, "node_modules/@mongodb-js-preview/atlas-local": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local/-/atlas-local-0.0.0-preview.6.tgz", - "integrity": "sha512-UoLhTzyrL+99hGwcQyjjtOuWC66zQHgWhRXEj+tQVfDP97v0aKWctRigGVSmMPWnc2r5JdAlfR2M+sULfl7eCg==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local/-/atlas-local-0.0.0-preview.7.tgz", + "integrity": "sha512-4ceLPuBYFWkJWEZqQ/MyUqKQkM6klrloRPkJexNzT4A4vIBYFPPPQLyVcFjfXc/n+PwNuacYthCY83a5dRoo5w==", "license": "Apache-2.0", "optional": true, "engines": { "node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0" }, "optionalDependencies": { - "@mongodb-js-preview/atlas-local-darwin-arm64": "0.0.0-preview.6", - "@mongodb-js-preview/atlas-local-darwin-x64": "0.0.0-preview.6", - "@mongodb-js-preview/atlas-local-linux-arm64-gnu": "0.0.0-preview.6", - "@mongodb-js-preview/atlas-local-linux-x64-gnu": "0.0.0-preview.6", - "@mongodb-js-preview/atlas-local-win32-x64-msvc": "0.0.0-preview.6" + "@mongodb-js-preview/atlas-local-darwin-arm64": "0.0.0-preview.7", + "@mongodb-js-preview/atlas-local-darwin-x64": "0.0.0-preview.7", + "@mongodb-js-preview/atlas-local-linux-arm64-gnu": "0.0.0-preview.7", + "@mongodb-js-preview/atlas-local-linux-x64-gnu": "0.0.0-preview.7", + "@mongodb-js-preview/atlas-local-win32-x64-msvc": "0.0.0-preview.7" } }, "node_modules/@mongodb-js-preview/atlas-local-darwin-arm64": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-darwin-arm64/-/atlas-local-darwin-arm64-0.0.0-preview.6.tgz", - "integrity": "sha512-xB2h87mdq0W1tq7wZmpUIzS/wmUOrEKRqUYKNbv1g6M8pY/1ln2OCPi1OGj1LUnT8dC/jvklh92Ittj6eb5leg==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-darwin-arm64/-/atlas-local-darwin-arm64-0.0.0-preview.7.tgz", + "integrity": "sha512-fuL2ALZzh63kRHYe/hnrUNMyNqqH1BwYUtfa8mxFuJLaArAWaQ5iXysCCUWHQQpwUmB7pm4Y/NtPO6wzdXvKKA==", "cpu": [ "arm64" ], @@ -2083,9 +2083,9 @@ } }, "node_modules/@mongodb-js-preview/atlas-local-darwin-x64": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-darwin-x64/-/atlas-local-darwin-x64-0.0.0-preview.6.tgz", - "integrity": "sha512-5o4fXyXm6lOB1vCOIxRiF2p4NpChFZtjLSvsal+nxHBHJb/tevl7k8kE+dt7a5guO7CW1TCfy71E58NQxxaxkQ==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-darwin-x64/-/atlas-local-darwin-x64-0.0.0-preview.7.tgz", + "integrity": "sha512-gh/CU/TnaTWfIzyYORzADgp+IlBw9ctEmartMF/uaH+gDWaX8nacQGXSZxR6p2nJuDN9SX1O84/rVuKJZkDlKw==", "cpu": [ "x64" ], @@ -2099,9 +2099,9 @@ } }, "node_modules/@mongodb-js-preview/atlas-local-linux-arm64-gnu": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-linux-arm64-gnu/-/atlas-local-linux-arm64-gnu-0.0.0-preview.6.tgz", - "integrity": "sha512-ul8odgYVF5jpW56u2WHMs82Pmaf/6giIjQxHbMMafcHUPC87R08+Y0qIp8iY0vl4lTE5CBPXNzIICyPp+Snw9Q==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-linux-arm64-gnu/-/atlas-local-linux-arm64-gnu-0.0.0-preview.7.tgz", + "integrity": "sha512-hyA4g2YczV9Nmx5pevvHTcBdemdwG91Oll/5sxBFGIeEUv2ySV4fvX835IMsOYemQ0ci1o8VMYeHYVUsUO15aw==", "cpu": [ "arm64" ], @@ -2115,9 +2115,9 @@ } }, "node_modules/@mongodb-js-preview/atlas-local-linux-x64-gnu": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-linux-x64-gnu/-/atlas-local-linux-x64-gnu-0.0.0-preview.6.tgz", - "integrity": "sha512-90t5SynjHFvhEgh6xXEr86tN5VnKHDK6LrOb9Yuf/IlMHNmFm85Cr/OD/B5jREGxlLl+rWWZE7f+EZn/5pWVgw==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-linux-x64-gnu/-/atlas-local-linux-x64-gnu-0.0.0-preview.7.tgz", + "integrity": "sha512-vcw+OR3t1erGAe8nb6GXY3u8wVT3fG9sceV2+LVPxC/uq5RKt7JPfs97ftPnSpdiEe+/NgAG/Au2gfB0McfD/Q==", "cpu": [ "x64" ], @@ -2131,9 +2131,9 @@ } }, "node_modules/@mongodb-js-preview/atlas-local-win32-x64-msvc": { - "version": "0.0.0-preview.6", - "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-win32-x64-msvc/-/atlas-local-win32-x64-msvc-0.0.0-preview.6.tgz", - "integrity": "sha512-sxwT5NMMffrHNuPbaywuuu91OZC0CTSJaTQpjdjYWQgdeQDMDyWFNWS6k6irgxbgEMwacv6HUKPuOE/fC+/uNA==", + "version": "0.0.0-preview.7", + "resolved": "https://registry.npmjs.org/@mongodb-js-preview/atlas-local-win32-x64-msvc/-/atlas-local-win32-x64-msvc-0.0.0-preview.7.tgz", + "integrity": "sha512-fclSsGcwIOMudQY3wPAE9/xU5sw+LKQmPt9n+f3t7R4AObDOVzmIK78XzBYRDrvWv3aVBxAxqiIC4TH7oZB3yw==", "cpu": [ "x64" ], diff --git a/package.json b/package.json index 4a685ad13..70ecaf4e3 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "node": "^20.19.0 || ^22.12.0 || >= 23.0.0" }, "optionalDependencies": { - "@mongodb-js-preview/atlas-local": "^0.0.0-preview.6", + "@mongodb-js-preview/atlas-local": "^0.0.0-preview.7", "kerberos": "^2.2.2" } } diff --git a/src/telemetry/types.ts b/src/telemetry/types.ts index f0392344e..a0f371aeb 100644 --- a/src/telemetry/types.ts +++ b/src/telemetry/types.ts @@ -32,6 +32,7 @@ export type ToolEventProperties = { org_id?: string; cluster_name?: string; is_atlas?: boolean; + atlas_local_deployment_id?: string; }; export type ToolEvent = TelemetryEvent; diff --git a/src/tools/atlasLocal/atlasLocalTool.ts b/src/tools/atlasLocal/atlasLocalTool.ts index 4c97f3e70..b305b196e 100644 --- a/src/tools/atlasLocal/atlasLocalTool.ts +++ b/src/tools/atlasLocal/atlasLocalTool.ts @@ -6,6 +6,7 @@ import type { Client } from "@mongodb-js-preview/atlas-local"; export abstract class AtlasLocalToolBase extends ToolBase { public category: ToolCategory = "atlas-local"; + protected deploymentId?: string; protected verifyAllowed(): boolean { return this.session.atlasLocalClient !== undefined && super.verifyAllowed(); @@ -38,6 +39,18 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue return this.executeWithAtlasLocalClient(client, ...args); } + protected async lookupDeploymentId(client: Client, containerId: string): Promise { + // Don't run if telemetry is disabled + if (this.telemetry.isTelemetryEnabled()) { + return; + } + + // Lookup the deployment id and save it to the deploymentId property. + // This property will be added to the telemetry metadata when resolveTelemetryMetadata is called. + const deploymentId = await client.getDeploymentId(containerId); + this.deploymentId = deploymentId; + } + protected abstract executeWithAtlasLocalClient( client: Client, ...args: Parameters> @@ -67,11 +80,9 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue return super.handleError(error, args); } - protected resolveTelemetryMetadata( - ...args: Parameters> - ): TelemetryToolMetadata { - // TODO: include deployment id in the metadata where possible - void args; // this shuts up the eslint rule until we implement the TODO above - return {}; + protected resolveTelemetryMetadata(): TelemetryToolMetadata { + return { + atlasLocaldeploymentId: this.deploymentId, + }; } } diff --git a/src/tools/atlasLocal/connect/connectDeployment.ts b/src/tools/atlasLocal/connect/connectDeployment.ts index e2420aef2..1936f1939 100644 --- a/src/tools/atlasLocal/connect/connectDeployment.ts +++ b/src/tools/atlasLocal/connect/connectDeployment.ts @@ -22,6 +22,9 @@ export class ConnectDeploymentTool extends AtlasLocalToolBase { // Connect to the deployment await this.session.connectToMongoDB({ connectionString }); + // Lookup the deployment id and add it to the telemetry metadata + await this.lookupDeploymentId(client, deploymentName); + return { content: [ { diff --git a/src/tools/atlasLocal/create/createDeployment.ts b/src/tools/atlasLocal/create/createDeployment.ts index 17cf26dab..1ee76a44f 100644 --- a/src/tools/atlasLocal/create/createDeployment.ts +++ b/src/tools/atlasLocal/create/createDeployment.ts @@ -26,6 +26,9 @@ export class CreateDeploymentTool extends AtlasLocalToolBase { // Create the deployment const deployment = await client.createDeployment(deploymentOptions); + // Lookup the deployment id and add it to the telemetry metadata + await this.lookupDeploymentId(client, deployment.containerId); + return { content: [ { diff --git a/src/tools/atlasLocal/delete/deleteDeployment.ts b/src/tools/atlasLocal/delete/deleteDeployment.ts index 6d0d6616a..bf6c890f7 100644 --- a/src/tools/atlasLocal/delete/deleteDeployment.ts +++ b/src/tools/atlasLocal/delete/deleteDeployment.ts @@ -16,6 +16,9 @@ export class DeleteDeploymentTool extends AtlasLocalToolBase { client: Client, { deploymentName }: ToolArgs ): Promise { + // Lookup the deployment id and add it to the telemetry metadata + await this.lookupDeploymentId(client, deploymentName); + // Delete the deployment await client.deleteDeployment(deploymentName); diff --git a/src/tools/tool.ts b/src/tools/tool.ts index 85f166b3a..85220079e 100644 --- a/src/tools/tool.ts +++ b/src/tools/tool.ts @@ -16,6 +16,7 @@ export type ToolCategory = "mongodb" | "atlas" | "atlas-local"; export type TelemetryToolMetadata = { projectId?: string; orgId?: string; + atlasLocaldeploymentId?: string; }; export type ToolConstructor = new (session: Session, config: UserConfig, telemetry: Telemetry) => ToolBase; @@ -232,6 +233,10 @@ export abstract class ToolBase { event.properties.project_id = metadata.projectId; } + if (metadata?.atlasLocaldeploymentId) { + event.properties.atlas_local_deployment_id = metadata.atlasLocaldeploymentId; + } + await this.telemetry.emitEvents([event]); } }