You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 893539d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(core): set span.status to error when MCP tool returns JSON-RPC error response (#20082)
When an MCP tool returns a JSON-RPC error response (i.e. the response
has an `error` field instead of `result`), the span was being ended with
`status=ok`. This meant `failure_rate()` read 0% in the MCP insights
dashboard even when tools were consistently failing.
## Root cause
`completeSpanWithResults` always ended the span without checking whether
the response was an error. The `captureError` path uses
`getActiveSpan()`, which returns `null` outside a `withActiveSpan()`
context — so errors were never reflected in span status.
## Fix
Pass `!!message.error` as a `hasError` flag to
`completeSpanWithResults`. When `true`, set `SPAN_STATUS_ERROR` with
`message: 'internal_error'` directly on the stored span before ending
it.
## Changes
- `correlation.ts` — `completeSpanWithResults` accepts optional
`hasError` param; sets error status when true
- `transport.ts` — passes `!!message.error` when completing spans on
outgoing send
- `transportInstrumentation.test.ts` — two new tests: error response
sets error status; success response does not
Closes#20083
---------
Co-authored-by: claude-sonnet-4-6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: dev-packages/e2e-tests/test-applications/node-express-v5/tests/mcp.test.ts
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -120,6 +120,23 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
120
120
121
121
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
122
122
});
123
+
124
+
awaittest.step('error tool sets span status to internal_error',async()=>{
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
128
128
});
129
+
130
+
awaittest.step('error tool sets span status to internal_error',async()=>{
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
125
125
});
126
+
127
+
awaittest.step('error tool sets span status to internal_error',async()=>{
0 commit comments