Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/code-health-long-running.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ permissions: {}
jobs:
run-long-running-tests:
name: Run long running tests
if: github.event_name == 'push' || (github.event.pull_request.user.login != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ubuntu-latest
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type TelemetryEvent<T> = {
duration_ms: number;
result: TelemetryResult;
category: string;
};
} & Record<string, string | number | string[]>;
};

export type BaseEvent = TelemetryEvent<unknown>;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/atlas/atlasTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ For more information on Atlas API access roles, visit: https://www.mongodb.com/d

// Extract projectId using type guard
if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
toolMetadata.projectId = data.projectId;
toolMetadata.project_id = data.projectId;
}

// Extract orgId using type guard
if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
toolMetadata.orgId = data.orgId;
toolMetadata.org_id = data.orgId;
}
return toolMetadata;
}
Expand Down
15 changes: 13 additions & 2 deletions src/tools/atlas/read/getPerformanceAdvisor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { AtlasToolBase } from "../atlasTool.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import type { OperationType, ToolArgs } from "../../tool.js";
import type { CallToolResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
import type { OperationType, TelemetryToolMetadata, ToolArgs } from "../../tool.js";
import { formatUntrustedData } from "../../tool.js";
import {
getSuggestedIndexes,
Expand All @@ -13,6 +13,7 @@ import {
SLOW_QUERY_LOGS_COPY,
} from "../../../common/atlas/performanceAdvisorUtils.js";
import { AtlasArgs } from "../../args.js";
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";

const PerformanceAdvisorOperationType = z.enum([
"suggestedIndexes",
Expand Down Expand Up @@ -130,4 +131,14 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase {
};
}
}

protected override resolveTelemetryMetadata(
result: CallToolResult,
args: ToolArgs<typeof this.argsShape>,
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
): TelemetryToolMetadata {
const baseMetadata = super.resolveTelemetryMetadata(result, args, extra);
baseMetadata.operations = args.operations;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why not capture this new field in TelemetryToolMetadata? keeping track of the data we populate there is handy - makes it easy to get a list of properties in the long term

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair - I think it's a bit annoying if it becomes unwieldy as we add more and more stuff. But you're right that by being overly permissive, we lose oversight into what's being sent to telemetry. I'll try to find a better solution.

return baseMetadata;
}
}
2 changes: 1 addition & 1 deletion src/tools/atlasLocal/atlasLocalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
// If the deployment ID is set, we use it for telemetry
const resultDeploymentId = result._meta?.[AtlasLocalToolMetadataDeploymentIdKey];
if (resultDeploymentId !== undefined && typeof resultDeploymentId === "string") {
toolMetadata.atlasLocaldeploymentId = resultDeploymentId;
toolMetadata.atlas_local_deployment_id = resultDeploymentId;
}

return toolMetadata;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mongodb/mongodbTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export abstract class MongoDBToolBase extends ToolBase {

// Add projectId to the metadata if running a MongoDB operation to an Atlas cluster
if (this.session.connectedAtlasCluster?.projectId) {
metadata.projectId = this.session.connectedAtlasCluster.projectId;
metadata.project_id = this.session.connectedAtlasCluster.projectId;
}

return metadata;
Expand Down
21 changes: 5 additions & 16 deletions src/tools/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export type ToolCategory = "mongodb" | "atlas" | "atlas-local";
* the project and organization IDs if available.
*/
export type TelemetryToolMetadata = {
projectId?: string;
orgId?: string;
atlasLocaldeploymentId?: string;
};
project_id?: string;
org_id?: string;
atlas_local_deployment_id?: string;
} & Record<string, string | number | string[]>;

export type ToolConstructorParams = {
session: Session;
Expand Down Expand Up @@ -303,21 +303,10 @@ export abstract class ToolBase {
component: "tool",
duration_ms: duration,
result: result.isError ? "failure" : "success",
...metadata,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice thanks!

},
};

if (metadata?.orgId) {
event.properties.org_id = metadata.orgId;
}

if (metadata?.projectId) {
event.properties.project_id = metadata.projectId;
}

if (metadata?.atlasLocaldeploymentId) {
event.properties.atlas_local_deployment_id = metadata.atlasLocaldeploymentId;
}

this.telemetry.emitEvents([event]);
}

Expand Down
Loading
Loading