This guide will help you get started with the Keycloak MCP Server using different deployment methods.
http://localhost:8180 or https://localhost:8543https://keycloak.example.comdocker pull quay.io/sshaaf/keycloak-mcp-server:latest
Note: The MCP server validates JWT tokens using OIDC discovery. No client secret is required.
mcp-serverProduction/Remote Keycloak:
docker run -d \
--name keycloak-mcp-server \
-p 8080:8080 \
-e KC_URL=https://keycloak.example.com \
-e KC_REALM=master \
-e OIDC_CLIENT_ID=mcp-server \
quay.io/sshaaf/keycloak-mcp-server:latest
Local Keycloak (macOS/Windows):
docker run -d \
--name keycloak-mcp-server \
-p 8080:8080 \
-e KC_URL=http://host.docker.internal:8180 \
-e KC_REALM=master \
-e OIDC_CLIENT_ID=mcp-server \
quay.io/sshaaf/keycloak-mcp-server:latest
Note: Use host.docker.internal instead of localhost to access services running on your host
Local Keycloak (Linux):
docker run -d \
--name keycloak-mcp-server \
--network host \
-e KC_URL=http://localhost:8180 \
-e KC_REALM=master \
-e OIDC_CLIENT_ID=mcp-server \
quay.io/sshaaf/keycloak-mcp-server:latest
# Check container status
docker ps | grep keycloak-mcp-server
# Check logs
docker logs keycloak-mcp-server
# Test health endpoint
curl http://localhost:8080/q/health
Edit ~/.cursor/mcp.json:
{
"mcpServers": {
"keycloak": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
}
}
}
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)In Cursor chat, ask:
List all Keycloak realms
Expected result: You should see a list of all realms from your Keycloak instance.
oc CLI installed and configured./setup-service-account.sh
–keycloak-url https://keycloak.apps.example.com
–admin-user admin
–admin-password your-admin-password
–client-id mcp-server
–realm master
Or follow the manual steps in [authentication.md](/keycloak-mcp-server/authentication.html).
### Step 3: Deploy MCP Server
1. **Create a new project (or use existing):**
```bash
oc new-project keycloak-mcp-server
# Or use existing project
# oc project your-project
oc create configmap keycloak-mcp-config \
--from-literal=keycloak-url=https://keycloak.apps.example.com \
--from-literal=keycloak-realm=master \
--from-literal=client-id=mcp-server
# Replace with your actual client secret from Step 2
oc create secret generic keycloak-mcp-secret \
--from-literal=client-secret=your-client-secret-from-keycloak
# Find the TLS secret name
KC_TLS_SECRET=$(oc get keycloak -o jsonpath='{.items[0].spec.http.tlsSecret}' -n keycloak)
# Extract and create CA bundle
oc get secret $KC_TLS_SECRET -n keycloak -o jsonpath='{.data.tls\.crt}' | \
base64 -d > /tmp/keycloak-ca.crt
oc create configmap keycloak-ca-bundle \
--from-file=ca.crt=/tmp/keycloak-ca.crt
rm /tmp/keycloak-ca.crt
# Clone the repository
git clone https://github.com/sshaaf/keycloak-mcp-server.git
cd keycloak-mcp-server
# Apply deployment manifests
oc apply -f deploy/openshift/deployment.yaml
oc apply -f deploy/openshift/service.yaml
oc apply -f deploy/openshift/route.yaml
Or use the automated deployment script:
cd keycloak-mcp-server/deploy/openshift
chmod +x deploy.sh
./deploy.sh
oc get route keycloak-mcp-server -o jsonpath='{.spec.host}'
# Example output: keycloak-mcp-server-your-project.apps.example.com
# Check pod status
oc get pods -l app=keycloak-mcp-server
# Check logs
oc logs -f deployment/keycloak-mcp-server
# Test health endpoint
ROUTE_URL=$(oc get route keycloak-mcp-server -o jsonpath='{.spec.host}')
curl https://$ROUTE_URL/q/health
Edit ~/.cursor/mcp.json:
{
"mcpServers": {
"keycloak": {
"transport": "sse",
"url": "https://keycloak-mcp-server-your-project.apps.example.com/mcp/sse"
}
}
}
Replace keycloak-mcp-server-your-project.apps.example.com with your actual route URL from Step 4.
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)In Cursor chat, ask:
List all users from the master realm
Expected result: You should see a list of users from your Keycloak master realm.
Download the latest native binary for your platform from the releases page:
Linux (x64):
wget https://github.com/sshaaf/keycloak-mcp-server/releases/download/v0.3.0/keycloak-mcp-server-linux-x64
chmod +x keycloak-mcp-server-linux-x64
macOS (x64):
wget https://github.com/sshaaf/keycloak-mcp-server/releases/download/v0.3.0/keycloak-mcp-server-darwin-x64
chmod +x keycloak-mcp-server-darwin-x64
macOS (ARM64):
wget https://github.com/sshaaf/keycloak-mcp-server/releases/download/v0.3.0/keycloak-mcp-server-darwin-arm64
chmod +x keycloak-mcp-server-darwin-arm64
Or build from source:
git clone https://github.com/sshaaf/keycloak-mcp-server.git
cd keycloak-mcp-server
mvn clean package -Dnative -DskipTests
Follow the steps in authentication.md to create a OIDC client in Keycloak.
Create a .env file:
cat > keycloak-mcp.env << EOF
KC_URL=https://keycloak.example.com
KC_REALM=master
OIDC_CLIENT_ID=mcp-server
QUARKUS_HTTP_PORT=8080
EOF
# Load environment variables
export $(cat keycloak-mcp.env | xargs)
# Run the native binary
./keycloak-mcp-server-linux-x64
# Or for macOS: ./keycloak-mcp-server-darwin-arm64
Run as Background Service (Linux/macOS):
# Create systemd service (Linux)
sudo tee /etc/systemd/system/keycloak-mcp-server.service > /dev/null <<EOF
[Unit]
Description=Keycloak MCP Server
After=network.target
[Service]
Type=simple
User=mcp-server
EnvironmentFile=/opt/keycloak-mcp/keycloak-mcp.env
ExecStart=/opt/keycloak-mcp/keycloak-mcp-server-linux-x64
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable keycloak-mcp-server
sudo systemctl start keycloak-mcp-server
# Check if port is listening
lsof -i :8080
# Or: netstat -tuln | grep 8080
# Test health endpoint
curl http://localhost:8080/q/health
Edit ~/.cursor/mcp.json:
{
"mcpServers": {
"keycloak": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
}
}
}
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)In Cursor chat, ask:
List all authentication flows from the master realm
Expected result: You should see a list of authentication flows from your Keycloak master realm.
Warning: This method is for development only. Use user authentication authentication for production.
git clone https://github.com/sshaaf/keycloak-mcp-server.git
cd keycloak-mcp-server
Edit src/main/resources/application.properties:
# Keycloak Connection (Development Mode)
quarkus.keycloak.admin-client.server-url=http://localhost:8180
quarkus.keycloak.admin-client.username=admin
quarkus.keycloak.admin-client.password=admin
# Dev services disabled (using external Keycloak)
quarkus.keycloak.devservices.enabled=false
# HTTP Configuration
quarkus.http.port=8080
quarkus.http.host=0.0.0.0
Or use environment variables:
export KC_URL=http://localhost:8180
export KC_REALM=master
export OIDC_CLIENT_ID=mcp-server
Note: Development mode disables authentication for convenience. No credentials are required.
mvn quarkus:dev
The server will start on http://localhost:8080 with hot-reload enabled.
Features in Dev Mode:
http://localhost:8080/q/dev# Test health endpoint
curl http://localhost:8080/q/health
# Access Dev UI
open http://localhost:8080/q/dev
Edit ~/.cursor/mcp.json:
{
"mcpServers": {
"keycloak-dev": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
}
}
}
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)In Cursor chat, ask:
Count all users in Keycloak
Expected result: You should see the total count of users across all realms.
Since you are in development mode, you can make code changes:
src/main/java/macOS/Linux:
~/.cursor/mcp.json
Windows:
%USERPROFILE%\.cursor\mcp.json
{
"mcpServers": {
"keycloak": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
}
}
}
{
"mcpServers": {
"keycloak-prod": {
"transport": "sse",
"url": "https://keycloak-mcp-server.apps.example.com/mcp/sse"
},
"keycloak-dev": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
}
}
}
{
"mcpServers": {
"keycloak": {
"transport": "sse",
"url": "http://localhost:8080/mcp/sse"
},
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {}
}
}
}
After editing mcp.json:
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)Try these commands in Cursor chat to verify everything is working:
List all Keycloak realms
Expected Output:
Found 3 realms:
1. master - Red Hat build of Keycloak (Enabled)
2. quarkus (Enabled)
3. test (Enabled)
How many users are in the master realm?
Expected Output:
There are X users in the master realm.
Show me all clients in the master realm
Expected Output:
Found X clients:
- account
- admin-cli
- broker
- master-realm
- mcp-server
- ...
Search Keycloak Discourse for "LDAP integration"
Expected Output:
Found X topics related to "LDAP integration":
1. [Topic Title] - https://keycloak.discourse.group/...
2. ...
Test the MCP server directly:
# Health check
curl http://localhost:8080/q/health
# Liveness probe
curl http://localhost:8080/q/health/live
# Readiness probe
curl http://localhost:8080/q/health/ready
# MCP SSE endpoint
curl -N http://localhost:8080/mcp/sse
The Keycloak MCP Server supports the following operations:
GET_USERS - List all usersGET_USER_BY_USERNAME - Get user by usernameGET_USER_BY_ID - Get user by IDCREATE_USER - Create a new userDELETE_USER - Delete a userUPDATE_USER - Update user detailsGET_USER_GROUPS - Get user’s groupsGET_USER_ROLES - Get user’s rolesADD_USER_TO_GROUP - Add user to groupREMOVE_USER_FROM_GROUP - Remove user from groupADD_ROLE_TO_USER - Assign role to userREMOVE_ROLE_FROM_USER - Remove role from userRESET_PASSWORD - Reset user passwordSEND_VERIFICATION_EMAIL - Send verification emailCOUNT_USERS - Count users in realmGET_REALMS - List all realmsGET_REALM - Get realm detailsCREATE_REALM - Create a new realmGET_CLIENTS - List all clientsGET_CLIENT - Get client detailsCREATE_CLIENT - Create a new clientDELETE_CLIENT - Delete a clientGENERATE_CLIENT_SECRET - Generate new client secretGET_CLIENT_ROLES - Get client rolesCREATE_CLIENT_ROLE - Create client roleDELETE_CLIENT_ROLE - Delete client roleGET_REALM_ROLES - List realm rolesGET_REALM_ROLE - Get realm role detailsGET_GROUPS - List all groupsGET_GROUP_MEMBERS - Get group membersCREATE_GROUP - Create a groupUPDATE_GROUP - Update group detailsDELETE_GROUP - Delete a groupCREATE_SUBGROUP - Create a subgroupGET_IDENTITY_PROVIDERS - List identity providersGET_IDENTITY_PROVIDER - Get identity provider detailsGET_IDENTITY_PROVIDER_MAPPERS - Get identity provider mappersGET_AUTHENTICATION_FLOWS - List authentication flowsGET_AUTHENTICATION_FLOW - Get flow detailsCREATE_AUTHENTICATION_FLOW - Create a flowDELETE_AUTHENTICATION_FLOW - Delete a flowGET_FLOW_EXECUTIONS - Get flow executionsUPDATE_FLOW_EXECUTION - Update flow executionSEARCH_DISCOURSE - Search Keycloak community forum# User management
"Create a user named john.doe with email john@example.com in the master realm"
"List all users in the quarkus realm"
"Add user alice to the admin group"
# Client management
"Show me all clients in the master realm"
"Create a new confidential client named my-app"
"Generate a new secret for the my-app client"
# Realm management
"List all realms"
"Show me the details of the quarkus realm"
"Create a new realm named production"
# Authentication flows
"List all authentication flows in the master realm"
"Show me the browser authentication flow"
# Discourse search
"Search Keycloak Discourse for 'SAML configuration'"
"Find topics about user federation"
Symptoms:
Solutions:
# For OpenShift oc get pods -l app=keycloak-mcp-server oc logs -f deployment/keycloak-mcp-server
# For native binary ps aux | grep keycloak-mcp-server
2. **Test the health endpoint:**
```bash
curl http://localhost:8080/q/health
curl -N http://localhost:8080/mcp/sse
Cmd+Shift+P → “Reload MCP Servers”Symptoms:
SSLHandshakeException: Failed to create SSL connectionSolutions:
docker run -d \
-e QUARKUS_TLS_TRUST_ALL=true \
-e QUARKUS_REST_CLIENT_TRUST_ALL=true \
...
export QUARKUS_TLS_TRUST_ALL=true
./keycloak-mcp-server-linux-x64
Symptoms:
401 Unauthorized errors403 Forbidden errorsSolutions:
curl -I https://keycloak.example.com
curl -X POST https://keycloak.example.com/realms/master/protocol/openid-connect/token \
-d 'grant_type=password' \
-d 'client_id=admin-cli' \
-d 'username=your-username' \
-d 'client_secret=your-secret'
curl -X POST https://keycloak.example.com/realms/master/protocol/openid-connect/token \
-d 'grant_type=password' \
-d 'client_id=admin-cli' \
-d 'username=admin' \
-d 'password=admin'
Symptoms:
Connection refused errorsNo route to host errorsSolutions:
curl http://localhost:8180
# Or for HTTPS
curl -k https://localhost:8543
host.docker.internal instead of localhost--network host or configure bridge networking# macOS sudo pfctl -sr
5. **Verify port is not in use:**
```bash
lsof -i :8080
Symptoms:
Solutions:
Cmd+Shift+P → “Reload MCP Servers”Restart Cursor completely
# Validate JSON
cat ~/.cursor/mcp.json | python -m json.tool
Symptoms:
Solutions:
# Docker
docker update --memory 1g --cpus 2 keycloak-mcp-server
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "1000m"
If you are still experiencing issues:
# OpenShift oc logs deployment/keycloak-mcp-server –tail 100
# Development mode # Logs appear in terminal
2. **Enable debug logging:**
```bash
# Add to environment
export QUARKUS_LOG_LEVEL=DEBUG
Once you have the MCP server running:
**Happy Keycloak management with MCP! **