Skip to content

Commit 0ea5876

Browse files
committed
fix: capture to only JSON-RPC server-side errors
1 parent 477f1f2 commit 0ea5876

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/core/src/integrations/mcp-server/transport.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export function wrapTransportError(transport: MCPTransport): void {
116116

117117
/**
118118
* Captures JSON-RPC error responses
119+
* Only captures server-side errors, not client validation errors
119120
*/
120121
function captureJsonRpcErrorResponse(
121122
errorResponse: unknown,
@@ -126,13 +127,20 @@ function captureJsonRpcErrorResponse(
126127
if (errorResponse && typeof errorResponse === 'object' && 'code' in errorResponse && 'message' in errorResponse) {
127128
const jsonRpcError = errorResponse as { code: number; message: string; data?: unknown };
128129

129-
const error = new Error(jsonRpcError.message);
130-
error.name = `JsonRpcError_${jsonRpcError.code}`;
130+
// Only capture server-side errors, not client validation errors
131+
// Per JSON-RPC 2.0 error object spec:
132+
// https://www.jsonrpc.org/specification#error_object
133+
const isServerError = jsonRpcError.code === -32603 || (jsonRpcError.code >= -32099 && jsonRpcError.code <= -32000);
131134

132-
captureError(error, 'protocol');
135+
if (isServerError) {
136+
const error = new Error(jsonRpcError.message);
137+
error.name = `JsonRpcError_${jsonRpcError.code}`;
138+
139+
captureError(error, 'protocol');
140+
}
133141
}
134142
} catch {
135-
// Silently ignore capture errors
143+
// noop
136144
}
137145
}
138146

@@ -143,6 +151,6 @@ function captureTransportError(error: Error, _transport: MCPTransport): void {
143151
try {
144152
captureError(error, 'transport');
145153
} catch {
146-
// Silently ignore capture errors
154+
// noop
147155
}
148156
}

0 commit comments

Comments
 (0)