fix(mcp): drop protocol-reserved _meta keys from model-visible output - #2600
Conversation
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.
|
commit: |
There was a problem hiding this comment.
💡 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".
| 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'); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
…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>
Related Issue
No linked issue — follow-up to #2596, addressing the two Codex review comments left on it.
Problem
#2596 forwards the whole
_metaobject into the model-visible<mcp-structured-result>block. The MCP spec's_metakey-name rules reserve prefixes whose dot-separated labels includemodelcontextprotocolormcp(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-v2convention that commentary lives only in the module header.What changed
mcpResultToExecutableOutput(v1mcp/output.ts, v2agent/mcp/output.ts) now drops_metakeys whose prefix labels includemodelcontextprotocolormcpbefore serialization. When nothing survives, the_metasection is omitted entirely (and the whole block is omitted ifstructuredContentis also absent).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
_metakey is reserved.tsc --noEmitandoxlintpass for both packages; output suites pass: 50 tests (v1), 44 tests (v2).