Skip to main content

MCP authentication

Requests to the Casdoor MCP server at /api/mcp are authenticated in the same ways as requests to the Casdoor API. This page describes how a client discovers what the server requires, and how each authentication method affects the tools that the client can call.

OAuth discovery​

Casdoor publishes OAuth 2.0 Protected Resource Metadata (RFC 9728), so that an MCP client can find out which authorization server protects the MCP endpoint:

curl https://your-casdoor.com/.well-known/oauth-protected-resource

The response names the authorization server:

{
"resource": "https://your-casdoor.com",
"authorization_servers": ["https://your-casdoor.com"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["openid", "profile", "email", "read", "write"],
"resource_signing_alg_values_supported": ["RS256"]
}

To get the metadata of a single application, put the application name in the path:

curl https://your-casdoor.com/.well-known/my-app/oauth-protected-resource

Use the application-specific endpoint when applications have different authorization requirements.

Organizations with their own issuer​

The metadata above names the global issuer, so an MCP client that connects to /api/mcp registers and signs users in on the default organization, built-in. When users of another organization use the MCP server, give them the endpoint of their organization:

https://your-casdoor.com/api/mcp/orgs/<organization>

It is the same MCP server with the same tools. Only the protected resource metadata differs: the challenge of an unauthenticated request points to /.well-known/oauth-protected-resource/api/mcp/orgs/<organization>, which names the issuer of the organization as the authorization server:

{
"resource": "https://your-casdoor.com/api/mcp/orgs/acme",
"authorization_servers": ["https://your-casdoor.com/orgs/acme"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["openid", "profile", "email", "read", "write"]
}

Turn on Use organization issuer for the organization first. Without it, the authorization server is still the global issuer. The client then reads the discovery document of the organization, registers in the organization, and signs users in on its sign-in page.

Authentication methods​

MethodTools that the client can callUse it for
Access tokenThe tools that the scopes of the token allow. See MCP authorization and scopesAutomation and MCP clients. This is the recommended method
Client ID and client secretThe tools that the application may useService accounts
Session cookieAll tools, without scope checksInteractive use in the browser

With an access token:

curl -X POST https://your-casdoor.com/api/mcp \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

With the client ID and client secret of an application:

curl -X POST https://your-casdoor.com/api/mcp \
-u "CLIENT_ID:CLIENT_SECRET" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Unauthenticated requests​

Casdoor answers a request to /api/mcp that it doesn't authorize, for example a request without credentials, with HTTP 401 and the header:

WWW-Authenticate: Bearer realm="casdoor", resource_metadata="https://your-casdoor.com/.well-known/oauth-protected-resource", scope="openid profile email read write"

resource_metadata is the URL of the protected resource metadata on the host of the request, including the base path of Casdoor. The scheme is http when the host contains no dot, such as localhost:8000, and https otherwise. scope lists the scopes that the client should request. An MCP client that follows the OAuth 2.0 specification reads the metadata from that URL and starts the authorization flow on its own.

The body of the response depends on the request:

RequestResponse
A JSON-RPC request with an idHTTP 401 with a JSON-RPC error, whose data gives the reason
A JSON-RPC notification, without an id, or a body that isn't JSON-RPCHTTP 401 with an empty body

A request with a method other than POST, such as GET, gets HTTP 405 with the header Allow: POST and no challenge, whether or not it is authenticated: the MCP server doesn't open an SSE stream with GET. A signed-in user or a valid token that isn't allowed to do the operation gets HTTP 403 without a challenge, since signing in again wouldn't help.

For example:

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32001,
"message": "Unauthorized",
"data": "Unauthorized operation"
}
}

The proxy endpoint of an external MCP server, /api/server/<organization>/<server-name>, answers in the same way, except that it accepts GET requests, its challenge has no scope, and a GET request without credentials gets HTTP 401 with an empty body.

See also​