Skip to content

Troubleshooting OAuth for MCP servers

OAuth proxy errors use the gateway’s error envelope, {"error": {"message": "..."}}. The exceptions are /register ({"error": "..."}) and oauth_reauth_required (below). Every 401 carries a WWW-Authenticate: Bearer ... challenge.

Start with MCP Server Access → OAuth Tokens in the Admin UI: the status of the user’s row usually tells you which case you are in. Proxy logs of type oauth show each exchange and refresh with its error.

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="brutor-mcp", error="invalid_token", error_description="OAuth token expired or revoked"
Content-Type: application/json
{
"error": "oauth_reauth_required",
"error_description": "OAuth token expired or revoked — please re-authenticate with the Identity Provider",
"mcp_server_id": "mcp-system-hubspot-default",
"mcp_server_name": "HubSpot",
"idp_id": "idp-system-hubspot-default"
}

The MCP JWT is valid but its stored token is unusable: expired with no refresh token, refresh rejected by the IdP, revoked (by the user, an admin, or because the IdP’s issuer changed), or never stored. Fix: run the authorization again (agent, or Re-authorize in the portal). If it recurs right after every authorization, check that the IdP issues refresh tokens and that Supports Refresh Tokens is set.

Response Cause Fix
401 Invalid JWT: Bearer token is not a recognised credential (not an API key, not a valid gateway JWT) MCP JWT sent alone, with no API key Add X-API-Key: sk_brutor_api_...
401 Authentication token has expired The portal session JWT or other gateway JWT expired Sign in again
403 Access denied: you do not have access to this MCP server No resource group of the caller grants this MCP server Bind the server to the caller’s resource group
Upstream 401 / 403 passed through No MCP JWT was sent (API key only), so no user token was injected Send the MCP JWT in Authorization
502 Stored OAuth credential for this server is malformed; re-authorize it The decrypted stored token is not a valid header value Revoke the row and authorize again; check ENCRYPTION_KEY matches on both planes
Tools missing for an OAuth server Capabilities are discovered only once a user has authorized Authorize once; discovery runs on the first exchange
Response Cause Fix
400 Missing required parameters: code, client_id Form body missing a field, or sent as JSON Send application/x-www-form-urlencoded
400 Unsupported grant_type: … Supported: authorization_code, refresh_token Any other grant, for example client_credentials Use one of the two
404 OAuth client configuration not found: <reason> No secret could be found for a non-PKCE exchange; reasons below Fix the record named in the reason
400 oauth_subject_unavailable: … The IdP returned no user subject (no userinfo endpoint, or it failed) and the exchange was not authenticated Configure the IdP’s UserInfo Endpoint, or send an API key on /token
502 Token exchange failed: IdP returned 400 Bad Request: {...} The IdP refused the code: expired or used code, redirect_uri different from the authorize step, wrong secret, missing or wrong PKCE verifier Read the IdP’s message in the error; restart from authorize
401 User info retrieval failed: … The userinfo call failed in a way the exchange could not recover from Check the userinfo URL and the granted scopes
409 Duplicate token exchange in progress Two exchanges of the same code at once Wait for the first; retries after it completes get its result
500 Confidential client has no stored secret confidential OAuth App Client saved without a secret Edit the client and enter the Client Secret
400 Token mcp_server_id '…' does not match URL path '…' Refresh grant with an MCP JWT for another server Use that server’s token endpoint
401 Invalid refresh token: … refresh_token is not an MCP JWT signed by this gateway Send the MCP JWT, not the provider’s refresh token
502 Token refresh failed: OAuth token expired and no refresh token available — user must re-authenticate Nothing left to refresh with Authorize again

The <reason> in OAuth client configuration not found names the broken link:

Reason Meaning
no server_config found for mcp_server_id='…' in tenant '…' The MCP server has no access configuration
server_config references oauth_client_id='…' but no such oauth_app_clients record exists The linked OAuth App Client was deleted
oauth client is_active=false (must be activated by admin) The client is inactive
idp_id mismatch: stored='…', requested='…' The client belongs to another IdP than the one in the URL
client_id mismatch: stored='…', requested='…' The client sent a different client_id than the stored one
Response Cause Fix
404 MCP server not found or disabled Wrong ID, or the server is disabled Enable it, check the ID
404 Identity Provider not found or disabled Wrong ID, or the IdP is disabled (an imported IdP with missing endpoints stays disabled) Complete and enable the IdP
403 … refused by the outbound policy The server’s base_url or an IdP endpoint resolves to a refused destination Use a public endpoint, or adjust the outbound policy
400 IdP has no authorization endpoint /authorize on an IdP without one Fill Authorization Endpoint
400 Missing tenant context Tenant could not be resolved from the MCP server Check the MCP server ID
503 configuration store temporarily unavailable; retry The database lookup failed Retry
The IdP shows redirect_uri mismatch The redirect URI is not registered at the provider Register it exactly, including the portal’s /callback
Discovery URLs point at the wrong host PROXY_PUBLIC_URL unset or contains localhost, so the URL is built from Host / X-Forwarded-* Set PROXY_PUBLIC_URL to the public gateway URL, or forward the headers from your proxy

CIMD and dynamic-registration errors are listed on MCP authorization spec support.