fix(handlers)!: reject malformed tool, resource and prompt handler results #281
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.46) × (1 − Review Confidence (0.82)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 204 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.77 · 2 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.318
Real PR Conversation Timeline
4 items
we are introducing a new union member. This is source-breaking for consumers with exhaustive outcome.reason switches. It should be included in the next major version
Agreed. I marked the PR as breaking (! in the title) and labelled it semver-major, so it ships with the next major release alongside the other breaking changes.
Approved
Approved these changes.
rozzilla
mcollina
Summary
Handler results were passed through without checking their shape. A tool handler that returned
undefined, a resource handler that returned{}, or a prompt handler withoutmessagesproduced a JSON-RPC result that looked successful.Now the server checks each handler result for the array its type requires (
contentfor tools,contentsfor resources,messagesfor prompts). If that array is missing, the server logs an error and replies with JSON-RPC-32603"Internal error". The reply has nodataand no handler details. It is an error response, so it carries noresultand nothing a client could cache. The check always runs, not only in strict mode.Tool calls go through one shared check, so every path behaves the same way:
tools/callreturns-32603.tools/callends in thefailedstatus withstatusMessage: 'Internal error', andtasks/resultreturns the same-32603error.app.mcpCallTool()returns{ ok: false, reason: 'invalid-result' }.onToolCallCompleteobservers get the same outcome.Tool errors are logged through
app.log, because a task can outlive its request. Resource and prompt errors are logged throughrequest.log, the same as the existing handler-failure logs there.Breaking change
McpCallToolOutcomehas a new member,{ ok: false, reason: 'invalid-result' }. TypeScript code that switches exhaustively onoutcome.reasonwill need a new case.-32603error.Tests
test/malformed-handler-results.test.tscovers three kinds of bad result:undefined,{}, and a non-array field. It runs them against:mcpCallTool(including theonToolCallCompleteoutcome) and task-augmented callsIt also checks that the error is logged and that well-formed results still pass. 21 of the 22 new tests fail on
main; the remaining one is the well-formed-results check. The full suite passes (620 tests).Fixes #252
🤖 Generated with Claude Code
https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM