Repository navigation
fix(mcp): valid results fail with nested union schema references - #145533
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 1:06 AM ET / 05:06 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR reuses shared JSON Schema normalization so MCP tool results can reference definitions inside nullable unions while preserving draft-specific validation behavior. Merge readiness✅ Ready for maintainer review The fix remains necessary: current main and v2026.9.4 retain the faulty schema traversal. No actionable correctness or security defect was found in the introduced patch. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s MCP client discovers external tools and validates their structured results against advertised output schemas. Schema normalization prepares those schemas for validation before results reach the agent. flowchart TD
A[MCP tool catalog] --> B[Output schema]
B --> C{Schema draft}
C -->|2020-12| D[Shared schema normalization]
C -->|Older draft| E[SDK validator]
D --> F[TypeBox validator]
E --> G[Accept or reject tool result]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -54, Tests +174, Other 0. Total +120 across 5 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep schema-resource placement and format handling in the shared normalizer while retaining original-schema diagnostics and strict rejection of invalid tool results. Do we have a high-confidence way to reproduce the issue? Yes: current source moves the referenced definition away from its JSON pointer, and TypeBox resolves the missing target to false. The stdio regression supplies a concrete reproduction path; this read-only review did not execute it. Is this the best way to solve the issue? Yes: removing the competing traversal repairs the producer of the invalid schema while preserving the existing validator contracts and default behavior for other callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 39708c63ddd0. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Keep schema resources at their original paths by using the canonical normalizer instead of a competing MCP prepass. Preserve annotation-only formats, older-draft validation, original diagnostics and invalid-result rejection. Removes 54 net production lines. Verified real stdio regression, parent runtime proof, owner siblings, complete changed gates, normal build and exact-source P2 review. Co-authored-by: steipete <[email protected]>
c42e27f to
8435f72
Compare
|
Merged via squash.
|
…nclaw#145533) Use the shared JSON Schema normalization owner for MCP structured-result validation instead of a competing traversal that moves nested resource definitions. Preserve original-schema diagnostics, draft-specific validation and annotation-only format behavior. Production +45/-99, net 54 lines removed. With TypeBox 1.3.26, the parent independently exercised the real stdio/session runtime before and after the change: baseline rejected a valid leaf with a false-schema error while rejecting the invalid leaf; the candidate accepts the valid leaf and still rejects invalid output. Both production files were restored and source hashes verified. The 15-case runtime selection, 97 sibling cases, complete changed checks, normal build and fresh P0–P2 review passed. The two parent stdio cases overlap the runtime selection. Exact-head CI passed and the current-head Claw review reported no blocking findings; the earlier head’s hosted failure remains unattributed. No HTTP/provider requests, dependency edits or guard overrides were used for proof. Co-authored-by: steipete <[email protected]>
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR.
What Problem This Solves
Fixes an issue where valid structured results from MCP tools were rejected when a draft-2020-12 output schema referenced a definition inside a nullable union. A valid result could fail with an error saying the referenced schema was false.
Why This Change Was Made
Use the existing resource-preserving JSON Schema normalizer instead of a competing MCP traversal that relocated definitions while expanding union types. MCP retains its annotation-only format handling; other callers keep their defaults, and older schema drafts retain the existing SDK/AJV path.
This removes 54 net production lines. Original-schema diagnostics, invalid-result rejection, non-mutating validation, and dispatch-time validator capture remain intact. The protocol-specific Codex adapter is unchanged; it has distinct generated-schema/default/diagnostic contracts.
User Impact
MCP tools using valid nested schema references can return their results successfully. Malformed results still fail validation, and unrelated catalog tools remain usable. No constraints are stripped to make a result pass, and no public SDK API or authority behavior changes.
Evidence