Sanitize hostile ability input schemas before tool conversion#46
Sanitize hostile ability input schemas before tool conversion#46dennisdornon wants to merge 1 commit into
Conversation
A PHP dashboard serializing an empty properties map as [] (seen live on
two experiment-branch abilities) invalidated the entire tools/list
response for spec-compliant MCP clients: the official SDK rejects the
payload, leaving the server connected with zero usable tools. Coerce
non-object properties to {} and drop malformed required entries, per
the treat-remote-schemas-as-hostile rule.
Claude-Session: https://claude.ai/code/session_01NnJiXybDffmpEsdwE1cnYT
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesInput Schema Sanitization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
|
Closing: this fix ships inside the upcoming code-review-cleanup PR, where it was developed alongside its acceptance-test coverage. Splitting it out was unnecessary. |
What changed
convertInputSchemainsrc/tool-schema.tsnow coerces a non-objectpropertiesfield to{}and drops non-string entries fromrequiredbefore building the MCP tool definition. Newsrc/tool-schema.test.tspins the behavior with five regression tests (four failed before the fix).Why
A PHP dashboard that registers an ability with an empty properties map serializes it as
[], and the server passed that straight through totools/list. Spec-compliant MCP clients validate the whole response, so one malformed ability took every tool offline: the official SDK rejects the payload with a zod error, and Claude Code showed the server as connected with zero usable tools. Two abilities on a dashboard experiment branch triggered this in practice.This is the treat-remote-schemas-as-hostile rule applied to schema shape, not only to content.
Review focus
The coercion happens before the description backfill loop, so a malformed schema now yields a valid empty-input tool instead of poisoning the catalog. Check that you agree silently coercing (rather than dropping the ability) is the right failure mode; the ability is still callable and the dashboard-side schema bug stays visible in its own API output.
Verification
npm test(446 passing, includes the 5 new regressions),npm run lint(0 errors),npm run format:check,npm run buildtools/listwent from a client-side zod rejection to 71 valid tools, verified with the official MCP SDK clienthttps://claude.ai/code/session_01NnJiXybDffmpEsdwE1cnYT
Summary by CodeRabbit
Bug Fixes
Tests