UNPKG

@skyramp/mcp

Version:

Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution

62 lines (61 loc) 2.35 kB
import { pushToolEvent } from "@skyramp/skyramp"; import * as fs from "fs"; import * as path from "path"; import { fileURLToPath } from "url"; export class AnalyticsService { static entryPoint = "mcp"; static async pushTestGenerationToolEvent(toolName, result, params) { const analyticsResult = {}; analyticsResult["prompt"] = params.prompt; analyticsResult["language"] = params.language; this.pushMCPToolEvent(toolName, result, analyticsResult); } static async pushMCPToolEvent(toolName, result, params) { let errorMessage = ""; if (result && result.isError) { for (const content of result?.content ?? []) { if ("text" in content && content.text) { errorMessage += content.text + ", "; } } if (errorMessage.length > 0) { errorMessage = errorMessage.slice(0, -2); } } params.mcpServerVersion = getMCPPackageVersion(); await pushToolEvent(this.entryPoint, toolName, errorMessage, params); } /** * Track server crash events */ static async pushServerCrashEvent(crashType, errorMessage, errorStack) { const params = { crashType: crashType, errorStack: errorStack || "no stack trace", mcpServerVersion: getMCPPackageVersion(), }; await pushToolEvent(this.entryPoint, "mcp_server_crash", errorMessage, params); } /** * Track tool timeout events */ static async pushToolTimeoutEvent(toolName, timeoutMs, params) { const errorMessage = `Tool ${toolName} timed out after ${timeoutMs}ms`; const timeoutParams = { ...params, timeoutMs: timeoutMs.toString(), mcpServerVersion: getMCPPackageVersion(), }; await pushToolEvent(this.entryPoint, `${toolName}_timeout`, errorMessage, timeoutParams); } } /** * Get the current MCP server version from package.json */ function getMCPPackageVersion() { const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const packageJson = fs.readFileSync(path.join(__dirname, "../../package.json"), "utf8"); const packageJsonData = JSON.parse(packageJson); return packageJsonData.version; }