fix: stop mcp_ tool prefixing to avoid billing validation rejection#189
Closed
Kuenec wants to merge 3 commits intogriffinmartin:mainfrom
Closed
fix: stop mcp_ tool prefixing to avoid billing validation rejection#189Kuenec wants to merge 3 commits intogriffinmartin:mainfrom
Kuenec wants to merge 3 commits intogriffinmartin:mainfrom
Conversation
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
p4r4d0xb0x
approved these changes
Apr 14, 2026
p4r4d0xb0x
left a comment
There was a problem hiding this comment.
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>
4 tasks
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 namestodowrite,background_output, andbackground_cancelare independently rejected by the validator.Root Cause
The plugin was applying a blanket
mcp_prefix to every tool name (e.g.,Read→mcp_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 (/messagesinstead 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:mcp_prefix is what triggers the billing validation rejection. Keeping it in any form leaves the fix dependent on Anthropic not tightening validation further.todowrite,background_output,background_cancel) need renaming. All other tool names pass through untouched.stripToolPrefixonly needs to restore the three renamed tools, rather than transforming every tool name on every response.Changes
src/transforms.tsmcp_prefixing of all tool names in both tool definitions and message content blocksBLOCKED_TOOL_NAMESmap that renames only the three rejected names:todowrite→TodoWritebackground_output→backgroundOutputbackground_cancel→backgroundCancelstripToolPrefixto reverse these renames in API responsessrc/index.tsbaseURL: "https://api.anthropic.com/v1"to the auth loader return objectsrc/transforms.test.tsmcp_prefixingstripToolPrefixreversing all three blocked name renamestransformBodycorrectly renames blocked names while leaving other tool names unchangedTesting