Connect Claude to the Casdoor MCP server
This guide explains how to connect Claude to the MCP server of Casdoor, or to an MCP server behind the Casdoor MCP gateway. It covers three ways:
- A custom connector in Claude Desktop, claude.ai, and the Claude mobile apps. Claude connects from the cloud of Anthropic, so Casdoor must be reachable from the Internet.
- Claude Code, the command-line agent, which connects from your computer.
mcp-remoteinclaude_desktop_config.json, for a Casdoor instance that only your computer can reach.
Learning outcomes
- Let Claude identify itself to Casdoor without an application created by hand.
- Add the MCP server to Claude in the way that fits your network.
- Sign in and check that Claude can call the tools.
What you need
- A running Casdoor instance. Use HTTPS in production.
- Claude Desktop, a claude.ai account, or Claude Code
- Global administrator access to the Casdoor admin console
Accept Claude in Casdoor
Claude identifies itself with a client ID metadata document (CIMD): its client ID is the URL of a document that Anthropic publishes, and Casdoor reads the document instead of asking Claude to register. Claude falls back to dynamic client registration (DCR) when the authorization server doesn't support CIMD. Both are governed by one switch:
- In the Casdoor admin console, go to User Management > Organizations and open the organization whose users sign in to Claude:
built-infor the Casdoor MCP server, or the organization of the server for a server behind the MCP gateway. - Turn on Enable dynamic client registration.
- Save the organization.
The discovery document of the organization then announces client_id_metadata_document_supported: true and lists none in token_endpoint_auth_methods_supported, the two values that Claude checks before it uses CIMD.
| Claude | Client ID | Redirect URI |
|---|---|---|
| Claude Desktop, claude.ai, mobile | https://claude.ai/oauth/mcp-oauth-client-metadata | https://claude.ai/api/mcp/auth_callback |
| Claude Code | https://claude.ai/oauth/claude-code-client-metadata | http://localhost:<port>/callback |
On the first sign-in, Casdoor creates an application for each client ID, with a name that starts with cimd_ and the tag cimd. All organizations share this one application, and each user signs in to their own organization. See Accept clients identified by a metadata document URL.
Option 1: add a custom connector
Claude Desktop, claude.ai, and the mobile apps share connectors. Claude connects to the MCP server and to Casdoor from the cloud of Anthropic, from the address range 160.79.104.0/21, so both must be reachable from the Internet over HTTPS. For the current steps, see Get started with custom connectors in the Claude Help Center.
Free, Pro, and Max plans:
- In Claude, go to Customize > Connectors, and select Add custom connector.
- Enter a name, such as
Casdoor, and the URL of the MCP server:https://your-casdoor.com/api/mcpfor the MCP server of Casdoorhttps://your-casdoor.com/api/server/<organization>/<server-name>for a server behind the MCP gateway
- Under the OAuth client options, keep Use Claude's published identity (Recommended).
- Select Add, and then Connect.
Team and Enterprise plans: an owner adds the connector in Organization settings > Connectors > Add > Custom > Web with the same URL, and each member selects Connect in their own Connectors settings.
When you select Connect, Claude opens the Casdoor sign-in page:
- Sign in with your account.
- If Casdoor shows a consent screen, click Allow.
- Casdoor sends you back to Claude. The connector shows as connected.
You can't change the authentication of a connector later. To switch to another OAuth client, remove the connector and add it again.
Use an application that you create
If you don't want to turn on dynamic client registration, create the client yourself:
- In the Casdoor admin console, go to Identity > Applications and add an application in the organization of your users, for example
claude-mcp. - Add
https://claude.ai/api/mcp/auth_callbackto Redirect URLs. - Save the application and copy its Client ID and Client Secret.
- In the Add custom connector dialog, choose Use your own OAuth client and enter them.
Option 2: Claude Code
Claude Code runs on your computer, so Casdoor only has to be reachable from it.
-
Add the server:
claude mcp add --transport http casdoor https://your-casdoor.com/api/mcpFor a server behind the MCP gateway, use the gateway URL instead. Add
--scope projectto share the server with your team through.mcp.json, or--scope userfor all your projects. -
Start Claude Code, run
/mcp, select the server, and select Authenticate. Your browser opens the Casdoor sign-in page.
Claude Code listens on a random port for the callback. Its document lists http://localhost/callback and http://127.0.0.1/callback, and Casdoor matches a loopback redirect URI on any port, as RFC 8252 requires. To sign out, run claude mcp logout casdoor, or select Clear authentication in /mcp.
To use an application that you create, pass its credentials and fix the port, so that the redirect URI is known:
claude mcp add --transport http --client-id <client-id> --client-secret --callback-port 8080 casdoor https://your-casdoor.com/api/mcp
Add http://localhost:8080/callback to the Redirect URLs of the application. See Connect Claude Code to tools via MCP.
Option 3: claude_desktop_config.json and mcp-remote
When Casdoor is on your local network or your computer, the cloud of Anthropic can't reach it. Run the connection on your computer with the mcp-remote package instead, which bridges Claude Desktop to a remote server over standard input and output and runs the OAuth 2.0 flow with DCR. It needs Node.js, which provides npx.
-
Open the configuration file of Claude Desktop in a text editor:
Operating system Path macOS ~/Library/Application Support/Claude/claude_desktop_config.jsonWindows %APPDATA%\Claude\claude_desktop_config.jsonLinux ~/.config/Claude/claude_desktop_config.json -
Add the server:
{
"mcpServers": {
"casdoor": {
"command": "npx",
"args": [
"mcp-remote",
"https://your-casdoor.com/api/mcp"
]
}
}
} -
Quit Claude Desktop completely, not only its window, and start it again.
mcp-remoteopens your browser for the sign-in.
mcp-remote registers an application whose name starts with dcr_ and listens for the callback at http://localhost:3334/oauth/callback. It stores the tokens on your computer.
Verify the result
Ask Claude to use the server, for example:
- "List all applications in Casdoor."
- "Show me the application named
my-app." - "Create an application called
test-appin the organizationmy-org."
Claude calls the MCP tools and answers with data from the server. In the Casdoor admin console, the Tokens page shows the token of your user for the cimd_ or dcr_ application.
Troubleshooting
Claude says it can't reach the server
- Check that the URL ends with
/api/mcp, or is a gateway URL/api/server/<organization>/<server-name>. - For a custom connector, check that Casdoor is reachable from the Internet with a valid certificate, and that no firewall blocks
160.79.104.0/21. Use Claude Code ormcp-remotefor a Casdoor instance on a private network. - Call the server yourself:
curl -i -X POST https://your-casdoor.com/api/mcp. Casdoor answers HTTP 401 with aWWW-Authenticateheader that names the protected resource metadata, which is what starts the sign-in in Claude.
Casdoor rejects the client ID metadata document
The error "client ID metadata documents are not accepted" means that Enable dynamic client registration is off for the organization. See Accept Claude in Casdoor.
Casdoor reports a redirect URL mismatch
For an application that you created, check that Redirect URLs contains the exact callback of the client: https://claude.ai/api/mcp/auth_callback for a connector, or http://localhost:<port>/callback for Claude Code with --callback-port. For mcp-remote, if port 3334 is in use, it chooses another port; free the port, delete the dcr_ application and the cached credentials of mcp-remote in ~/.mcp-auth, and connect again.
A tool call fails with insufficient_scope
The token lacks the scope that the tool requires. See MCP authorization and scopes.
Secure the connection
- HTTPS: Serve Casdoor over HTTPS in production, to protect the OAuth 2.0 flow.
- Least privilege: Sign in with an account that has only the rights that Claude needs.
- Revocation: To cut off the client, delete its tokens on the Tokens page of the Casdoor admin console.
- Enterprise: With an enterprise identity provider, Claude Team and Enterprise can get tokens without a browser sign-in. See Enterprise-managed authorization.