MCP security
Deploying an MCP server exposes a tool-calling surface that AI clients can reach directly. Unlike a traditional API consumed by humans, MCP servers are called autonomously by agents that may hold broad permissions. Two concerns matter most: who can call which tools, and what did they actually do.
Casdoor addresses both. It acts as the OAuth 2.1 authorization server that gates access, and as the telemetry backend that records what happened.
Access control
MCP uses OAuth 2.1 with a clean separation between the authorization server and the resource server. The MCP server (your tool host) delegates authentication entirely to an external provider — it never manages users or issues tokens. Casdoor fills that role.
How the flow works
When an MCP client connects to a server for the first time:
- The server returns
401 Unauthorizedwith aWWW-Authenticateheader pointing to its Protected Resource Metadata endpoint. - The client fetches
/.well-known/oauth-protected-resourceto discover which authorization server protects the resource. - The client registers itself with Casdoor via Dynamic Client Registration (RFC 7591) if it doesn't have credentials yet.
- The client completes an authorization code + PKCE flow against Casdoor, obtaining an access token with the scopes the user consented to.
- Subsequent requests carry
Authorization: Bearer <token>. The MCP server validates the JWT against Casdoor's JWKS endpoint before executing any tool.
The MCP server's implementation burden is minimal: serve the metadata document, return 401 challenges, validate JWTs, and enforce scopes per tool.