Skip to content

Commit f18b916

Browse files
committed
address comment: inject config to constructor
1 parent 7997c54 commit f18b916

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/session.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
22
import { ApiClient } from "./common/atlas/apiClient.js";
3-
import config from "./config.js";
3+
import defaultConfig from "./config.js";
44
import { Implementation } from "@modelcontextprotocol/sdk/types.js";
55

66
export class Session {
@@ -13,15 +13,17 @@ export class Session {
1313
};
1414
private credentials?: { clientId: string; clientSecret: string };
1515
private baseUrl: string;
16+
private readonly config: any;
1617

17-
constructor() {
18-
this.baseUrl = config.apiBaseUrl ?? "https://cloud.mongodb.com/";
18+
constructor(config = defaultConfig) {
19+
this.config = config;
20+
this.baseUrl = this.config.apiBaseUrl ?? "https://cloud.mongodb.com/";
1921

2022
// Store credentials if available
21-
if (config.apiClientId && config.apiClientSecret) {
23+
if (this.config.apiClientId && this.config.apiClientSecret) {
2224
this.credentials = {
23-
clientId: config.apiClientId,
24-
clientSecret: config.apiClientSecret,
25+
clientId: this.config.apiClientId,
26+
clientSecret: this.config.apiClientSecret,
2527
};
2628

2729
// Initialize API client with credentials

src/telemetry/constants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pkg from "../../package.json" with { type: "json" };
2+
import config from "../config.js";
3+
4+
/**
5+
* Machine-specific metadata formatted for telemetry
6+
*/
7+
export const MACHINE_METADATA = Object.freeze({
8+
device_id: "id", // TODO: use @mongodb-js/machine-id
9+
mcp_server_version: pkg.version,
10+
mcp_server_name: config.mcpServerName,
11+
platform: process.platform,
12+
arch: process.arch,
13+
os_type: process.platform,
14+
os_version: process.version,
15+
});

src/telemetry/telemetry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class Telemetry {
9393
const result = await this.sendEvents(this.session.apiClient, allEvents);
9494
if (result.success) {
9595
await this.clearCache();
96+
logger.debug(mongoLogId(1_000_000), "telemetry", `Sent ${allEvents.length} events successfully`);
9697
return;
9798
}
9899

0 commit comments

Comments
 (0)