Repository navigation
fix(mcp): inline local refs in bundled tool schemas - #81238
Conversation
|
/review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs changes before merge. Summary Reproducibility: no. for the original Notion pre-dispatch failure: maintainer live validation reached Notion on current main and PR head. Yes by source inspection for the PR regression: resolved Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Keep the shared normalizer and bundled MCP materialization boundary, but merge only after the resolver preserves valid Do we have a high-confidence way to reproduce the issue? No for the original Notion pre-dispatch failure: maintainer live validation reached Notion on current main and PR head. Yes by source inspection for the PR regression: resolved Is this the best way to solve the issue? No. Normalizing local refs at the shared tool-schema boundary is the right shape, but the implementation must preserve JSON Schema 2020-12 sibling constraints and leave recursive refs safe instead of replacing them with permissive schemas. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 524185a68ea2. |
59894ff to
3c943e6
Compare
3c943e6 to
c1be32f
Compare
|
Rebased on current origin/main and reran focused verification.\n\nChecks:\n- oxfmt --check changed files\n- node scripts/test-projects.mjs src/agents/pi-bundle-mcp-tools.materialize.test.ts src/agents/pi-tools.schema.test.ts --reporter=verbose\n- node scripts/check-changed.mjs\n- git diff --check\n\n@clawsweeper re-review |
galiniliev
left a comment
There was a problem hiding this comment.
PR #81238 fixes the right bundled MCP boundary for issue #78737 by normalizing tool.inputSchema before exposing MCP tools. The direct Notion-style $ref: "#/$defs/parentRequest" case is covered, but the resolver currently breaks valid JSON Schema refs outside that narrow shape.
By: Gio Della-Libera (@giodl73-repo, acct 2025-09-30) | OpenClaw: 17 PRs, 1 issue, 13 commits/12mo | GitHub: 21 repos, 3353 commits, 40 PRs, 8 issues, 2 reviews
Issue opener: @cozywithher (acct 2025-12-03) | OpenClaw: 0 PRs, 2 issues, 0 commits/12mo | GitHub: 0 commits, 0 PRs, 2 issues, 0 reviews
Findings
- Blocking:
inlineLocalSchemaRefsWithDefsonly resolves refs matching#/$defs/<name>or#/definitions/<name>, but it removes every$defs/definitionsobject while walking the schema. A valid schema such asproperties.x.$ref = "#/$defs/Foo/properties/bar"is not resolved by the regex atsrc/agents/pi-tools-parameter-schema.ts:198, then the root$defsis dropped atsrc/agents/pi-tools-parameter-schema.ts:243, leaving a dangling ref that local validation rejects. MCP's SDK contract exposesinputSchemaas a JSON Schema object (node_modules/@modelcontextprotocol/sdk/dist/esm/spec.types.d.ts:1180), and TypeBox currently validates that nested JSON Pointer form correctly when$defsis retained. Best fix: either implement full local JSON Pointer resolution or preserve$defs/definitionswhenever unresolved local refs remain. Add a regression with a nested pointer ref.
Verdict
Request changes. The approach is right for the reported Notion direct-ref bug, and src/agents/pi-bundle-mcp-materialize.ts:114 is the right boundary, but the shared normalizer must not make broader valid MCP schemas invalid.
Evidence read: linked issue #78737, PR diff, current materialization path, pi-ai validateToolArguments using TypeBox compile, MCP SDK tool schema types, and the PR tests. CI on the PR is green, but GitHub currently reports the PR as conflicting due to CHANGELOG.md, which is landing cleanup rather than the review finding.
b80c2ab to
9a54635
Compare
|
Fixed the nested local JSON Pointer review finding and rebased on current Changes:
Focused verification:
@clawsweeper re-review |
9a54635 to
0edf3de
Compare
|
Rebased again onto current Focused verification after this rebase:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer live validation update: I ran a real OpenClaw live probe on Crabbox/Blacksmith, not just the focused fixture tests. Setup:
Result: both PR head and current So I could not reproduce the issue as “OpenClaw rejects the valid Notion The PR still appears useful as schema-normalization / provider-compat cleanup: PR head exposes the smaller inlined schema, while main exposes the raw |
0edf3de to
fbc239c
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
fbc239c to
fec810f
Compare
|
Addressed the review feedback: the schema normalizer now resolves nested local JSON Pointer refs under both |
edc559d to
2fdad23
Compare
78130ab to
a02cd9d
Compare
a02cd9d to
f4beb91
Compare
|
Updated #81238 with a fresh deterministic proof image and gate-friendly proof section. The proof compares
Fresh proof image: https://raw.githubusercontent.com/giodl73-repo/openclaw/proof-artifacts/pr-81238-fresh/pr-81238/pr-81238-bundled-mcp-ref-union-schema-before-after-proof.png |
Summary
Fixes #78737.
Bundled MCP tools can expose JSON Schema
$defs/definitionsplus local$refpointers. Today those schemas are passed through during MCP tool materialization, so tools like NotionAPI-post-pagecan expose a requiredparentparameter as a local$refto aoneOfunion and fail before the call reaches the MCP server.This PR:
$refschemas during tool-parameter normalization;oneOfobject union so valid Notion-style parent inputs still validate;Validation
pnpm test src/agents/pi-tools.schema.test.ts src/agents/pi-bundle-mcp-tools.materialize.test.ts -- --reporter=verbosepnpm exec oxfmt --check --threads=1 src/agents/pi-tools-parameter-schema.ts src/agents/pi-bundle-mcp-materialize.ts src/agents/pi-tools.schema.test.ts src/agents/pi-bundle-mcp-tools.materialize.test.ts CHANGELOG.mdpnpm check:changedpnpm check:test-typesgit diff --checkReal behavior proof
parentparameter expressed as$ref: #/$defs/parentRequest, whereparentRequestis aoneOfover page/database parent objects, should expose an inlined provider-usable schema and continue to accept a valid{ parent: { page_id } }argument before the MCP call.upstream/mainand PR headf4beb91003afbc90b8569e4090399ac6462ff9b8.upstream/mainandfork/fix-mcp-ref-union-schema; in each worktree rannode --import ./node_modules/tsx/dist/loader.mjs ./probe-mcp-ref-schema.mjs. The probe materialized a real bundled MCP tool namednotion__API-post-pagefrom a schema containing$defs,$ref, andoneOf, then ran the real tool-argument validator with{ parent: { page_id: "page-id" } }.upstream/mainexposes a bundled MCP tool schema that still contains local$ref/$defsand does not exposeparent.oneOfdirectly. PR head exposes the inlinedparent.oneOfschema without$ref/$defs, while the valid Notion page-parent argument still passes validation.