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
6 changes: 5 additions & 1 deletion src/lib/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logger from "../logger.js";
import { getBrowserStackAuth } from "./get-auth.js";
import { createRequire } from "module";
import { detectRunMode } from "./utils.js";
const require = createRequire(import.meta.url);
const packageJson = require("../../package.json");
import axios from "axios";
Expand All @@ -12,6 +13,7 @@ interface MCPEventPayload {
tool_name: string;
mcp_client: string;
success?: boolean;
mode?: string;
error_message?: string;
error_type?: string;
};
Expand Down Expand Up @@ -53,7 +55,9 @@ export function trackMCP(
event.event_properties.error_type =
error instanceof Error ? error.constructor.name : "Unknown";
}


event.event_properties.mode = detectRunMode();

let authHeader = undefined;
if (config) {
const authString = getBrowserStackAuth(config);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sharp from "sharp";
import path from "path";
import { fileURLToPath } from "url";
import type { ApiResponse } from "./apiClient.js";

export function sanitizeUrlParam(param: string): string {
Expand Down Expand Up @@ -38,3 +40,14 @@ export async function assertOkResponse(
);
}
}

export function detectRunMode(): "npx" | "local" | "unknown" {
try {
const scriptPath = fileURLToPath(import.meta.url);
const normalizedPath = path.normalize(scriptPath);
const npxPattern = path.sep + "_npx" + path.sep;
return normalizedPath.includes(npxPattern) ? "npx" : "local";
} catch {
return "unknown";
}
}