@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
55 lines (54 loc) • 1.65 kB
JavaScript
import { getClient } from "../../currentScopes.js";
import "../../tracing/spanstatus.js";
import { captureException } from "../../exports.js";
import "../../tracing/index.js";
import { getActiveSpan } from "../../utils/spanUtils.js";
// src/integrations/mcp-server/errorCapture.ts
/**
* Safe error capture utilities for MCP server instrumentation
*
* Ensures error reporting never interferes with MCP server operation.
* All capture operations are wrapped in try-catch to prevent side effects.
*/
/**
* Classifies JSON-RPC errors using MCP server semantic conventions.
* @param code - JSON-RPC error code
* @see https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/mcp.md#server
*/
function isJsonRpcServerError(code) {
return ![
-32700,
-32600,
-32601,
-32602,
-32002
].includes(code);
}
/**
* Captures an error without affecting MCP server operation.
*
* The active span already contains all MCP context (method, tool, arguments, etc.)
* @param error - Error to capture
* @param errorType - Classification of error type for filtering
* @param extraData - Additional context data to include
*/
function captureError(error, errorType, extraData) {
try {
if (!getClient()) return;
const activeSpan = getActiveSpan();
if (activeSpan?.isRecording()) activeSpan.setStatus({
code: 2,
message: "internal_error"
});
captureException(error, { mechanism: {
type: "auto.ai.mcp_server",
handled: false,
data: {
error_type: errorType || "handler_execution",
...extraData
}
} });
} catch {}
}
export { captureError, isJsonRpcServerError };
//# sourceMappingURL=errorCapture.js.map