Skip to content

fix(anthropic): use double-underscore mcp__ prefix for OAuth tool names - #46687

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/oauth-mcp-double-underscore-prefix
Closed

fix(anthropic): use double-underscore mcp__ prefix for OAuth tool names#46687
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/oauth-mcp-double-underscore-prefix

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Changes the Anthropic OAuth tool-name prefix from single underscore (mcp_) to double underscore (mcp__) so that tool-using requests over Max OAuth are correctly classified as Claude Code and route to plan billing instead of being rejected as third-party (HTTP 400).

Related Issue

Fixes #46675

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/anthropic_adapter.py: Changed _MCP_TOOL_PREFIX from "mcp_" to "mcp__". Updated startswith guards to check both "mcp__" and "mcp_" prefixes via a _MCP_SKIP tuple, preventing double-prefixing of native MCP server tools that use the legacy single-underscore format.
  • agent/transports/anthropic.py: Changed the local _MCP_PREFIX from "mcp_" to "mcp__" in normalize_response so the response-side stripping matches the new outgoing prefix.
  • tests/agent/test_anthropic_mcp_prefix_strip.py: Updated all test assertions to use mcp__ prefix. Added test_legacy_single_underscore_native_mcp_not_stripped to verify that native MCP tools with the old mcp_ format are not incorrectly stripped.

How to Test

  1. Configure an Anthropic Max OAuth token: hermes auth add anthropic --type oauth
  2. Start a conversation with tools enabled (default)
  3. Verify the request returns HTTP 200 with service_tier: standard (plan-eligible)
  4. If MCP servers are configured, verify their tools still work (not double-prefixed)
  5. Run: pytest tests/agent/test_anthropic_mcp_prefix_strip.py -v

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/agent/test_anthropic_mcp_prefix_strip.py -v and all 12 tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A (pure string constant change, no platform-specific behavior)
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

Anthropic's Claude-Code request classifier treats tool names with a
single-underscore `mcp_<x>` prefix as non-Claude-Code / third-party,
routing the request to extra-usage billing (HTTP 400). Real Claude Code
uses double underscores: `mcp__<server>__<tool>`.

Change the tool-name prefix from `mcp_` to `mcp__` in both the outgoing
path (build_anthropic_kwargs) and the incoming path
(normalize_response). Update the skip-guard to check for both `mcp_`
and `mcp__` prefixes so native MCP server tools (which use the legacy
single-underscore format) are not double-prefixed.

Fixes NousResearch#46675
@alt-glitch alt-glitch added type/bug Something isn't working 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 P1 High — major feature broken, no workaround labels Jun 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: fix PR for #46675.

@fzlzjerry

Copy link
Copy Markdown

can we merge it

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Superseded by #47723, which cherry-picks this commit (your mcp_mcp__ change, authorship preserved in git history) and extends it to also normalize single-underscore mcp_<server>_<tool> MCP-server tool names — the gap that left sessions with an MCP server configured still billing to extra usage. Thanks for the original fix; it's carried forward in #47723. Closing this in favor of the combined PR.

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 P1 High — major feature broken, no workaround provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Max OAuth requests rejected as third-party (HTTP 400 "extra usage") due to single-underscore mcp_ tool-name prefix

4 participants