Skip to content

feat: use node-machine-id #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025
Merged
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
35 changes: 10 additions & 25 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 @@ -69,7 +69,7 @@
"mongodb-log-writer": "^2.4.1",
"mongodb-redact": "^1.1.6",
"mongodb-schema": "^12.6.2",
"native-machine-id": "^0.1.0",
"node-machine-id": "^1.1.12",
"openapi-fetch": "^0.13.5",
"simple-oauth2": "^5.1.0",
"yargs-parser": "^21.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const LogId = {
telemetryEmitStart: mongoLogId(1_002_003),
telemetryEmitSuccess: mongoLogId(1_002_004),
telemetryMetadataError: mongoLogId(1_002_005),
telemetryDeviceIdFailure: mongoLogId(1_002_006),

toolExecute: mongoLogId(1_003_001),
toolExecuteFailure: mongoLogId(1_003_002),
Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getMachineIdSync } from "native-machine-id";
import { packageInfo } from "../packageInfo.js";
import { type CommonStaticProperties } from "./types.js";
import { getDeviceId } from "./device-id.js";
/**
* Machine-specific metadata formatted for telemetry
*/
export const MACHINE_METADATA: CommonStaticProperties = {
device_id: getMachineIdSync(),
device_id: getDeviceId(),
mcp_server_version: packageInfo.version,
mcp_server_name: packageInfo.mcpServerName,
platform: process.platform,
Expand Down
21 changes: 21 additions & 0 deletions src/telemetry/device-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createHmac } from "crypto";
import nodeMachineId from "node-machine-id";
import logger, { LogId } from "../logger.js";

export function getDeviceId(): string {
try {
const originalId = nodeMachineId.machineIdSync(true);
// Create a hashed format from the all uppercase version of the machine ID
// to match it exactly with the denisbrodbeck/machineid library that Atlas CLI uses.
const hmac = createHmac("sha256", originalId.toUpperCase());

/** This matches the message used to create the hashes in Atlas CLI */
const DEVICE_ID_HASH_MESSAGE = "atlascli";

hmac.update(DEVICE_ID_HASH_MESSAGE);
return hmac.digest("hex");
} catch (error) {
logger.debug(LogId.telemetryDeviceIdFailure, "telemetry", String(error));
return "unknown";
}
}
Loading