Skip to content

Connect an MCP client or agent to your API

Your API is also a Model Context Protocol (MCP) server, and people connect Claude Code, claude.ai, or another MCP client to it. Each person signs in at your Authwise issuer once, and the client calls your server with a token that is theirs, refreshed on its own. Nobody copies a token out of a browser. This page shows what your server publishes, which client you register for the agent, how each Claude surface connects, and what your server checks on every call.

  • An issuer with a realm and sign-in method, and the API your MCP server belongs to registered as an audience on that issuer. See Domains and issuers and Sign users in with OpenID Connect.
  • A tenant administrator seat, or a service account holding tenant.admin, to register the client.
  • awctl 0.33 or later, or Terraform provider 0.19 or later, if you register the client from the command line.

MCP authorization is OAuth 2.1. The client learns everything from your server and the issuer; the person only sees the sign-in page.

  1. The client calls your MCP server with no token. The server answers 401 with a WWW-Authenticate header that names its protected resource metadata.
  2. The client reads that document: the server’s resource identifier and the issuer that protects it.
  3. The client reads the issuer’s authorization server metadata at ISSUER_URL/.well-known/oauth-authorization-server, which Authwise serves beside its OpenID discovery document.
  4. The client identifies itself with the client ID you registered for it and runs the authorization code flow with PKCE in the person’s browser, naming your server as the resource.
  5. The client stores the tokens and refreshes them on its own.

Your server does steps 1 and 2. The issuer does 3 to 5, once a client for the agent exists.

Serve the RFC 9728 document at /.well-known/oauth-protected-resource on your server’s origin. When the server’s URL has a path, also serve it with that path appended, which is where a client looks first. For a server at https://mcp.example.com/mcp:

https://mcp.example.com/.well-known/oauth-protected-resource/mcp
https://mcp.example.com/.well-known/oauth-protected-resource
{
"resource": "https://mcp.example.com/mcp",
"authorization_servers": ["https://login.example.com"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["openid", "profile", "email", "offline_access"]
}
  • resource is your server’s URL exactly as people enter it in the client, path included.
  • authorization_servers holds your issuer URL. Claude uses the first entry only.
  • scopes_supported is what a client asks for when the challenge names no scope. Include offline_access, or the client gets no refresh token and the person signs in again when the access token expires.

The Authwise Admin API publishes its own this way:

Terminal window
curl -s https://api.authwise.com/.well-known/oauth-protected-resource
{"resource":"https://api.authwise.com","authorization_servers":["https://admin.authwise.com"],"bearer_methods_supported":["header"],"resource_name":"Authwise admin API"}

Answer a request with no token, or with one you refuse, with 401 and a WWW-Authenticate header that points at the metadata. The status must be 401: a client ignores the header on any other status.

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource/mcp", scope="openid offline_access"
  • scope names the scopes the client should request. Claude uses it over scopes_supported when both are present.
  • Add error="invalid_token" when a token was presented and refused.
  • When a valid token lacks a scope a tool needs, answer 403 with error="insufficient_scope" and the scopes required.

On an install that signs people in, never fall back to a stand-in identity for a call without a token. The 401 is what starts the sign-in.

Authwise does not register clients dynamically and does not read a client ID metadata document, so the agent uses a client you register. One client serves every Claude surface. Register it on the issuer, in the audience your MCP server belongs to:

  • Public, with no secret. A desktop or command-line client cannot keep one. PKCE with S256 is then required, and the client’s redirect URIs are matched exactly.
  • Grant types authorization_code and refresh_token.
  • Redirect URIs: http://localhost/callback and http://127.0.0.1/callback for Claude Code, which answers on an ephemeral port, and https://claude.ai/api/mcp/auth_callback for claude.ai, Claude Desktop, and the mobile apps. A loopback entry matches on any port, so you never register a port.

With awctl:

Terminal window
awctl identity clients create --tenant-id TENANT_ID --issuer-id ISSUER_ID \
--display-name "Claude" --audience-id AUDIENCE_ID --kind CLIENT_KIND_APPLICATION \
--grant-types authorization_code,refresh_token \
--token-endpoint-auth-method none \
--config '{"@type":"type.googleapis.com/authwise.types.core.v1alpha1.InteractiveClientConfig","allowed_redirect_uris":["http://localhost/callback","http://127.0.0.1/callback","https://claude.ai/api/mcp/auth_callback"]}'
Created tenants/t-01/issuers/i-01/clients/c-g389ckq8iivd

With Terraform:

data "authwise_interactive_client_config" "claude" {
allowed_redirect_uris = [
"http://localhost/callback",
"http://127.0.0.1/callback",
"https://claude.ai/api/mcp/auth_callback",
]
}
resource "authwise_client" "claude" {
display_name = "Claude"
audience_id = authwise_audience.mcp.audience_id
grant_types = ["authorization_code", "refresh_token"]
token_endpoint_auth_method = "none"
config = data.authwise_interactive_client_config.claude.any
}

AUDIENCE_ID is the audience whose identifier is your MCP server’s URL, or its origin. Give the client ID to the people who connect; it is not a secret.

Add the server with the client ID. Claude Code discovers the issuer from your server’s challenge, and signs in through the browser:

Terminal window
claude mcp add --transport http --client-id CLIENT_ID NAME https://mcp.example.com/mcp
claude mcp login NAME

Replace CLIENT_ID with the client you registered and NAME with the name the server has in Claude Code. With no --client-id, Claude Code tries to register itself and stops with “Incompatible auth server: does not support dynamic client registration”. Pass --callback-port PORT only if a firewall on the machine needs a fixed port; the loopback entries you registered match any port.

Add the server as a custom connector with its URL. Under Authentication, keep sign-in on, and under OAuth client select Use your own OAuth client and enter the client ID. Leave the client secret empty: the client is public. The other two options, Claude’s published identity and automatic registration, need a client ID metadata document or dynamic registration at the issuer, which Authwise does not offer, and fail with an authorization error. The Anthropic page Authentication for connectors describes the dialog and what Claude’s client expects.

What the token carries and what your server checks

Section titled “What the token carries and what your server checks”

The client asks for your server as the resource, and the issuer mints an access token for it. Its aud is the audience’s identifier. An identifier that is an origin, such as https://mcp.example.com, covers every path on that origin, so a client of https://mcp.example.com/mcp is admitted and the token says https://mcp.example.com. An identifier with a path is matched exactly. A client that names a resource outside its audience is refused with invalid_target.

On every call your server verifies the token’s signature against the issuer’s JWKS (jwks_uri in the discovery document) and checks:

  • iss is your issuer;
  • aud is your audience’s identifier, and no other audience’s, even from the same issuer;
  • exp is ahead.

sub is the person’s ID and client_id is the client you registered. The access token carries no profile or email claims; to show who is calling, resolve sub at the userinfo endpoint as Sign users in with OpenID Connect describes. Never forward the token to another service: MCP forbids token passthrough, and a downstream service needs a token for its own audience.

With offline_access granted, the client holds a refresh token and renews the access token without the person. Refresh tokens rotate on every use; a refresh token already used is refused with invalid_grant, which is the answer Claude expects. The lifetimes are the issuer’s, audience’s, or client’s: by default an access token lives 900 seconds, and a refresh token 12 hours unused and 30 days in all.

For curl, a script, or a client that takes a fixed header, awctl signs in once through the browser as the client you registered and prints a fresh access token on demand:

Terminal window
awctl auth login --issuer https://login.example.com --client-id CLIENT_ID
awctl auth print-access-token --issuer https://login.example.com

The login asks for offline_access, and print-access-token renews the token through the refresh token before printing it. The client needs http://localhost/return among its redirect URIs for awctl, beside the Claude ones. A header built with $(awctl auth print-access-token …) expands once, when the shell runs it, so it suits a request you run now, not a stored configuration: for an MCP client, register the client and let it sign in itself as above.

SymptomCause
Claude Code: Incompatible auth server: does not support dynamic client registrationNo --client-id. Add the server again with the client ID.
claude.ai: authorization failed before the sign-in pageThe connector’s OAuth client is Claude’s published identity or automatic registration. Select Use your own OAuth client.
The sign-in page answers invalid_targetThe resource the client sent is not covered by the client’s audience. Set the audience’s identifier to the server’s origin or exact URL.
Your server refuses every token with a wrong audThe audience’s identifier is not what your server compares against, or the client belongs to another audience.
The person signs in again every 15 minutesNo refresh token: offline_access was not requested. Name it in the challenge’s scope or in scopes_supported.
The sign-in page refuses the redirectThe redirect URI is not registered exactly, or the client has a secret and the loopback rule does not apply. Register the three URIs above on a public client.