Surface MCP tool-result _meta to the model, minus protocol-reserved keys (port from kimi-code) - #80712
Open
teknium1 wants to merge 1 commit into
Open
Surface MCP tool-result _meta to the model, minus protocol-reserved keys (port from kimi-code)#80712teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
…eta to the model, minus protocol-reserved keys MCP tool results carry a server _meta mapping (exposed as .meta by the Python SDK) alongside structuredContent. Servers return namespaced machine-readable contracts there (validated payloads, browser-handoff URLs); Hermes previously dropped the field entirely, so that data was invisible to the agent. Now _meta is included in the JSON tool output, after filtering protocol-reserved keys per the MCP spec's key-name rules: a prefix is reserved when a modelcontextprotocol or mcp label is followed by at least one more label (modelcontextprotocol.io/..., tools.mcp.com/...). Vendor namespaces with a trailing reserved word (com.example.mcp/...) and unprefixed keys pass through. Non-serializable metadata drops the extras rather than failing the call.
Contributor
૮ >ﻌ< ა ci reviewran on 295d701
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MCP tool results now surface the server
_metamapping to the model, with protocol-reserved keys filtered out. Previously the field was dropped entirely, so servers returning namespaced machine-readable contracts (validated payloads, browser-handoff URLs) in_metawere invisible to the agent.Ported from MoonshotAI/kimi-code#2596 + #2600 (their
<mcp-structured-result>block), adapted to Hermes' existing JSON tool-output shape intools/mcp_tool.py.Changes
tools/mcp_tool.py:_make_tool_handlerresult assembly includes_meta(SDK exposes wire_metaas.meta); new_is_reserved_mcp_meta_key()/_strip_reserved_meta_keys()helpers implement the MCP spec key-name rules — a prefix is reserved when amodelcontextprotocolormcplabel is followed by at least one more label (modelcontextprotocol.io/...,tools.mcp.com/...); vendor namespaces with a trailing reserved word (com.example.mcp/...) and unprefixed keys pass through. Non-serializable metadata drops the extras rather than failing the call.tests/tools/test_mcp_structured_content.py: 8 new tests (passthrough, reserved-key filtering, all-reserved omission, combination with structuredContent, non-serializable, non-dict, predicate unit tests).Validation
_metain tool outputCallToolResult.model_validate({..., "_meta": {...}})→.metapresent, filter verifiedInfographic