Authentication · troubleshooting record
Bearer token rejected by a remote MCP server
The client is sending something in the Authorization header, but the server does not accept it. The failure can come from a placeholder that was never replaced, a wrong token type, a hidden whitespace character, or a token from the wrong environment.
Symptoms
- Server returns 401 or an invalid_token error.
- A token works in a REST client but not through MCP.
- The configuration contains a literal ${TOKEN} or a value copied from documentation.
Confirmed causes
These causes have a documented basis. They may not be the cause of your specific failure.
The placeholder was sent literally
A value such as ${TOKEN} is only substituted when the client documents that expansion; otherwise it is sent as text.
The token type is wrong for the endpoint
Some providers use bearer tokens, while others expect a custom API-key header or a signed request.
Hidden whitespace or a newline was included in the token value
HTTP header values cannot contain line breaks, and leading or trailing spaces can make a valid token invalid.
Possible causes
- The token belongs to a test environment while the URL points to production.
- The token expired or was rotated.
- The provider requires an organization or project header in addition to the token.
- A proxy rewrites the Authorization header.
What still needs verification
- Whether the client expands the exact placeholder syntax used in the file.
- The token prefix and length expected by the provider.
- The request headers as seen by the server or a debugging proxy.
Affected environments
Fixes
Verify the exact header value
- Use the Config Doctor to check for empty headers, control characters, and unresolved placeholders.
- Confirm the client's documented expansion syntax and restart from a shell that exports it.
- Never paste a real token into a shared config file.
Exchange the credential outside the client
- Test the token against the provider's documented endpoint with curl.
- Check the provider's token prefix and environment.
- Rotate the token if there is any chance it was exposed.
Verify the fix
- The request carries the intended header value without a literal placeholder.
- The provider accepts the token and returns a normal protocol response.
- The client lists the remote server's tools.
Paste the configuration into the Config Doctor. It runs in your browser, never uploads the file, and can show structural issues and safe fixes.
Why we believe this
- developers.openai.com/codex/mcpOfficial documentation · checked Oct 23, 2026 · documented
Codex documents bearer_token_env_var for remote MCP authentication.
- cursor.com/docs/mcpOfficial documentation · checked Oct 23, 2026 · documented
Cursor documents ${env:VAR} interpolation and remote headers.