Skip to content

fix(anthropic): use Claude Code-compatible MCP tool prefix for OAuth - #17681

Closed
JayGwod wants to merge 1 commit into
NousResearch:mainfrom
JayGwod:fix/anthropic-oauth-mcp-prefix
Closed

JayGwod wants to merge 1 commit into
NousResearch:mainfrom
JayGwod:fix/anthropic-oauth-mcp-prefix

Conversation

@JayGwod

@JayGwod JayGwod commented Apr 30, 2026

Copy link
Copy Markdown

Summary

  • Use Claude Code-compatible mcp__ as the MCP tool-name prefix for native Anthropic OAuth requests.
  • Keep stripping the MCP prefix when normalizing Anthropic tool_use responses back into Hermes tool calls.
  • Cover both request serialization and response normalization with tests.

Why

Claude Code's Anthropic OAuth tool protocol uses a double-underscore MCP marker, for example:

mcp__terminal

Hermes was previously emitting a single-underscore marker on the native Anthropic OAuth path:

mcp_terminal

That can make Hermes OAuth tool requests diverge from the Claude Code-compatible shape even though the request is otherwise using Claude Code/OAuth beta headers. Using the same mcp__ marker makes the OAuth tool schema consistent with Claude Code-style MCP tool naming.

This PR is intentionally scoped only to tool-name compatibility. It does not claim to change Anthropic account/billing behavior such as extra-usage gating.

Tests

./venv/bin/python -m py_compile agent/anthropic_adapter.py agent/transports/anthropic.py
./venv/bin/python -m pytest -o 'addopts=' tests/agent/test_anthropic_adapter.py -q

Result:

140 passed

Additional sanity checks verified:

  • OAuth request tool name serializes as mcp__terminal.
  • Response normalization strips mcp__terminal back to Hermes tool name terminal.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API area/auth Authentication, OAuth, credential pools labels Apr 30, 2026
@JayGwod

JayGwod commented May 2, 2026

Copy link
Copy Markdown
Author

Bumping — open for ~2 days.

Status on current upstream/main (f903ceece):

  • Applies cleanly, no rebase needed.
  • pytest tests/agent/test_anthropic_adapter.py -k "mcp or prefix" → 5 passed on a worktree at f903ceece with this commit on top.

Context: this is the prefix companion to the context-1m beta fix in #17680#17752. Anthropic's OAuth path expects MCP tool names to use Claude Code's double-underscore convention (mcp__server__tool). Without it, OAuth + MCP sessions get a 400 from the Anthropic API on tool registration even after the beta-header fix lands.

Happy to take feedback if you'd prefer this fold into a different code path. Thanks!

@JayGwod
JayGwod force-pushed the fix/anthropic-oauth-mcp-prefix branch 5 times, most recently from 31f8e92 to 7ec9dd1 Compare May 9, 2026 15:23
@JayGwod
JayGwod force-pushed the fix/anthropic-oauth-mcp-prefix branch 2 times, most recently from b2849ab to 0fbddca Compare May 12, 2026 15:58
@JayGwod
JayGwod force-pushed the fix/anthropic-oauth-mcp-prefix branch 4 times, most recently from d3d36a7 to 2d9e685 Compare May 22, 2026 18:14
@JayGwod
JayGwod force-pushed the fix/anthropic-oauth-mcp-prefix branch from 2d9e685 to 1725d32 Compare May 27, 2026 21:26
@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused compatibility fix. This is an automated hermes-sweeper review; current main now provides this behavior and a broader MCP-server-safe round trip.

  • b70a4e7533dce506a41f847b3fc082d6b6fe4a9b implements mcp__ normalization for bare and MCP-server tool names on the Anthropic OAuth wire.
  • agent/anthropic_adapter.py:2570-2581 preserves existing mcp__ names, promotes legacy mcp_ names, and prefixes bare tools.
  • agent/transports/anthropic.py:134-153 maps the response back to the name registered by Hermes.
  • tests/agent/test_anthropic_mcp_prefix_strip.py:179-255 covers the request and response invariants, including the MCP-server case described in the PR discussion.

Closing as implemented on main.

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

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants