Skip to content

Commit 89c3568

Browse files
committed
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into gagik/use-machine-id
2 parents 5d981ee + de2c604 commit 89c3568

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { packageInfo } from "../packageInfo.js";
22
import { type CommonStaticProperties } from "./types.js";
3+
import { getDeviceId } from "./device-id.js";
34
/**
45
* Machine-specific metadata formatted for telemetry
56
*/

src/telemetry/device-id.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createHmac } from "crypto";
2+
import nodeMachineId from "node-machine-id";
3+
import logger, { LogId } from "../logger.js";
4+
5+
export function getDeviceId(): string {
6+
try {
7+
const originalId = nodeMachineId.machineIdSync(true);
8+
// Create a hashed format from the all uppercase version of the machine ID
9+
// to match it exactly with the denisbrodbeck/machineid library that Atlas CLI uses.
10+
const hmac = createHmac("sha256", originalId.toUpperCase());
11+
12+
/** This matches the message used to create the hashes in Atlas CLI */
13+
const DEVICE_ID_HASH_MESSAGE = "atlascli";
14+
15+
hmac.update(DEVICE_ID_HASH_MESSAGE);
16+
return hmac.digest("hex");
17+
} catch (error) {
18+
logger.debug(LogId.telemetryDeviceIdFailure, "telemetry", String(error));
19+
return "unknown";
20+
}
21+
}

0 commit comments

Comments
 (0)