Keycloak MCP Server
About
A complete Model Context Protocol (MCP) server for Keycloak 26.x
Details
- Author
- paoloamato2
- Categories
- Other, Security
Jump to
Option 3: Install from source (For development)
git clone https://github.com/paoloamato2/keycloak-mcp-server.git cd keycloak-mcp-server uv pip install -e .
Set environment variables (or create a.envfile based on.env.example):
# Required export KEYCLOAK_URL=http://localhost:8080 # Authentication - Option A: Password flow export KEYCLOAK_ADMIN_USERNAME=admin export KEYCLOAK_ADMIN_PASSWORD=admin # Authentication - Option B: Client credentials flow export KEYCLOAK_CLIENT_ID=my-client export KEYCLOAK_CLIENT_SECRET=my-secret # Optional export KEYCLOAK_ADMIN_REALM=master # default: master export KEYCLOAK_VERIFY_SSL=true # default: true
Add to your Claude Code MCP configuration (~/.claude/claude_desktop_config.jsonor project-level):
{ "mcpServers": { "keycloak": { "command": "python", "args": ](https://www.keycloak.org/docs-api/latest/rest-api/index.html)["-m", "keycloak_mcp_server"], "env": { "KEYCLOAK_URL": "http://localhost:8080", "KEYCLOAK_ADMIN_USERNAME": "admin", "KEYCLOAK_ADMIN_PASSWORD": "admin" } } } }
{ "mcpServers": { "keycloak": { "command": "uv", "args": ["run", "--directory", "/path/to/keycloak-mcp-server", "python", "-m", "keycloak_mcp_server"], "env": { "KEYCLOAK_URL": "http://localhost:8080", "KEYCLOAK_ADMIN_USERNAME": "admin", "KEYCLOAK_ADMIN_PASSWORD": "admin" } } } }
python -m keycloak_mcp_server --transport sse --port 8080
Then configure in your GitHub Copilot MCP settings (VS Codesettings.json):
{ "github.copilot.chat.mcpServers": { "keycloak": { "type": "sse", "url": "http://localhost:8080/sse" } } }
# stdio mode (default) python -m keycloak_mcp_server # SSE mode python -m keycloak_mcp_server --transport sse --host 0.0.0.0 --port 8080 # Using the entry point keycloak-mcp-server --transport sse --port 8080
A comprehensiveModel Context Protocol (MCP)server that exposes theKeycloak Admin REST APIas typed MCP tools. 299 tools covering all API categories.
- Complete API coverage: All 299 Keycloak Admin REST API endpoints
- Dual transport: stdio (Claude Code) and SSE (GitHub Copilot, other MCP clients)
- Auto-authentication: Supports both password and client credentials flows with automatic token refresh
- Zero configuration tools: Each tool is self-describing with full input schemas
(Add a GIF or screenshot here demonstrating 3 real prompts and their executed tools!)
Option 1: Run directly withuvx(Recommended)
You can run the server directly without manual installation using astral'suv:
(When usinguvx, you can pass environment variables inline or keep them in your MCP config file.)
If you prefer a global or virtual environment installation:
pip install git+https://github.com/paoloamato2/keycloak-mcp-server.git
Option 3: Install from source (For development)
git clone https://github.com/paoloamato2/keycloak-mcp-server.git cd keycloak-mcp-server uv pip install -e .
Set environment variables (or create a.envfile based on.env.example):
# Required export KEYCLOAK_URL=http://localhost:8080 # Authentication - Option A: Password flow export KEYCLOAK_ADMIN_USERNAME=admin export KEYCLOAK_ADMIN_PASSWORD=admin # Authentication - Option B: Client credentials flow export KEYCLOAK_CLIENT_ID=my-client export KEYCLOAK_CLIENT_SECRET=my-secret # Optional export KEYCLOAK_ADMIN_REALM=master # default: master export KEYCLOAK_VERIFY_SSL=true # default: true
Add to your Claude Code MCP configuration (~/.claude/claude_desktop_config.jsonor project-level):
{ "mcpServers": { "keycloak": { "command": "python", "args": ["-m", "keycloak_mcp_server"], "env": { "KEYCLOAK_URL": "http://localhost:8080", "KEYCLOAK_ADMIN_USERNAME": "admin", "KEYCLOAK_ADMIN_PASSWORD": "admin" } } } }
{ "mcpServers": { "keycloak": { "command": "uv", "args": ["run", "--directory", "/path/to/keycloak-mcp-server", "python", "-m", "keycloak_mcp_server"], "env": { "KEYCLOAK_URL": "http://localhost:8080", "KEYCLOAK_ADMIN_USERNAME": "admin", "KEYCLOAK_ADMIN_PASSWORD": "admin" } } } }
python -m keycloak_mcp_server --transport sse --port 8080
Then configure in your GitHub Copilot MCP settings (VS Codesettings.json):
{ "github.copilot.chat.mcpServers": { "keycloak": { "type": "sse", "url": "http://localhost:8080/sse" } } }
# stdio mode (default) python -m keycloak_mcp_server # SSE mode python -m keycloak_mcp_server --transport sse --host 0.0.0.0 --port 8080 # Using the entry point keycloak-mcp-server --transport sse --port 8080
Security & Production Recommendations
⚠️SECURITY WARNING:This MCP Server registersallKeycloak Admin REST API endpoints (299 tools), including sensitive write operations (like creating/deleting users, resetting passwords, and managing realms).Do not use your master realm super-admin credentials in a production environment.
When attaching this MCP server to your AI Assistants, please strictly follow thePrinciple of Least Privilege:
-
Use Service Accounts (Client Credentials Flow): Avoid using the Password flow (KEYCLOAK_ADMIN_USERNAME/KEYCLOAK_ADMIN_PASSWORD). Instead, create a dedicated Keycloak Client with Service Accounts Enabled, and use theKEYCLOAK_CLIENT_IDandKEYCLOAK_CLIENT_SECRET.
Limit Target Realms: Do not attach the server to themasterrealm unless specifically necessary. PointKEYCLOAK_ADMIN_REALMto the exact realm your AI assistant should manage.
Grant Only Required Roles: Only assign the minimum necessary roles to your MCP Service Account.
- If your LLM only needs toreaddata: Assign onlyview-users,view-clients, orview-realm.
- If your LLM needs tomanageusers: Assign onlymanage-users.
- Neverassignadminorrealm-adminroles to the AI unless you are fully aware of the risks.
Always Verify SSL: KeepKEYCLOAK_VERIFY_SSL=trueenabled in production to prevent Man-in-the-Middle (MITM) attacks. Setting it tofalseis only acceptable for local development.
Once connected, you can use natural language to interact with Keycloak:
- "List all realms"→ callslist_realms
- "Create a user called john in the master realm"→ callscreate_user
- "Show me all clients in the production realm"→ callslist_clients
- "What roles does user X have?"→ callsget_user_role_mappings
- "Add the admin role to the developers group"→ callsadd_group_realm_role_mappings
src/keycloak_mcp_server/ ├── __init__.py # Package entry point ├── __main__.py # CLI entry point ├── config.py # Environment-based configuration ├── client.py # Async HTTP client with auto-auth ├── server.py # MCP server setup and tool registration └── endpoints/ # Endpoint definitions by category ├── __init__.py # Base classes (EndpointDef, Param) ├── attack_detection.py ├── authentication.py ├── certificates.py ├── client_initial_access.py ├── client_registration_policy.py ├── client_role_mappings.py ├── client_scopes.py ├── clients.py ├── component.py ├── groups.py ├── identity_providers.py ├── key.py ├── organizations.py ├── protocol_mappers.py ├── realms.py ├── roles.py ├── roles_by_id.py ├── scope_mappings.py └── users.py
ALTER - identity infrastructure for the AI economy
Auth0, but for agents. Identity and authentication service for AI agents.
AgentTrust is a pure MCP-only reputation and trust scoring server for AI agents.
https://github.com/SPAZIO-GENESI/attest-mcp
Drive a personal UK Tesco grocery account: search, basket, delivery slots, orders, and on-pack nutrition. Filter and rank products by macros + micros. Catalogue and nutrition tools need no auth.
Latvian property portal MCP: search rentals, sales & nightly stays, market stats; owner tools via OAuth. Remote server at https://bezbaseina.lv/mcp
Live space data for AI agents — rocket launches, ISS passes, launch news. Free, no auth.
It connects Agents to data wallet with DID and verifiable credentials
An observatory that probes every MCP server in the official MCP registry and reports which ones actually work: live, auth-gated, dead, or erroring.
AI-native property MCP for North Cyprus (KKTC) — 9 tools, live data from evlek.app, hosted, no auth required.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



