# Protect your MCP server

If you run a Model Context Protocol (MCP) server, OhAuthCat can be its authorization server. MCP clients such as AI assistants then discover how to sign in, register themselves, ask your user for consent and get short-lived tokens for your server only. This follows the MCP Authorization specification (2025-06-18 and 2025-11-25), RFC 9728, RFC 7591, RFC 7592 and RFC 8707.

## Set it up

1. Register your server as a resource: `POST /v1/oauth/resources` with `kind: "mcp"`, its absolute `https` identifier (the URL clients use), its `scopes` and `dynamic_registration: true`. MCP tokens last 5 minutes by default.
2. Fetch the protected resource metadata with `GET /v1/oauth/resources/{resource}/protected_resource_metadata` and serve that JSON at `/.well-known/oauth-protected-resource` on your server.
3. When a request has no valid token, answer `401` with `WWW-Authenticate: Bearer resource_metadata="<that metadata URL>"`.
4. On every request, verify the bearer token: ES256 signature from the issuer's `/jwks`, `typ: at+jwt`, the issuer `https://login.ohauthcat.com/oauth/<environment id>`, `aud` equal to your identifier exactly, and an unexpired `exp`. Check `scope` for the tool being called.

The CLI does steps 1 and 2 with `ohauthcat mcp-auth resources create` and `ohauthcat mcp-auth resources metadata`.

## What clients do

The client reads your metadata, finds the OhAuthCat issuer, registers itself at `/register` (open registration exists only while some resource allows it, limited to 10 registrations an hour per address and 100 an hour per environment), runs the authorization code flow with PKCE and `resource`, and shows your user a consent screen. Dynamically registered clients are always third-party, must name one resource that allows dynamic registration and cannot use client credentials.

## Agents and revocation

`GET /v1/oauth/grants` lists what users have authorized; grants of dynamic clients carry `agent: true`. Revoke one grant, every grant of a user, or every grant of an organization's members (`POST /v1/organizations/{org}/oauth_grants/revoke`).

OhAuthCat's own [hosted MCP server](/reference/hosted-mcp/), which manages your OhAuthCat project, still uses API keys.
