---
title: "MCP OAuth 2.1 authorization server"
description: "Run theAuth as your MCP OAuth 2.1 authorization server: PKCE S256, RFC 9728, 8707, 8414 and 7591, refresh rotation and a zero-dependency resource module."
canonical: https://theauth.dev/mcp-oauth/
lastmod: 2026-10-31
---

MCP authorization

# MCP OAuth 2.1 authorization server

Secure an MCP server with an authorization server you host. theAuth implements the discovery, registration and token steps MCP clients expect, and adds agent identity and delegation chains behind the token.

[Read the MCP guide](https://docs.theauth.dev/mcp) [mcpresource on pkg.go.dev](https://pkg.go.dev/github.com/glincker/theauth-go/mcpresource)

Discover, register, get a token

## What an MCP client does, step by step

The client starts knowing only the MCP server URL. Everything else is discovered.

Client to resource server

### Call without a token

The MCP server answers 401 with a `WWW-Authenticate: Bearer` header that points at its resource metadata (RFC 6750, RFC 9728).

Client to resource server

### Read protected resource metadata

`GET /.well-known/oauth-protected-resource` names the resource and its authorization servers (RFC 9728).

Client to authorization server

### Read server metadata

`GET /.well-known/oauth-authorization-server` lists endpoints and `code_challenge_methods_supported: ["S256"]` (RFC 8414).

Client to authorization server

### Register

Dynamic registration (RFC 7591), or in Go a CIMD client whose `client_id` is an https URL the server fetches (MCP spec 2025-11-25).

Client to authorization server

### Authorize with PKCE

The client sends a PKCE S256 challenge and a `resource` indicator (RFC 8707). The user consents and a code returns.

Client to authorization server

### Exchange the code

The code and verifier go to the token endpoint. The access token is bound to the audience.

Client to resource server

### Call with the token

The MCP server validates signature, audience, scope and expiry before running the tool.

Endpoint URLs are advertised in the metadata, so clients do not hard-code them. The TypeScript server serves `/mcp/register`, `/mcp/authorize` and `/mcp/token`. The Go server serves `/oauth/register`, `/oauth/authorize` and `/oauth/token`.

The token it issues

## Read the token one claim at a time

What a resource server sees once the client has its token, and what each claim is for.

access token payload (decoded, example)

```json
{
  "sub": "user-123",
  "act": { "sub": "agt_planner" },
  "aud": "https://mcp.example.com",
  "scope": "read:calendar",
  "cnf": { "jkt": "0ZcOCORZ..." },
  "exp": 1790000900
}
```

1. subWho the token speaks for: the human who owns the grant.
2. actWho is acting. After an RFC 8693 token exchange the agent appears here, so the resource server sees both the owner and the actor.
3. audThe one resource server this token is for (RFC 8707 resource indicator). Any other server should refuse it.
4. scopeWhat it may do. An exchange can narrow scope, never widen it.
5. cnf.jktRFC 9449 DPoP binding: the thumbprint of the client key. A stolen token without that key is not accepted.
6. expExpiry. Short lifetimes limit what a leak is worth. The Go server defaults to one hour and lets you shorten it.

Values are made up. act and cnf.jkt appear in the Go authorization server (token exchange and DPoP are opt-in features). Claim names follow the RFCs.

Go

## CIMD, rotation and the resource module

- **CIMD.** When enabled, a `client_id` that is an https URL is resolved by fetching a metadata document. The document's `client_id` must equal the URL it was fetched from. The trust policy defaults to deny all; you opt in with `AllowHTTPSHosts` or `AllowAnyHTTPS`.
- **Refresh rotation with family revocation.** Presenting an already-used refresh token revokes the whole token family (RFC 9700).
- **mcpresource.** A standalone Go module with no dependencies outside the standard library. It checks the JWT against a cached JWKS, enforces audience, and walks the RFC 8693 actor chain through introspection. Revocation reaches it within the cache TTL, 60 seconds by default.
- **More Go grants.** RFC 8693 token exchange, 9449 DPoP, 9126 PAR, 9101 JAR and 9509 CIBA.

main.go

```go
// Resource server: go get github.com/glincker/theauth-go/mcpresource
v := mcpresource.New(
    "https://mcp.example.com",
    mcpresource.WithJWKS("https://as.example.com/oauth/jwks"),
    mcpresource.WithIntrospection(
        "https://as.example.com/oauth/introspect",
        "mcp-client-id", "mcp-client-secret",
    ),
)
r := chi.NewRouter()
r.Use(v.Middleware) // JWT validation, audience check, actor-chain walk
r.Get("/tools/run", func(w http.ResponseWriter, r *http.Request) {
    p, _ := v.Principal(r.Context())
    // p.Subject (user), p.Actor (final agent), p.ActorChain (delegation path)
})
```

Runnable example: [examples/mcp-server](https://github.com/glincker/theauth-go/tree/main/examples/mcp-server).

auth.ts

```ts
import { createTheAuth } from "@glinr/theauth";

const auth = await createTheAuth({
  database: { provider: "postgres", url: process.env.DATABASE_URL },
  mcp: {
    enabled: true,
    issuer: "https://auth.yourapp.com",
    baseUrl: "https://auth.yourapp.com",
    signingSecret: process.env.MCP_SIGNING_SECRET,
  },
});
```

TypeScript

## Enable it in the core

Mount the MCP routes through a framework adapter, then validate tokens with auth.mcp.validate(token) or the adapter's withMcpAuth middleware. TypeScript access tokens are HS256 at+jwt signed with your secret, so validation happens in the same deployment. The Go server signs with Ed25519 and publishes a JWKS, which lets separate resource servers verify tokens on their own.

Where it fits

## What differs from other options

Other identity products also document MCP OAuth support, so the protocol alone is not the difference. What theAuth adds:

- [Agent identity and delegation chains](https://theauth.dev/agent-identity/) behind the same tokens, with per-agent audit.
- MIT license and self-hosting on your own database.
- A zero-dependency Go resource-server module.

Choose another tool if

you already run a hosted identity provider that meets your MCP needs and you do not need agent-level identity or self-hosting.

- [Agent identity](https://theauth.dev/agent-identity/)
- [Security](https://theauth.dev/security/)
- [MCP on the homepage](https://theauth.dev/#mcp)
- [MCP authorization spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization)

[DPoP and device flow for agents](https://theauth.dev/agent-oauth/) [Secure an MCP server in TypeScript](https://theauth.dev/guides/mcp-server-typescript/) [Better Auth alternative](https://theauth.dev/compare/better-auth/) [Auth0 for MCP compared](https://theauth.dev/compare/auth0-for-mcp/)
