Skip to content

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
mainfrom
kimi-code-port/mcp-meta-passthrough
Open

Surface MCP tool-result _meta to the model, minus protocol-reserved keys (port from kimi-code)#80712
teknium1 wants to merge 1 commit into
mainfrom
kimi-code-port/mcp-meta-passthrough

Conversation

@teknium1

@teknium1 teknium1 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

MCP tool results now surface the server _meta mapping 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 _meta were invisible to the agent.

Ported from MoonshotAI/kimi-code#2596 + #2600 (their <mcp-structured-result> block), adapted to Hermes' existing JSON tool-output shape in tools/mcp_tool.py.

Changes

  • tools/mcp_tool.py: _make_tool_handler result assembly includes _meta (SDK exposes wire _meta as .meta); new _is_reserved_mcp_meta_key() / _strip_reserved_meta_keys() helpers implement the MCP spec 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.
  • 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

Before After
_meta in tool output dropped included, reserved keys filtered
tests/tools/test_mcp_structured_content.py 3 passed 11 passed
Real SDK check CallToolResult.model_validate({..., "_meta": {...}}).meta present, filter verified

Infographic

MCP _meta passthrough

…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.
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 295d701

⚠️ Warnings

OSV vulnerability scan · View job

50 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 3m28s vs 6m14s (-44.4%). 12 job(s) slower, 10 faster, 1 unchanged.

  • Python tests / Run tests slice 1/12: +21.0s
  • Python tests / Run tests slice 9/12: -19.0s
  • Python tests / Run tests slice 8/12: +10.0s
  • Python tests / Run tests slice 10/12: +9.0s
  • Python tests / Run tests slice 6/12: -8.0s

@alt-glitch alt-glitch added type/feature New feature or request tool/mcp MCP client and OAuth P3 Low — cosmetic, nice to have labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants