fix(agent-core/mcp): support tuple array items in JSON Schema sanitizer
Related Issue
Resolve #(issue_number)
Problem
What changed
Checklist
- [x] I have read the CONTRIBUTING document.
- [x] I have linked a related issue, or explained the problem above.
- [x] I have added tests that prove my feature works.
- [x] Ran
gen-changesetsskill, or this PR needs no changeset. - [x] Ran
gen-docsskill, or this PR needs no doc update.
🦋 Changeset detected
Latest commit: 574418902fbc1e8c4c89c4d8b0937ecb295ef1a5
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @moonshot-ai/agent-core | Patch |
| @moonshot-ai/kimi-code | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
This branch incorporates a critical schema-compatibility fix that resolves a startup/inference crash when using model providers with strict JSON Schema requirements (specifically the Moonshot/Kimi API validator).
The Issue (Continuing from #830)
In addition to the circular reference checks introduced in #830, standard MCP servers (like the generative @mcp-z/mcp-pdf server) advertise tuple parameter arrays using standard JSON Schema Draft-07 syntax, where items is an array of schemas, for example:
"size": {
"anyOf": [
{ "type": "string", "enum": ["LETTER", "A4", "LEGAL"] },
{ "type": "array", "items": [{"type": "number"}, {"type": "number"}] }
]
}
However, the Moonshot/Kimi API validator rejects this structure, enforcing that the items property of any array-type parameter must be a single schema object, leading to a 400 Bad Request during initialization:
tools.function.parameters is not a valid moonshot flavored json schema, details: <At path 'properties.pageSetup.properties.size.anyOf.items': items must be an object>
What Changed
We extended sanitizeMcpSchema in packages/agent-core/src/mcp/schema-sanitize.ts to intercept array-based items schemas and transform them into an object-based { anyOf: items } schema (which represents the exact same validation rule but matches the stricter validator expectations).
With this fix, @mcp-z/mcp-pdf and other tuple-based MCP servers connect and run successfully under the Moonshot/Kimi API.
Successfully merged upstream origin/main into debian1branch and resolved all conflicts.
Superseded by the cleaned-up #830 (rebased on latest main, Codex review feedback addressed, no plugin/lockfile noise). Please review https://github.com/MoonshotAI/kimi-code/pull/830