Skip to content
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToolEventProperties>;
Expand Down
23 changes: 17 additions & 6 deletions src/tools/atlasLocal/atlasLocalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<void> {
// 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<ToolCallback<typeof this.argsShape>>
Expand Down Expand Up @@ -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<ToolCallback<typeof this.argsShape>>
): 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,
};
}
}
3 changes: 3 additions & 0 deletions src/tools/atlasLocal/connect/connectDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
3 changes: 3 additions & 0 deletions src/tools/atlasLocal/create/createDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
3 changes: 3 additions & 0 deletions src/tools/atlasLocal/delete/deleteDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class DeleteDeploymentTool extends AtlasLocalToolBase {
client: Client,
{ deploymentName }: ToolArgs<typeof this.argsShape>
): Promise<CallToolResult> {
// Lookup the deployment id and add it to the telemetry metadata
await this.lookupDeploymentId(client, deploymentName);

// Delete the deployment
await client.deleteDeployment(deploymentName);

Expand Down
5 changes: 5 additions & 0 deletions src/tools/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
Expand Down
Loading