Skip to content

fix(mcp): show verifiers an MCP tool's own name under every harness - #7070

Open
cwing-nvidia wants to merge 12 commits into
mainfrom
cwing/mcp-tool-names-for-verifiers
Open

cwing-nvidia wants to merge 12 commits into
mainfrom
cwing/mcp-tool-names-for-verifiers

Conversation

@cwing-nvidia

@cwing-nvidia cwing-nvidia commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A verifier that checks for a tool call has to know how each harness names an MCP tool for its model. The same tool, get_weather on a server named weather, reaches a verifier as mcp__weather__get_weather, weather__get_weather, weather_get_weather or get_weather, depending on the harness. A verifier written against one harness reports a false failure under another, and on main a task folder's verifier gets the raw harness name under every harness.

With this change a verifier checks for the tool's own name, get_weather, under every harness. The rollout keeps the name the model emitted.

Closes #2668. Supersedes #2673, which carried the tool's identity on the verify request and no longer fits main, where the environment server calls /verify and task folders have no resources server.

What changed

  • Each agent adapter declares how its harness names an MCP tool (MCPToolNaming) and records, in the response's metadata, which server and tool each emitted name stands for. Names are resolved against the MCP servers Gym configured for the session, not by splitting on a separator. Covers Claude Code, Hermes, Kilo, OpenClaw, OpenCode and Pi. Hermes and Pi no longer rewrite the names in the response.

  • A resources server that serves its tools over MCP shows its verifier the tool's own name at /verify, and returns the emitted names in its reply as before.

  • The trajectory file a task folder's verifier reads (/logs/agent/trajectory.json), and the ATIF export of a saved rollout, use the tool's own name as function_name, with mcp_server and emitted_name under extra.nemo_gym.

  • Each tool call of a rollout's trajectory carries mcp_server and mcp_tool beside tool_name, which stays the emitted name.

  • Tool metrics count an MCP tool under its own name. Its span adds nemo.gym.tool.emitted_name and nemo.gym.tool.mcp_server.

  • A name that belongs to one of the session's MCP servers but cannot be resolved (the harness may have cut it, or two servers match it) becomes an mcp_tool_name_unresolved observation gap, and /verify leaves it as emitted.

  • A resources server warns at startup about tools whose name, with the server's, reaches 64 characters, where some harnesses cut the name. A shorter mcp_server_name avoids it.

  • An agent declares its naming as mcp_tool_naming on its class. When a session closes, every tool call the session observed gets its MCP server and tool, including calls a subagent made and calls of earlier activations of a continued session, which no single response lists.

  • Rebuilding a response from an exported trajectory restores the emitted name and the record of its server and tool, so reverification credits a resources server only for its own tools when two servers serve a tool of the same name.

Compatibility

  • A task-folder verifier that matched a raw harness name such as mcp__<server>__<tool> in the trajectory file now sees the tool's own name. The raw name is in extra.nemo_gym.emitted_name.
  • Responses from Hermes and Pi sessions now hold the name the model emitted, not mcp__<grant>__<tool>. A resources server's /verify scores them the same.
  • nemo.gym.tool.name for an MCP tool changes from the harness's name to the tool's own name.
  • A rollout with an mcp_tool_name_unresolved gap is refused by the strict ATIF export, like any rollout with a gap.
  • Rollouts stored before this change have no record. /verify still strips mcp__<server>__ and accepts <server>__<tool>, <server>_<tool> and mcp_<server>_<tool> when the server serves a tool of that name.

Validation

Unit tests: 3,009 passed, 28 skipped, none failed across the repository-wide checks, tests/unit_tests/trajectory, the new tests and the six adapters' MCP tests. pre-commit run on the changed files passed, including the import-linter contract.

Real rollouts, Claude Sonnet 4.6, Docker sandboxes, main at dd09637 against this branch.

Resources server path: example_single_tool_call with expose_tools_over_mcp: true behind single_agent_turn; its verifier gives reward 1 only for a call named exactly get_weather. Two episodes each.

Harness Emitted name Reward on main Reward on this branch
OpenClaw 2026.11.5 example_single_tool_call__get_weather 0, 0 1, 1
OpenCode 1.17.11 example_single_tool_call_get_weather 0 (one episode made no tool call) 1 (one episode made no tool call)
Kilo 7.4.15 example_single_tool_call_get_weather 0 (one episode made no tool call) 1 (one episode made no tool call)
Hermes mcp__example_single_tool_call__get_weather 1, 1 1, 1
Pi 1.5.2 example_single_tool_call_get_weather 1, 1 1, 1
Claude Code 2.1.312, through its own /run mcp__example_single_tool_call__get_weather 1, 1 1, 1

The OpenClaw and Hermes rows are from the head of this branch. The OpenCode, Kilo, Pi and Claude Code rows are from this branch's first two commits (the adapter and /verify changes), before the trajectory commits and the review fix; they were not rerun at the head. In the Kilo episode with the tool call, a later model call failed, so its response status is failed on both trees.

Task folder path: a task with one streamable-http MCP server (hello-tools, tool get_greeting), task_mcp_grants: required, and a tests/test.sh that gives reward 1 only if the trajectory file has a call whose function_name is exactly get_greeting. One episode each.

Harness function_name on main Reward on main function_name on this branch Reward on this branch
OpenClaw hello-tools__get_greeting 0 get_greeting 1
Hermes mcp__hello-tools__get_greeting 0 get_greeting 1
Pi mcp__hello-tools__get_greeting 0 get_greeting 1
OpenCode hello-tools_get_greeting 0 get_greeting 1

Not run: Kilo on the task folder path (the request did not complete on main or on this branch, cause not found), and Claude Code on the task folder path (its sessions take no MCP grants). The unresolved-name gap, the startup warning and the span attributes are covered by unit tests only.

The last commit (reverification, subagent calls, continued sessions) answers the automated review and is covered by unit tests only: a round trip through the export for two servers serving a tool of one name, a session close with subagent and earlier-activation calls, and the shared resolver. No real rollout was run on it.

Known limits

  • Each declaration encodes one harness's naming. If a harness changes how it names tools, its calls keep the emitted name until the declaration is updated, and nothing flags it. Resolving names against each server's tool list would remove the declarations; that is left for a follow-up.
  • Where a harness joins server and tool with _, a tool of its own named <server>_<something> is taken as that server's tool. A resources server rejects it by its tool list; a task folder has no tool list to check against.
  • A name a harness cut or replaced with a hash cannot be resolved. A name of exactly 64 characters under Hermes or OpenClaw counts as possibly cut.
  • A task folder's own MCP servers get no startup warning, because their tools are not known before a harness connects.

…servers

Each harness shows its model an MCP tool under its own name (Claude Code mcp__<server>__<tool>, OpenClaw <server>__<tool>, older Hermes mcp_<server>_<tool>), and a verifier that compares tool names literally scored the same call differently per harness. Hermes and Pi each carried a private rename; OpenClaw had none, so its MCP calls reached verify as <server>__<tool>.

Add nemo_gym.agents.mcp_tool_names: an adapter declares its harness's scheme as an MCPToolNaming, and name_mcp_tool_calls renames a response's MCP calls to Gym's mcp__<server>__<tool>, which the tool's resources server already strips before verify. Names are resolved against the MCP servers Gym configured for the session, not split on a separator, so server and tool names that hold underscores resolve exactly.

Use it in the OpenClaw adapter (new), the Hermes adapter (replacing its private helper, same behavior) and Claude Code's /run (restores a server name Claude Code rewrote). The verify request and response are unchanged.

Refs #2668

Signed-off-by: Chris Wing <[email protected]>
The first commit renamed MCP calls in the response, so a stored rollout lost the name the model emitted. Adapters now leave function-call names as emitted and record, in the response's nemo_gym_mcp_tool_identities metadata, the configured server and tool each emitted name stands for. A resources server that serves its tools over MCP reads that record in its /verify wrapper, scores the tool's own name, and restores the emitted names in what is stored. BaseVerifyRequest and BaseVerifyResponse are unchanged.

Resolution is exact against the session's servers: a name that more than one server's prefix matches, or that the harness may have cut, is not resolved. OpenClaw's server-name rewriting (sanitizing, mcp- prefix, 30-character cap, numbering) and 64-character bound are ported from its 2026.6.11 source; Hermes gets its 64-character clamp guard.

Pi, Hermes, OpenClaw, OpenCode, Kilo and Claude Code now share nemo_gym.agents.mcp_tool_names; Pi's and Hermes' private helpers are gone.

Rollouts stored without a record: /verify still strips mcp__<server>__, and now also accepts this server's own <server>__, <server>_ and mcp_<server>_ aliases when what follows is one of its tools and the whole name is not.

Refs #2668

Signed-off-by: Chris Wing <[email protected]>
…fiers

A verifier that checks for a tool call had to know how the harness names an
MCP tool for its model. The agent adapter's record of the server and tool
behind each emitted name was applied only in a resources server's /verify.

Carry it where the other readers look:
- Each tool attempt of a rollout's trajectory has mcp_server and mcp_tool
  beside tool_name, which stays the name the model emitted.
- The trajectory file a task folder's verifier reads, and the ATIF export of
  a saved rollout, name such a call by the tool's own name, with mcp_server
  and emitted_name under extra.nemo_gym.

The record's reader moves to nemo_gym.core so the trajectory package can
use it.

Refs #2668

Signed-off-by: Chris Wing <[email protected]>
…by their own names

- A tool span and the tool metrics name an MCP tool by its own name; the
  span keeps the emitted name and the server beside it.
- A name that belongs to one of the session's MCP servers but cannot be
  resolved, because the harness may have cut it or two servers match it,
  is recorded on the response and becomes an mcp_tool_name_unresolved
  observation gap.
- A resources server that serves its tools over MCP warns at startup about
  tools whose name, with the server's, reaches the 64 characters where a
  harness may cut it.
- Glossary: tool's own name, emitted name.

Refs #2668

Signed-off-by: Chris Wing <[email protected]>
The tutorial listed how two harnesses name MCP tools, which goes stale when
a harness changes. Say what a verifier checks for and point to each agent's
README. Tell harness authors to cover their naming with a transcript from
the pinned harness version.

Signed-off-by: Chris Wing <[email protected]>
Found in review of the branch:
- /verify still guessed at a name the agent adapter had recorded as
  unresolved, through the alias fallback for older rollouts.
- A harness tool of its own whose name starts like the server's, such as
  store_fetch beside a server named store, was recorded as that server's
  tool and shown to the verifier as fetch. The server now takes a recorded
  tool only when it serves a tool of that name.
- Agent adapters import MCPToolNaming and record_mcp_tool_identities from
  nemo_gym.agents, the package's public API.
- Annotations in the added code use X | None.

Signed-off-by: Chris Wing <[email protected]>
The MCP tutorial and the harness guide already say which name a verifier
checks for.

Signed-off-by: Chris Wing <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cwing-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test c953741

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:high Autobot PR risk: high bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Dec 2, 2026
@cwing-nvidia
cwing-nvidia marked this pull request as ready for review December 2, 2026 04:44
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Dec 2, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

HOLD

I found one BLOCKER and two RISKs. ATIF reverification can credit a foreign server’s tool call to the verifier’s own server. The identity propagation also misses child-only calls and earlier activations in continued sessions.

I reviewed all 34 changed files and connected consumers with three delegated topic reviewers.

Validation:

  • I relied on successful head CI checks: Lint check, Nemo_CICD_Test, Unit tests / Test, Unit tests / Server suite, and Unit tests / Combined core coverage. Core/server shards, sandbox tests, and session-routing tests also succeeded. Harness conformance and environment compliance have nonblocking failures; I have not attributed those failures to this change.
  • CPU probes ran in 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:146389feffb52af5b4cfd138b5c89fe5dc123016, the default-branch CI image. The head’s container build was skipped. Identity serialization, verify echo/reverification, ambiguity handling, partial responses, and normal ATIF projection passed the focused probes.
  • A base-versus-head HTTP verifier probe reproduced reward changing from 0 to 1 after ATIF export/reverification only on head. Mocked Kilo/Hermes adapter probes reproduced missing child identities. A cumulative-session probe reproduced missing earlier identities and unresolved-name gaps.

I did not rerun green repository suites or execute real harness/model rollouts.

Note: formal approval is not available for this request, so this review is posted as a comment only.


Inline comments (escaped v1):

  • nemo_gym/trajectory/atif_reverification.py line 383: BLOCKER: Preserve MCP server identity during ATIF reverification.

    The exporter now writes the bare tool name into function_name and keeps its server in extra.nemo_gym. This unchanged consumer copies only function_name, so the server distinction disappears. A call to other.get_weather then reaches the weather verifier as its own get_weather.

    I reproduced this through build_atif_verify_payload and a real FastAPI /verify wrapper using /workspace/review-probes/leader/probe_atif_reverify.py. On head, direct reward is 0.0 and the exported/reverified reward is 1.0; both rewards are 0.0 on the admitted base. This silently changes scores for exported MCP rollouts.

    Could you consume the per-call MCP identity when rebuilding the response? Restore distinct server-qualified names, or emitted names plus identity metadata, and keep that information through the materialized-request overlay. A map keyed only by the bare name cannot distinguish two servers sharing it. Keep bare names in the task-verifier ATIF file and preserve ordinary ATIF documents without this extension.

    Acceptance: round-trip both live and saved exports containing weather.get_weather and other.get_weather; direct and reverified rewards must agree, and only the weather server’s call may receive credit.

  • nemo_gym/agents/mcp_tool_names.py line 111: RISK: Resolve child-only tool calls from the observation bundle too.

    This loop scans only the root response.output. Kilo deliberately keeps child output in its family observations, as its existing separation test shows. Hermes also imports delegated tool calls separately from the root response. A tool used only by a child therefore never enters the identity map, so the new trajectory, ATIF, and telemetry paths keep its harness-specific name.

    Mocked production-adapter probes confirm this for both harnesses. /workspace/review-probes/mcp-identity-1/child_kilo_probe.py produces recorded identities: {} and grandchild weather_get_weather None None despite a configured weather grant. The Hermes delegation probe produces the same missing MCP fields.

    Could you resolve the collected observation tool names with the same naming scheme and record their identities and unresolved gaps before trajectory assembly? Keep emitted names intact and keep child output separate from the root response.

    Acceptance: child-only Kilo and Hermes MCP calls must carry mcp_server='weather' and mcp_tool='get_weather', with canonical export/metric names. Cover an unresolved child call and an ordinary non-MCP child tool while retaining the root-output separation test.

  • nemo_gym/rollouts/trajectory_builder.py line 562: RISK: Enrich every activation in a continued episode.

    This reads identities and unresolved names only from the final response. Harbor’s continued-episode result combines the last activation’s response with the whole session’s observations and trajectory. Earlier tool names absent from the final response therefore get no MCP identity, and earlier unresolved-name markers disappear.

    /workspace/review-probes/leader/probe_cumulative.py reproduces weather__get_weather retaining (None, None) while the final activation’s weather__forecast resolves. An unresolved marker retained on the first turn produces no final mcp_tool_name_unresolved gap. Metrics and exports consequently depend on which tools the last activation repeats.

    Could you attach identities and unresolved gaps to activation-owned evidence before accumulation, or consume the retained per-turn responses with their invocation ownership? Preserve emitted names and avoid assigning one activation’s identity to unrelated attempts by name alone.

    Acceptance: a two-activation continuation that calls different MCP tools must retain both identities and canonical metric/export names. An unresolved call in the first activation must still appear as a gap after the second activation.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

…bagents and continued sessions

From review:
- Rebuilding a response from an exported trajectory took only
  function_name, the tool's own name, and dropped its server. A call of
  another server's tool of the same name was then credited to the
  verifying server. The response now gets the emitted name back with the
  record of its server and tool, and the record survives the task's own
  request metadata.
- The record was built from the response's own tool calls. Calls a
  subagent made, and calls of earlier activations of a continued session,
  are only in the session's observations. An agent that declares
  mcp_tool_naming now has every observed tool call resolved when its
  session closes, with unresolved names added as gaps there.

Signed-off-by: Chris Wing <[email protected]>
@cwing-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 69f55e7

Conflict in nemo_gym/agents/base_responses_api_agent.py: both sides added
imports beside agent_outcome. Kept main's and this branch's.

Signed-off-by: Chris Wing <[email protected]>
@cwing-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 5e01928

@nemo-pr-automation
nemo-pr-automation Bot requested review from a team December 2, 2026 17:17
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Dec 3, 2026
Conflict in responses_api_agents/claude_code_agent/app.py: main added
classify_outcome at the top of ClaudeCodeAgent, where this branch declares
mcp_tool_naming. Kept both.

Signed-off-by: Chris Wing <[email protected]>
@cwing-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 60370d9

Conflicts in nemo_gym/agents/base_responses_api_agent.py and
responses_api_agents/opencode_agent/app.py: main and this branch each added
an import on the same line. Kept both.

Signed-off-by: Chris Wing <[email protected]>
@cwing-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 9eadac5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: MCP tool identity not preserved for verification

2 participants