[BUG] Unable to connect custom mcp server using Anthropic API
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Currently I've developed my own custom MCP server that fully conforms OAuth 2.1 specifications. I was planning to to make prompts connect to my server as mentioned on this page.
I tested all the features and oauth process through mcp inspector. everything worked fine.
And also when adding to claude code using claude mcp add command, it also worked fine. The term working fine means that server access and tool calling worked as expected.
But when calling through anthropic api, the response always give me this error.
{"type":"error","error":{"type":"invalid_request_error","message":"Invalid authorization token for MCP server '<MY_SERVER_NAME>'. Please check your token and try again."},"request_id":"<MY_REQ_ID>"}
The exact token that I've used allows access when using claude-code or mcp-inspector. It only fails with anthropic API. My server doesn't even received any requests so it seams that anthropic is denying for some reason.
curl request:
curl https://api.anthropic.com/v1/messages \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-API-Key: <MY_ANTHROPIC_API_KEY>" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: mcp-client-2025-04-04" \
-d '{
"model": "claude-opus-4-1-20250805",
"max_tokens": 1000,
"messages": [{"role": "user", "content": "What tools do you have available?"}],
"mcp_servers": [
{
"type": "url",
"url": "<MY_SERVER_URL>",
"name": "<MY_SERVER_NAME>",
"authorization_token": "<MY_AUTH_TOKEN>"
}
]
}'
Perhaps, is there some kind of pre-registration process that should be done in order to let anthropic api to access? Or is there a token format standard that anthropic requires?
What Should Happen?
I should get a response that I had requested (What tools do you have available?)
Error Messages/Logs
{"type":"error","error":{"type":"invalid_request_error","message":"Invalid authorization token for MCP server '<MY_SERVER_NAME>'. Please check your token and try again."},"request_id":"<MY_REQ_ID>"}
Steps to Reproduce
Using the curl request mentioned above
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
1.0.110
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
These are the OAuth endpoints that my custom mcp server provides:
/// OAuth 2.0 endpoint paths (RFC-compliant constants)
pub mod oauth_endpoints {
/// OAuth 2.0 authorization server metadata endpoint (RFC 8414)
pub const AUTHORIZATION_SERVER_METADATA: &str = "/.well-known/oauth-authorization-server";
/// OAuth 2.0 protected resource metadata endpoint (RFC 8414)
pub const PROTECTED_RESOURCE_METADATA: &str = "/.well-known/oauth-protected-resource";
/// OAuth 2.0 dynamic client registration endpoint (RFC 7591)
pub const REGISTER: &str = "/oauth/register";
/// OAuth 2.0 authorization endpoint
pub const AUTHORIZE: &str = "/oauth/authorize";
/// OAuth 2.0 token exchange endpoint
pub const TOKEN: &str = "/oauth/token";
/// OAuth 2.0 callback endpoint
pub const CALLBACK: &str = "/oauth/callback";
/// OAuth 2.0 token introspection endpoint (RFC 7662)
pub const INTROSPECT: &str = "/oauth/introspect";
}This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗