Skip to content

fix(mcp): drop protocol-reserved _meta keys from model-visible output - #2600

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
xpzouying:fix/mcp-meta-reserved-prefix
Aug 4, 2026
Merged

fix(mcp): drop protocol-reserved _meta keys from model-visible output#2600
sailist merged 2 commits into
MoonshotAI:mainfrom
xpzouying:fix/mcp-meta-reserved-prefix

Conversation

@xpzouying

Copy link
Copy Markdown
Contributor

Related Issue

No linked issue — follow-up to #2596, addressing the two Codex review comments left on it.

Problem

#2596 forwards the whole _meta object into the model-visible <mcp-structured-result> block. The MCP spec's _meta key-name rules reserve prefixes whose dot-separated labels include modelcontextprotocol or mcp (e.g. modelcontextprotocol.io/…, tools.mcp.com/…) for protocol use. Entries under those prefixes carry host/protocol plumbing — progress and task wiring, UI component payloads — that servers do not address to the model, so forwarding them leaks side-channel data into the conversation and wastes context.

Separately, the v2 copy of the change carried inline implementation comments, which violates the agent-core-v2 convention that commentary lives only in the module header.

What changed

  • mcpResultToExecutableOutput (v1 mcp/output.ts, v2 agent/mcp/output.ts) now drops _meta keys whose prefix labels include modelcontextprotocol or mcp before serialization. When nothing survives, the _meta section is omitted entirely (and the whole block is omitted if structuredContent is also absent).
  • Unprefixed and vendor-prefixed keys pass through unchanged: their semantics belong to the server, and the host cannot know which of them the model is meant to see — hard-coding vendor knowledge here is exactly the coupling this pipeline avoids.
  • v2 only: the implementation commentary moved from inline comments into the module-header pipeline description, and the serialization try/catch was factored into a comment-free helper.

No changeset: this narrows behavior introduced by #2596, which has not shipped in a release yet — both land in the same next release, so a separate changelog entry would describe a delta users never saw.

Verification

  • New unit tests (mirrored v1/v2): reserved-prefix keys dropped while vendor and unprefixed keys survive; block omitted entirely when every _meta key is reserved.
  • tsc --noEmit and oxlint pass for both packages; output suites pass: 50 tests (v1), 44 tests (v2).

Follow-up to MoonshotAI#2596. The MCP spec reserves _meta key prefixes whose labels
include "modelcontextprotocol" or "mcp" for protocol use; those entries
carry host/protocol plumbing rather than model-facing data, so filter them
out before serializing the <mcp-structured-result> block. Unprefixed and
vendor-prefixed keys still pass through — their semantics belong to the
server. Also moves the v2 implementation commentary into the module header
per the agent-core-v2 comment convention.
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 422c0d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@422c0d8
npx https://pkg.pr.new/@moonshot-ai/kimi-code@422c0d8

commit: 422c0d8

@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: bcb859e1c2

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +228 to +232
function isReservedMetaKey(key: string): boolean {
const slash = key.indexOf('/');
if (slash <= 0) return false;
const labels = key.slice(0, slash).split('.');
return labels.some((label) => label === 'modelcontextprotocol' || label === 'mcp');

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 Limit _meta filtering to prefixes whose second label is reserved

MCP only reserves _meta prefixes when the second dotted label is mcp or modelcontextprotocol; this predicate drops any prefix that contains either label anywhere before /. A server using a valid vendor namespace such as com.example.mcp/trace or org.foo.modelcontextprotocol/... will have that metadata stripped before it reaches the model-visible block, so this change discards legitimate server data.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right — the spec reserves a prefix only when another label follows mcp/modelcontextprotocol (any number of leading labels may precede it, so not strictly the second label). Fixed in 422c0d8: com.example.mcp/… now passes through, with a test pinning it.

…ontextprotocol

Per the spec's key-name rules a prefix is reserved when a
modelcontextprotocol or mcp label is followed by at least one more label;
a trailing reserved word (com.example.mcp/) is a legitimate vendor
namespace and now passes through.
@sailist
sailist merged commit 74c321e into MoonshotAI:main Aug 4, 2026
14 checks passed
mbuckaway pushed a commit to mbuckaway/kimi-code that referenced this pull request Aug 4, 2026
…MoonshotAI#2600)

* fix(mcp): drop protocol-reserved _meta keys from model-visible output

Follow-up to MoonshotAI#2596. The MCP spec reserves _meta key prefixes whose labels
include "modelcontextprotocol" or "mcp" for protocol use; those entries
carry host/protocol plumbing rather than model-facing data, so filter them
out before serializing the <mcp-structured-result> block. Unprefixed and
vendor-prefixed keys still pass through — their semantics belong to the
server. Also moves the v2 implementation commentary into the module header
per the agent-core-v2 comment convention.

* fix(mcp): reserve _meta prefixes only when a label follows mcp/modelcontextprotocol

Per the spec's key-name rules a prefix is reserved when a
modelcontextprotocol or mcp label is followed by at least one more label;
a trailing reserved word (com.example.mcp/) is a legitimate vendor
namespace and now passes through.

---------

Co-authored-by: zouying <zouying@moonshot.cn>
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