Skip to content

Commit de2c604

Browse files
authored
feat: use node-machine-id (#175)
1 parent d585baa commit de2c604

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

package-lock.json

Lines changed: 10 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"mongodb-log-writer": "^2.4.1",
7070
"mongodb-redact": "^1.1.6",
7171
"mongodb-schema": "^12.6.2",
72-
"native-machine-id": "^0.1.0",
72+
"node-machine-id": "^1.1.12",
7373
"openapi-fetch": "^0.13.5",
7474
"simple-oauth2": "^5.1.0",
7575
"yargs-parser": "^21.1.1",

src/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const LogId = {
1818
telemetryEmitStart: mongoLogId(1_002_003),
1919
telemetryEmitSuccess: mongoLogId(1_002_004),
2020
telemetryMetadataError: mongoLogId(1_002_005),
21+
telemetryDeviceIdFailure: mongoLogId(1_002_006),
2122

2223
toolExecute: mongoLogId(1_003_001),
2324
toolExecuteFailure: mongoLogId(1_003_002),

src/telemetry/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { getMachineIdSync } from "native-machine-id";
21
import { packageInfo } from "../packageInfo.js";
32
import { type CommonStaticProperties } from "./types.js";
3+
import { getDeviceId } from "./device-id.js";
44
/**
55
* Machine-specific metadata formatted for telemetry
66
*/
77
export const MACHINE_METADATA: CommonStaticProperties = {
8-
device_id: getMachineIdSync(),
8+
device_id: getDeviceId(),
99
mcp_server_version: packageInfo.version,
1010
mcp_server_name: packageInfo.mcpServerName,
1111
platform: process.platform,

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)