Skip to content

fix(agent-core/mcp): sanitize MCP JSON Schemas for Moonshot MFJS vali… - #2242

Closed
creatiVision wants to merge 1 commit into
MoonshotAI:mainfrom
creatiVision:fix/mcp-schema-sanitize-clean
Closed

fix(agent-core/mcp): sanitize MCP JSON Schemas for Moonshot MFJS vali…#2242
creatiVision wants to merge 1 commit into
MoonshotAI:mainfrom
creatiVision:fix/mcp-schema-sanitize-clean

Conversation

@creatiVision

Copy link
Copy Markdown

…dator

Resolve local $ref (with RFC 6901 pointer unescaping and circular-safe inlining), fill missing property types, normalize tuple items arrays, and split mixed-type enums into typed anyOf branches. Also map common config aliases (disabled→enabled, max_tokens→maxOutputSize).

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.

…dator

Resolve local $ref (with RFC 6901 pointer unescaping and circular-safe
inlining), fill missing property types, normalize tuple items arrays,
and split mixed-type enums into typed anyOf branches. Also map common
config aliases (disabled→enabled, max_tokens→maxOutputSize).
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a0fc9fe

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: a0fc9fe2a5

ℹ️ 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 on lines +171 to +173
if (Array.isArray(items)) {
for (const value of items) normalizeProperty(value);
record['items'] = { anyOf: items };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve positional semantics when normalizing tuple items

When an MCP server advertises a draft-07 tuple such as items: [{ type: 'string' }, { type: 'number' }], replacing it with items: { anyOf: ... } changes the contract from positional validation to allowing either type at every position. Since the resulting Tool.parameters is also compiled by validateExecutableToolArgs, malformed calls such as [1, 'x'] now pass local validation and reach the MCP server. Preserve the original tuple semantics rather than converting it to a homogeneous union.

Useful? React with 👍 / 👎.

Comment on lines +109 to +110
if (typeof current !== 'object' || current === null || Array.isArray(current)) {
throw new Error(`Unable to resolve reference path: ${pointer}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve array segments in local JSON Pointers

For a valid local reference such as #/$defs/Choice/anyOf/0, traversal reaches the anyOf array before processing segment 0, and this condition throws instead of resolving the array index. The exception propagates through connectAndDiscoverTools, causing connectOne to mark the entire MCP server failed, so one such schema prevents all of that server's tools from loading. Handle numeric RFC 6901 array segments during pointer resolution.

Useful? React with 👍 / 👎.

Comment on lines +140 to +141
const { $ref: _, ...rest } = record;
return { ...(target as JsonRecord), ...rest };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Dereference schema content in $ref siblings

When a draft 2020-12 $ref node has sibling schema content containing another local reference, the sibling values in rest are merged without passing through traverse. The root definition buckets are subsequently deleted, leaving that nested reference dangling; Ajv then fails to compile the tool schema and every invocation is rejected. Traverse the sibling values before merging them into the resolved target.

Useful? React with 👍 / 👎.

@creatiVision

Copy link
Copy Markdown
Author

Duplicate of #830 (same MCP schema sanitize fix). Closing in favor of #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.

1 participant