Skip to content

fix(agent-core/mcp): support tuple array items in JSON Schema sanitizer#1605

Closed
creatiVision wants to merge 14 commits into
MoonshotAI:mainfrom
creatiVision:debian1branch
Closed

fix(agent-core/mcp): support tuple array items in JSON Schema sanitizer#1605
creatiVision wants to merge 14 commits into
MoonshotAI:mainfrom
creatiVision:debian1branch

Conversation

@creatiVision

@creatiVision creatiVision commented Jul 13, 2026

Copy link
Copy Markdown

Related Issue

Resolve #(issue_number)

Problem

What changed

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5744189

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a2f70e31d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/mcp/connection-manager.ts Outdated
@creatiVision

Copy link
Copy Markdown
Author

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.

@creatiVision

Copy link
Copy Markdown
Author

Successfully merged upstream origin/main into debian1branch and resolved all conflicts.

@creatiVision creatiVision changed the title Debian1branch fix(agent-core/mcp): support tuple array items in JSON Schema sanitizer Jul 13, 2026
@creatiVision

Copy link
Copy Markdown
Author

Superseded by the cleaned-up #830 (rebased on latest main, Codex review feedback addressed, no plugin/lockfile noise). Please review #830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants