Skip to content

fix: stop mcp_ tool prefixing to avoid billing validation rejection#189

Closed
Kuenec wants to merge 3 commits intogriffinmartin:mainfrom
Kuenec:fix/billing-validation-tool-names
Closed

fix: stop mcp_ tool prefixing to avoid billing validation rejection#189
Kuenec wants to merge 3 commits intogriffinmartin:mainfrom
Kuenec:fix/billing-validation-tool-names

Conversation

@Kuenec
Copy link
Copy Markdown

@Kuenec Kuenec commented Apr 14, 2026

Summary

Fixes #188, fixes #190

Anthropic's OAuth billing validation rejects requests containing mcp_-prefixed tool names when 3 or more tools are present, returning a spurious 400 "You're out of extra usage" error even when the user has a valid Claude Max subscription with remaining usage. Additionally, the bare tool names todowrite, background_output, and background_cancel are independently rejected by the validator.

Root Cause

The plugin was applying a blanket mcp_ prefix to every tool name (e.g., Readmcp_Read). Anthropic's server-side billing validation treats this prefix pattern as a signal of a non-Claude-Code client and rejects the request once 3+ tools are present.

Separately, the auth loader omitted an explicit baseURL, causing the AI SDK to construct incorrect API endpoint URLs (/messages instead of /v1/messages), resulting in 404 errors.

Approach

This PR removes the mcp_ prefix entirely rather than attempting to preserve it with casing workarounds (e.g., PascalCasing after the prefix). Removing the prefix is the better approach because:

  • Eliminates the root cause. The mcp_ prefix is what triggers the billing validation rejection. Keeping it in any form leaves the fix dependent on Anthropic not tightening validation further.
  • Reduces surface area. Only the three specifically blocked tool names (todowrite, background_output, background_cancel) need renaming. All other tool names pass through untouched.
  • Simpler response handling. The reverse mapping in stripToolPrefix only needs to restore the three renamed tools, rather than transforming every tool name on every response.

Changes

src/transforms.ts

  • Remove blanket mcp_ prefixing of all tool names in both tool definitions and message content blocks
  • Add a targeted BLOCKED_TOOL_NAMES map that renames only the three rejected names:
    • todowriteTodoWrite
    • background_outputbackgroundOutput
    • background_cancelbackgroundCancel
  • Update stripToolPrefix to reverse these renames in API responses

src/index.ts

  • Add explicit baseURL: "https://api.anthropic.com/v1" to the auth loader return object

src/transforms.test.ts

  • Update existing test to reflect removal of mcp_ prefixing
  • Add test coverage for stripToolPrefix reversing all three blocked name renames
  • Add test verifying transformBody correctly renames blocked names while leaving other tool names unchanged

Testing

  • Verified with Claude Max subscription across multiple projects and working directories
  • Confirmed all tools (Read, Grep, Write, Edit, Glob, Bash, etc.) function correctly
  • Requests with 20+ tools no longer trigger the billing validation error
  • All 211 transform, signing, beta, and credential tests pass (3 pre-existing keychain test failures on Windows are unrelated to this change)

Anthropic's OAuth billing validation rejects tool names with the `mcp_`
prefix when 3+ tools are present, returning a spurious "out of extra
usage" 400 error. The bare tool name `todowrite` is also independently
blocked.

This commit:
- Removes the blanket `mcp_` prefix applied to all tool names
- Renames only the blocked `todowrite` → `TodoWrite` in both request
  tools and message content blocks
- Updates `stripToolPrefix` to reverse the `TodoWrite` rename in
  responses
- Adds explicit `baseURL` to the auth loader return so AI SDK constructs
  the correct API endpoint URL

Fixes #187
Copy link
Copy Markdown

@p4r4d0xb0x p4r4d0xb0x left a comment

Choose a reason for hiding this comment

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

an unstoppable force vs an immovable object

SeaL773 added a commit to SeaL773/opencode-claude-auth that referenced this pull request Apr 14, 2026
Anthropic's OAuth billing validation rejects certain tool names
(todowrite, background_output, background_cancel) when multiple tools
are present, returning spurious 400 "out of extra usage" errors.

Replace the blanket mcp_ prefix strategy with a targeted rename map
for known blocked names. Also add explicit baseURL to ensure correct
API endpoint construction.

Fixes griffinmartin#190
Related: griffinmartin#189

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Anthropic's billing validator also rejects `background_output` and
`background_cancel` tool names (see #190). Add them to the blocked
names map and include reverse mappings in stripToolPrefix.

Update tests to cover blocked tool name renaming and remove stale
mcp_ prefix assertions.

Fixes #190
@Profpatsch
Copy link
Copy Markdown

works!

feisuzhu pushed a commit to feisuzhu/opencode-claude-auth that referenced this pull request Apr 15, 2026
Anthropic's OAuth billing validation rejects certain tool names
(todowrite, background_output, background_cancel) when multiple tools
are present, returning spurious 400 "out of extra usage" errors.

Replace the blanket mcp_ prefix strategy with a targeted rename map
for known blocked names. Also add explicit baseURL to ensure correct
API endpoint construction.

Fixes griffinmartin#190
Related: griffinmartin#189

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Kuenec Kuenec closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants