MCP servers
Protect an MCP server so MCP clients such as Claude Code find your realm, sign the person in and call your tools with a token issued for your server alone.
In the Model Context Protocol authorization model, your MCP server is an OAuth resource server and Authio is its authorization server. The server never signs anyone in: an MCP client — Claude Code, an IDE, the MCP Inspector — discovers Authio from the server, signs the person in through the hosted login and calls your tools with an access token whose audience is your server.
Two packages implement the server’s half: @hyper.authio/mcp 0.8.0 for Node.js, on top of the official MCP SDK and the Authio Node.js SDK 0.13, and Authio.Mcp.AspNetCore 0.8.0 for ASP.NET Core, on top of the official C# MCP SDK and Authio.AspNetCore 0.12. Both verify tokens, publish the metadata MCP clients look for, answer with the challenges that start the OAuth flow and authorize each tool.
Configure them the way the server is registered
Looking for Authio’s own MCP server?
How an MCP client finds Authio
- The client calls the server without a token. The server answers
401with aWWW-Authenticate: Bearerheader whoseresource_metadatapoints at its protected resource metadata. - The client reads that document (RFC 9728), served under
/.well-known/oauth-protected-resourcefollowed by the endpoint’s path. It names the realm as the authorization server. - It reads the realm’s authorization server metadata (RFC 8414) at the path-inserted address MCP clients try first,
https://authio.api.hyperio.tech/.well-known/oauth-authorization-server/realms/acme; the realm’s OpenID Connect discovery address answers too. - It identifies itself with a client ID you registered for it, or with the URL of its own Client ID Metadata Document if the realm accepts those. A realm can also turn on dynamic client registration, off by default, for MCP clients that can do neither.
- It runs the authorization code flow with PKCE and
resource=https://mcp.example.com/mcp(RFC 8707). The access token carries that identifier asaud, so it is useless on any other server. - Your server checks the signature against the realm’s keys, the issuer, the audience, the expiry and the scopes it requires. With introspection set to
activeCheck, it also asks Authio whether the token is still active — at most once every 30 seconds per token.
{
"resource": "https://mcp.example.com/mcp",
"authorization_servers": ["https://authio.api.hyperio.tech/realms/acme"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["mcp:tools"],
"resource_name": "Acme tools"
}scopes_supported lists the required scopes and any others you advertise, and is left out when there are none.
Set up the realm
Register the server as a resource server
In Resource servers, set the Identifier to the public URL of the MCP endpoint, such as
https://mcp.example.com/mcp, and add a scope such asmcp:tools. The identifier becomes every token’saudand cannot change later; it is stored with the scheme and host lower-cased and without a default port or trailing slash.Create the server’s own client
In Clients, create a confidential client for the server and choose it as the resource server’s Introspection client. Its ID, its Token endpoint auth method and its secret (or, for
private_key_jwt, its private key) go in the server’s configuration. Give it the token exchange grant if tools will use connected accounts. A server that validates locally and exchanges nothing does not need it.Let MCP clients in
Register a client for each MCP client you use and add it under Allowed clients, turn on Accept CIMD clients so MCP clients that publish a metadata document can ask for tokens, or — for MCP clients that can do neither — turn on dynamic client registration in the realm and Accept dynamically registered clients here. All three are described below.
Pre-registered clients
- A public client with the
authorization_codegrant, PKCE required andS256allowed. - The redirect URI of each MCP client: Claude Code uses
http://localhost:<callback-port>/callback, the MCP Inspectorhttp://localhost:6274/oauth/callback. Turn on Loopback on any port for native clients that pick their port. - Require OpenID Connect off, because MCP clients usually ask only for your scope — or have them ask for
openidtoo. - The client listed under Allowed clients on the resource server; otherwise the authorize request fails with
invalid_target.
Then give Claude Code the client ID and the callback port you registered:
claude mcp add --transport http --client-id acme-claude-code --callback-port 8765 acme-tools https://mcp.example.com/mcpClient ID Metadata Documents
A Client ID Metadata Document (CIMD) lets an MCP client identify itself with an https URL that serves a JSON description of it — its name and redirect URIs — instead of a client ID you created. The URL is the identity: a document that names a different client_id is refused.
- Turn it on per realm: in the realm’s MCP clients (CIMD) settings, switch on Accept clients by metadata document (CIMD). It is off by default.
- Optionally limit Allowed hosts. Empty accepts any public
httpshost;*.example.comcovers the subdomains ofexample.combut notexample.comitself. - Turn on Accept CIMD clients on each resource server those clients may reach.
- The client is registered on first use, is always public, always shows the consent screen and stays in sync with its document. Turning the setting off, or removing its host, shuts it out on the next request.
- The realm’s discovery document advertises
client_id_metadata_document_supported: truewhile the setting is on.
Dynamic client registration
Dynamic client registration (RFC 7591) lets an MCP client create its own client by posting its metadata to the realm’s registration endpoint, POST https://authio.api.hyperio.tech/realms/acme/protocol/openid-connect/register. It is off by default and turned on per realm.
Prefer CIMD or a pre-registered client
InitialAccessToken rather than Open.- Turn it on per realm: on the realm’s page, in the Access section, switch on Dynamic client registration (DCR). Through the Admin API, it is the
dynamicClientRegistrationobject ofPUT /api/v1/admin/realms/{realm}:admin.realm.updatein@hyper.authio/admin, and on .NET anHttpClientwith the account credential, as Routes without a method in .NET shows. - While it is off — or the realm does not exist or is inactive — the endpoint answers
404and the realm’s metadata (/.well-known/oauth-authorization-server/realms/acmeand the OpenID configuration) carries noregistration_endpoint. While it is on,registration_endpointis published. - Turn on Accept dynamically registered clients (
allowDynamicallyRegisteredClients) on each resource server those clients may reach, as Accept CIMD clients does for CIMD. Without it, a token request withresource=fails withinvalid_target.
| Setting | API member | Default | Meaning |
|---|---|---|---|
| Enabled | enabled | false | Opens the endpoint and publishes registration_endpoint. |
| Access | access | InitialAccessToken | InitialAccessToken requires a credential of the account that owns the realm on every registration; Open lets anyone register. |
| Allowed scopes | allowedScopes | openid profile email offline_access | A request that names no scope gets all of them; a scope outside the list is refused. |
| Allowed grant types | allowedGrantTypes | authorization_code refresh_token | May also allow client_credentials and device_code. A request that names none gets authorization_code. |
| Allowed auth methods | allowedAuthMethods | none | May also allow client_secret_basic and client_secret_post. A request that omits it gets client_secret_basic if allowed, otherwise the first allowed method. |
| Redirect hosts | redirectHosts | Empty: any https host | *.example.com covers the subdomains of example.com but not example.com itself. |
| Allow loopback redirects | allowLoopbackRedirects | true | http or https on 127.0.0.1, [::1] or localhost, on any port. |
With InitialAccessToken, the request carries Authorization: Bearer with an API key or personal access token of the account that owns the realm, holding realm:write — the permission the Admin API needs to create clients. A credential restricted to another realm or to a single client does not work. The body takes the RFC 7591 members redirect_uris, token_endpoint_auth_method, grant_types, response_types, client_name, client_uri, scope and contacts; any other member is ignored.
curl -X POST https://authio.api.hyperio.tech/realms/acme/protocol/openid-connect/register \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer pat_...' \
-d '{"client_name":"My MCP client","redirect_uris":["http://127.0.0.1:33418/callback"],"grant_types":["authorization_code","refresh_token"],"response_types":["code"],"token_endpoint_auth_method":"none","scope":"openid offline_access"}'A confidential client also gets client_secret and client_secret_expires_at: 0. There is no registration_access_token or registration_client_uri: client management (RFC 7592) is not supported, and the client is managed in the console like any other.
| Error | Status | When |
|---|---|---|
invalid_client_metadata | 400 | A scope, grant type or auth method the policy does not allow, or metadata that does not hold together. |
invalid_redirect_uri | 400 | http on a host other than loopback, a host not listed, a loopback address while loopback is off, a fragment or user info. |
invalid_token | 401 | The initial access token is missing or lacks realm:write on the realm. |
| None | 404 | Registration is off, or the realm does not exist or is inactive. |
The registered client is created like any other: it counts toward the plan’s client quota, is recorded in the audit trail and fires the admin_resource_created webhook. The console marks it Dynamically registered. A public one always requires PKCE with S256, the consent screen is always shown and Require OpenID Connect is off.
Pre-registered vs CIMD vs DCR
| Pre-registered | CIMD | DCR | |
|---|---|---|---|
| Who creates the client | You, in the console | Authio, from the client’s document on first use | The MCP client, by calling the registration endpoint |
| Client ID | Chosen when you create it | The document’s https URL | Issued by Authio |
| In the realm | Nothing to turn on | Accept clients by metadata document (CIMD) | Dynamic client registration (DCR) |
| On the resource server | Allowed clients | Accept CIMD clients | Accept dynamically registered clients |
| When to use it | MCP clients you know and configure, such as Claude Code | MCP clients that publish a metadata document — the recommended default | Only MCP clients that can do neither |
Node.js: @hyper.authio/mcp
@hyper.authio/mcp needs Node.js 20.19 or later and is ESM only. express is needed only for the @hyper.authio/mcp/express helpers.
npm install @hyper.authio/mcp @modelcontextprotocol/sdk expresscreateAuthio reads the realm’s discovery document at start-up, so a wrong authority, realm or issuer stops the server with a sentence instead of every token being refused later. authioMetadataRouter publishes the protected resource metadata and answers CORS for browser clients such as the MCP Inspector; mount it at the root. authio.protect(server).registerTool takes what McpServer.registerTool takes plus requires — requireScope, requireRole, requirePermission, requireCallerKind, requireOrganization, requireAuthenticationLevel, allOf, anyOf — and hands each tool the caller as extra.user: its kind, subject, client, scopes, roles, permissions, organization, acr/amr and delegation.
Not on Express? authio.authenticate(authorizationHeader) answers the caller or the refusal to send, authio.authorizeRequest(user, body) checks a tools/call, authio.metadata is the protected resource metadata, and authio.tokenVerifier is an OAuthTokenVerifier for the MCP SDK’s own requireBearerAuth.
ASP.NET Core: Authio.Mcp.AspNetCore
The package targets .NET 8 and .NET 10 and brings Authio.AspNetCore, Authio.Client and the official C# MCP SDK (ModelContextProtocol.AspNetCore) with it. It reads every setting from the Authio:Mcp section.
dotnet add package Authio.Mcp.AspNetCoreKeep the secret in user-secrets or the Authio__Mcp__ClientSecret environment variable. AddAuthioMcp(options => options.RequiredScopes = ["mcp:tools"]) sets the scopes in code. RequireAuthioMcp() requires the AuthioMcpDefaults.Policy policy on the endpoint and authorizes each tools/call against the tool’s [AuthioScope], [AuthioRole], [AuthioPermission], [AuthioCallerKind], [AuthioOrganization] or step-up attributes before it runs; AddAuthorizationFilters() hides from tools/list what the caller may not call. ClientId is optional when the server neither introspects nor exchanges tokens.
Options
| Node option | .NET setting | Left out | Meaning |
|---|---|---|---|
authority + realm, or issuer | Authority + Realm, or Issuer | Required | Where the realm is. The authority must be the base Authio publishes in its issuer, without /realms/…. |
resource | Resource | Required | The public URL of the MCP endpoint: the resource identifier, every token’s aud and resource in the metadata. |
clientId | ClientId | None | The resource server’s introspection client, also used for connected-account exchanges. Required with introspection. |
tokenEndpointAuthMethod | TokenEndpointAuthMethod | Follows the credentials | The client’s Token endpoint auth method, which Authio matches exactly: client_secret_basic, client_secret_post, private_key_jwt or none (Basic, Post, PrivateKeyJwt, None in .NET). Left out: basic with a secret, private_key_jwt with only a private key, none with neither. |
clientSecret | ClientSecret | None | The client’s secret, for the basic and post methods and for HS access tokens. |
requiredScopes | RequiredScopes | No scope required | Scopes every token must carry, all of them. Name the ones the server insists on, such as mcp:tools; they also go into the 401 challenge and scopes_supported. |
introspection | Introspection | none: local validation only | activeCheck also asks Authio about each token (cached per token), so a revoked token or an ended session is refused before it expires; introspectionOnly validates by introspection alone, for opaque (Reference) tokens or HS tokens the server cannot verify. Both need clientId. |
introspectionCacheDuration | IntrospectionCacheDuration | 30 seconds | How long an active answer is reused, never past the token’s expiry. |
accessTokenSignedResponseAlg | AccessTokenSignedResponseAlg | RS, PS and ES only, never HS | The algorithm, or several, the client signs access tokens with. HS256, HS384 and HS512 are verified with clientSecret. |
clientEncryptionKey | ClientEncryptionKey | Nothing decrypted | The private key Authio encrypts this server’s access tokens to; see Encrypted tokens. |
scopesSupported, resourceName | ResourceScopes, ResourceName | None | The rest of the protected resource metadata. |
Left out means off
requiredScopes, any token issued for the server is accepted, whatever its scopes, and the 401 challenge carries no scope. Without introspection, a token is validated locally only: a revoked token or an ended session keeps working until the token expires. A server that relies on either one states it, as requiredScopes: ['mcp:tools'] and introspection: 'activeCheck' ("RequiredScopes": [ "mcp:tools" ] and "Introspection": "ActiveCheck" in .NET).MCP clients whose access token is signed with HS
accessTokenSignedResponseAlg set to the HS algorithm and its clientSecret, validates it locally. An MCP server does not hold the secret of the MCP clients that call it, so for those tokens use introspection: 'introspectionOnly' ("Introspection": "IntrospectionOnly"), or sign those clients’ access tokens with RS, PS or ES. The client’s view in the console warns when its access tokens need introspection; see Token signing.Access token formats
The format of the tokens the server receives is decided by the client the MCP clients sign in through, and introspection follows it.
| Format | What the token carries | introspection / Introspection |
|---|---|---|
| JWT (self-contained) | Everything | Any; none validates it locally |
| Lightweight | Only who called and how: sub, client_id, scope, sid, acr/amr, act and the organization. Roles, permissions, subscription, the profile, the email and a consumer’s credential_type are left to introspection | activeCheck or introspectionOnly (ActiveCheck or IntrospectionOnly), from 0.6.0 |
| Opaque (reference) | Nothing readable | introspectionOnly (IntrospectionOnly) |
From 0.6.0, with activeCheck, the caller is the token’s payload plus the claims of the introspection answer the token does not carry, so a lightweight token reaches requireRole, requirePermission, requireCallerKind, [AuthioRole] and [AuthioPermission] complete; a claim the token carries keeps its signed value. With none, a lightweight token is still valid but arrives without roles or permissions, and every tool that requires one refuses it: the packages never guess the format from the claims a token lacks. See every library in Integrate with the libraries.
What the MCP specification fixes
Three things are not options, because the MCP authorization specification requires them rather than any client or resource server setting in Authio:
| Fixed | Why |
|---|---|
authorization_servers is the realm’s issuer | The metadata must name the authorization server an MCP client has to use. For an Authio-protected server that is the realm that issues its tokens; any other value would send the client to a server whose tokens are refused. |
bearer_methods_supported is ["header"] | MCP clients send the token in the Authorization: Bearer header and never in the query string, and the packages read only the header. |
Every 401 carries resource_metadata | The server points the client at its protected resource metadata through WWW-Authenticate; that is how the client discovers Authio. The metadata is therefore always published. |
What the server answers
| Situation | Status | WWW-Authenticate carries |
|---|---|---|
| No token | 401 | resource_metadata, plus scope in Node when requiredScopes names any |
| Invalid, expired or issued for another resource; revoked, with introspection on | 401 | error="invalid_token", a description and resource_metadata |
| Token without the required scopes, or without a tool’s scope | 403 | error="insufficient_scope", the scopes needed and resource_metadata |
| A tool that needs a stronger or more recent sign-in | 403 in Node, 401 in .NET | error="insufficient_user_authentication", acr_values and max_age |
| A tool’s role, permission, caller kind or organization rule not met | 403 | Nothing |
Browser-based clients such as the MCP Inspector must read that header across origins. Both packages expose WWW-Authenticate through CORS — the Express router by default, ASP.NET Core with AddAuthioMcpPolicy and RequireCors.
Use the person’s connected accounts
A tool can trade the caller’s Authio token for the token of an account they connected in Authio — GitHub, Google Drive and others — without storing any third-party credential. Call authio.exchangeConnection({ subjectToken: extra.user.token, provider }) in Node, which answers a status, or IAuthioTokenClient.ExchangeForConnectionAsync(subjectToken, provider, connectionId) in .NET, with HttpContext.GetAuthioAccessToken() as the subject token. provider is the connection provider’s alias.
| Result | What to tell the person |
|---|---|
| Granted | Nothing: use the provider’s access token. Authio never hands out the provider’s refresh token. |
| Connection required | The address where they connect the account (connectUri). |
| Selection required | The accounts to choose from; call again with one connectionId. |
| Refused | The reason, such as access_denied when the plan does not include connected accounts. |
In Node, describeConnectionRefusal(result, 'GitHub') words any result other than granted for the person.
Upgrading from 0.3
clientAuthenticationis nowtokenEndpointAuthMethod, andClientAuthenticationis nowTokenEndpointAuthMethod. The old names are not read.validAlgorithmsis nowaccessTokenSignedResponseAlg, andValidAlgorithmsis nowAccessTokenSignedResponseAlg; HS is accepted when listed, verified withclientSecret.requiredScopesleft out requires no scope (it wasmcp:tools), andintrospectionleft out is off (it wasactiveCheck). A server that relied on them now states them.DEFAULT_REQUIRED_SCOPEandAuthioMcpDefaults.Scopeare gone. In .NET,ClientIdis optional without introspection.
Try it end to end
curl -i -X POST https://mcp.example.com/mcp
curl https://mcp.example.com/.well-known/oauth-protected-resource/mcp
curl https://authio.api.hyperio.tech/.well-known/oauth-authorization-server/realms/acmeThe first call should answer 401 with resource_metadata, the second name your realm, the third describe it. Then connect a real client: add the server to Claude Code as shown above, or open the MCP Inspector with npx @modelcontextprotocol/inspector, point it at the endpoint and start the OAuth flow from its connection settings.
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
invalid_target at the authorize request | The MCP client may not ask for this resource. | List its client under Allowed clients, turn on Accept CIMD clients for a CIMD client, or Accept dynamically registered clients for a client created by dynamic registration. |
404 at /protocol/openid-connect/register, or no registration_endpoint in the metadata | Dynamic client registration is off in the realm. | Turn on Dynamic client registration (DCR) in the Access section of the realm’s page — or give the MCP client a pre-registered client or a metadata document. |
invalid_token at the registration endpoint | The access is InitialAccessToken and the credential is missing or lacks realm:write on the realm. | Send an API key or personal access token of the realm’s account with realm:write, not restricted to another realm or to a client. |
invalid_scope — scope must include openid | The client requires OpenID Connect and the MCP client asked only for your scope. | Turn Require OpenID Connect off on that client. |
| The hosted login refuses the redirect URI | The MCP client’s callback is not registered exactly. | Register it with its port, or turn on Loopback on any port. |
| The server does not start: Authio names a different issuer | authority is not the base Authio publishes in its issuer. | Use the issuer without /realms/acme, or pass issuer. |
| Every token refused: not issued for this resource | resource differs from the resource server’s identifier. | Make them identical, scheme, host and path included. |
Every token refused with 401 once introspection is on | Authio refused the introspection request with invalid_client. | Check the client ID, its secret or key, and that tokenEndpointAuthMethod is the client’s Token endpoint auth method. |
Tokens without mcp:tools get through | requiredScopes is left out, so no scope is required. | Set requiredScopes: ['mcp:tools']. |
| A revoked token still works until it expires | introspection is left out, so tokens are validated locally only. | Set introspection: 'activeCheck' and the introspection client. |
HS-signed tokens refused with invalid_algorithm | Without accessTokenSignedResponseAlg, only RS, PS and ES are accepted. | Use introspection: 'introspectionOnly', or sign the client’s access tokens with RS, PS or ES. |