Entry point wrapper for AI tools to integrate with Keycloak via the Model Context Protocol (MCP).
This package serves as a streamlined entry point for AI assistants (like Claude Desktop) to interact with Keycloak. It loads environment configuration and starts the another-keycloak-mcp server automatically.
npm installCopy the example environment file and configure it:
cp .env.example .envEdit .env with your Keycloak connection details:
# Keycloak Server Configuration
# IMPORTANT: Use 'localhost' or '127.0.0.1', not '0.0.0.0'
# For legacy Keycloak (<17) use: http://localhost:8082/auth
# For modern Keycloak (>=17) use: http://localhost:8082
KEYCLOAK_URL=http://localhost:8082/auth
KEYCLOAK_REALM=my-realm
# Authentication Method 1 (Recommended): Client Credentials
# Use a dedicated OIDC client with service account enabled
KEYCLOAK_CLIENT_ID=sso-admin-mcp
KEYCLOAK_CLIENT_SECRET=test12345
# Authentication Method 2 (Alternative): Admin User Credentials
# Note: Some Keycloak setups may not allow password grant type
# KEYCLOAK_ADMIN_USERNAME=admin
# KEYCLOAK_ADMIN_PASSWORD=admin
# Operation Mode: development | production
OPERATION_MODE=development
# Read-Only Mode: true | false
READ_ONLY_MODE=false
# Transport: stdio | http
TRANSPORT=stdio
# Logging Level: error | warn | info | debug
LOG_LEVEL=infonpm run buildnpm startOr use the binary directly:
node dist/index.jsThis MCP server can be integrated with various AI tools that support the Model Context Protocol.
Create or edit .cursor/mcp.json in your project directory:
{
"mcpServers": {
"keycloak": {
"command": "node",
"args": [
"/absolute/path/to/keycloak-mcp-entrypoint/dist/index.js"
]
}
}
}Important: Replace the path with your actual absolute path.
After configuration:
- Save the
mcp.jsonfile - Restart Cursor completely
- The Keycloak tools should appear in Cursor's AI context
- You can now ask Cursor to perform Keycloak operations (e.g., "list all users in the acme-x realm")
Add the following configuration to your Claude Desktop config file.
Configuration File Locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"keycloak": {
"command": "node",
"args": [
"/absolute/path/to/keycloak-mcp-entrypoint/dist/index.js"
]
}
}
}Important: Replace the path with your actual absolute path. To get your current directory path, run:
cd /path/to/keycloak-mcp-entrypoint
pwdEdit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"keycloak": {
"command": "node",
"args": [
"C:\\Users\\YourUsername\\Documents\\keycloak-mcp-entrypoint\\dist\\index.js"
]
}
}
}- Save the config file
- Completely quit and restart Claude Desktop (not just reload)
- Open a new conversation
- Look for the Keycloak MCP tools in the tools panel (hammer icon)
- You should see all 45 Keycloak management tools available
| Variable | Description | Default |
|---|---|---|
KEYCLOAK_URL |
Keycloak server URL (use localhost or 127.0.0.1, not 0.0.0.0) |
http://localhost:8082/auth |
KEYCLOAK_REALM |
Keycloak realm name | my-realm |
KEYCLOAK_CLIENT_ID |
OIDC Client ID for service account authentication (recommended) | sso-admin-mcp |
KEYCLOAK_CLIENT_SECRET |
OIDC Client secret for service account authentication | test12345 |
KEYCLOAK_ADMIN_USERNAME |
Admin username (alternative to client credentials) | - |
KEYCLOAK_ADMIN_PASSWORD |
Admin password (alternative to client credentials) | - |
OPERATION_MODE |
Operation mode: development or production |
development |
READ_ONLY_MODE |
Enable read-only mode: true or false |
false |
TRANSPORT |
Transport type: stdio or http |
stdio |
HTTP_PORT |
HTTP port (only when TRANSPORT=http) | 3000 |
HTTP_HOST |
HTTP host (only when TRANSPORT=http) | 0.0.0.0 |
LOG_LEVEL |
Logging level: error, warn, info, or debug |
info |
KEYCLOAK_VERSION |
Keycloak version being used | 26.4.5 |
The KEYCLOAK_URL format depends on your Keycloak version:
- Legacy Keycloak (< 17) or Red Hat SSO: Use
http://localhost:8082/auth - Modern Keycloak (>= 17): Use
http://localhost:8082
Important: Always use localhost or 127.0.0.1 for the client URL, not 0.0.0.0. While 0.0.0.0 is valid for server binding, it's not a valid target for HTTP clients.
The MCP server supports two authentication methods:
This is the recommended approach for service-to-service authentication. The MCP server will use OIDC client credentials flow.
Requirements:
- Create a dedicated OIDC client in Keycloak (e.g.,
sso-admin-mcp) - Enable "Service Accounts" for the client
- Assign appropriate roles to the service account:
- Go to the client → Service Account Roles tab
- Assign
realm-managementroles (e.g.,view-users,manage-users,view-realm, etc.)
Configuration:
KEYCLOAK_CLIENT_ID=sso-admin-mcp
KEYCLOAK_CLIENT_SECRET=test12345Advantages:
- More secure than username/password
- Works when password grant type is disabled
- Better for service accounts
- Supports token refresh
Uses admin username and password with the password grant type. This may not work if your Keycloak configuration disables the password grant type for security reasons.
Configuration:
KEYCLOAK_ADMIN_USERNAME=admin
KEYCLOAK_ADMIN_PASSWORD=admin
# Leave CLIENT_SECRET empty to use this methodNote: If both client credentials and username/password are provided, client credentials will be used (prioritized).
This entry point provides access to all 45 tools from another-keycloak-mcp:
- User Management (13 tools): Create, read, update, delete users, manage attributes, check multiple accounts, verify IDP links
- Group Management (16 tools): Full CRUD, hierarchy management, attribute search, boolean toggles
- Realm Operations (3 tools): List, read, and get stats for realms
- Authentication (3 tools): Manage authentication flows and required actions
- Realm Tools (3 tools): Export realms, check SAML certificates, list custom SPIs
- Client Scopes (7 tools): Full CRUD for client scope management
- Operation Modes: Run in
developmentorproductionmode with different safety levels - Read-Only Mode: Prevent all write operations when enabled
- Safety Checks: All destructive operations include safety warnings and checks
- Validation: All inputs validated with Zod schemas
- Automatic Token Refresh: Keycloak access tokens are automatically refreshed before expiration to prevent authentication failures
npm run build- Build the projectnpm run dev- Build in watch modenpm start- Run the built entry pointnpm run clean- Clean the dist foldernpm run type-check- Run TypeScript type checking
keycloak-mcp-entrypoint/
├── src/
│ └── index.ts # Entry point script
├── dist/ # Built output
├── .env # Your configuration (not committed)
├── .env.example # Example configuration
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── tsup.config.ts # Build configuration
If you cannot connect to Keycloak:
-
Verify Keycloak is running:
curl http://localhost:8082/auth/realms/master/.well-known/openid-configuration
You should see a JSON response with Keycloak configuration.
-
Check your
.envfile has the correctKEYCLOAK_URL:- Use
localhostor127.0.0.1, NOT0.0.0.0 - For legacy Keycloak (<17):
http://localhost:8082/auth - For modern Keycloak (>=17):
http://localhost:8082
- Use
-
Verify admin credentials are correct:
- Check your Keycloak admin console credentials
- Default is typically
admin/adminfor local development
-
Check logs for detailed error messages:
npm start
Look for connection errors or authentication failures in the output.
-
Common Error: "Unable to determine error message"
- This usually means the URL is incorrect (likely using
0.0.0.0instead oflocalhost) - Or the
/authpath is missing for legacy Keycloak versions
- This usually means the URL is incorrect (likely using
-
401 Unauthorized Error:
- The MCP server automatically refreshes expired tokens, but if you still see 401 errors:
- Verify credentials in
.envare correct - Check that the service account has proper roles assigned in Keycloak
- Ensure the realm name is spelled correctly
- Try restarting the MCP server (restart Cursor or Claude Desktop)
-
"unauthorized_client" Error:
- This means the client doesn't support the authentication method being used
- Solution: Switch to client credentials authentication (Method 1)
- Ensure your Keycloak client has "Service Accounts Enabled" turned ON
- Assign proper
realm-managementroles to the service account - Update your
.envto useKEYCLOAK_CLIENT_IDandKEYCLOAK_CLIENT_SECRET
If Cursor doesn't show the Keycloak tools or shows "no tools, prompts or resources":
- Verify the
.cursor/mcp.jsonfile exists in your project root - Check the absolute path is correct in the config file
- Ensure the project is built:
npm run build - Restart Cursor completely - close all windows and reopen
- Check Cursor's MCP logs for any error messages
- Test the server manually:
You should see successful Keycloak connection messages
cd /path/to/keycloak-mcp-entrypoint npm start
If Claude Desktop doesn't show the Keycloak tools:
-
Verify the absolute path in
claude_desktop_config.jsonis correct:# Get the correct path cd /path/to/keycloak-mcp-entrypoint pwd # Then append /dist/index.js to this path
-
Ensure the project is built:
npm run build
Verify
dist/index.jsexists. -
Test the server manually first:
npm start
Make sure it connects successfully before adding to Claude Desktop.
-
Completely quit and restart Claude Desktop (not just reload):
- macOS: Cmd+Q to quit, then reopen
- Windows: File → Exit, then reopen
- Linux: Close all windows, then reopen
-
Check Claude Desktop logs for errors:
- macOS:
~/Library/Logs/Claude/mcp*.log - Windows:
%APPDATA%\Claude\logs\mcp*.log - Linux:
~/.config/Claude/logs/mcp*.log
- macOS:
-
Verify JSON syntax is correct:
- Use a JSON validator to check your config file
- Make sure there are no trailing commas
- Ensure proper quote escaping (especially on Windows paths: use
\\)
If the build fails:
- Ensure
another-keycloak-mcpis built:cd ../another-keycloak-mcp && npm run build - Clean and rebuild:
npm run clean && npm install && npm run build - Check Node.js version:
node --version(requires >= 18.0.0)
MIT