Keycloak MCP Server for Agentic Data Management
Optimize agentic data workflows with the Keycloak MCP server to efficiently search and manage Keycloak data.
npx -y @idoyudha/mcp-keycloakOverview
The Keycloak MCP Server is a lightweight service that exposes Keycloak data as a Model Context Protocol (MCP) provider. It indexes and surfaces Keycloak objects—users, clients, roles, groups, and realm metadata—so downstream agents and LLM-driven workflows can efficiently search and retrieve contextual identity information. By translating Keycloak state into a searchable, structured context endpoint, the server enables automated tooling to make real-time decisions that depend on identity and access data.
This server is particularly useful for teams integrating LLMs or agentic systems with identity management: instead of embedding Keycloak queries directly into agents, you point agents at the MCP endpoint. Agents can request concise, relevant slices of Keycloak data (for example, user attributes, client scope details, or role hierarchies) without direct Keycloak integration, simplifying security boundaries and caching strategies.
Features
- Exposes Keycloak entities (users, clients, roles, groups, realms) via an MCP-compatible API
- Full-text and structured search across Keycloak objects
- Incremental or scheduled indexing from a Keycloak instance
- Authentication to Keycloak using admin credentials or tokens
- Lightweight HTTP server easily containerizable
- Simple JSON-based configuration for realms and index rules
- Health and readiness endpoints for orchestration
Installation / Configuration
Prerequisites:
- Running Keycloak instance (vX or later)
- Docker (recommended) or Node.js runtime (if building locally)
Clone the repo and run with Docker:
# Build and run with Docker (example)
Or run from source (Node.js example):
# Install dependencies
# Run with env vars
KEYCLOAK_URL="https://keycloak.example.com" \
KEYCLOAK_ADMIN_USER="admin" \
KEYCLOAK_ADMIN_PASSWORD="password" \
Common environment variables
| Variable | Purpose |
|---|---|
| KEYCLOAK_URL | Base URL of your Keycloak instance |
| KEYCLOAK_ADMIN_USER | Admin username for Keycloak API access |
| KEYCLOAK_ADMIN_PASSWORD | Admin password |
| MCP_PORT | Port the MCP server listens on (default: 8080) |
| MCP_INDEX_INTERVAL_SECONDS | Interval for periodic re-indexing (optional) |
| MCP_REALMS | Comma-separated list of realms to index (defaults to all) |
Example JSON configuration (mcp-config.json):
Place the file in the container or pass its path via MCP_CONFIG_PATH env var.
Available Resources
- GitHub repository: https://github.com/idoyudha/mcp-keycloak — source, issues, and examples
- Health endpoint: GET /health — basic service liveness
- Readiness endpoint: GET /ready — indexing readiness and Keycloak connectivity
- MCP manifest (if implemented): GET /.well-known/mcp — discovery document for agents
- Main MCP search endpoint: POST /mcp/search — accepts MCP search payloads and returns contextual results
API quick reference
- GET /health — 200 OK when service is up
- GET /ready — 200 when the service has a recent index and can serve requests
- POST /mcp/search — body: MCP search query (filters, text query); returns array of context snippets
- POST /mcp/index — trigger a manual re-index (requires admin access)
Use Cases
- Agentic user-support bot: A conversational agent needs to describe a user’s assigned roles, attributes, and client memberships to help troubleshoot access issues. The bot issues a focused MCP search for a username and receives a concise context payload instead of crawling Keycloak APIs directly.
- Automated access remediation: A workflow monitors anomalous events and needs to remove a compromised client. It queries the MCP server for the client’s details, evaluates policies, then takes action using Keycloak admin APIs—keeping policy evaluation decoupled from Keycloak logic.
- Compliance reporting and audit: Periodic agents generate reports that require a snapshot of roles and group memberships across realms. The MCP server delivers structured search results suitable for aggregation and templated report generation.
- Onboarding assistant: An onboarding agent queries relevant client and role templates for a new service account, then presents curated configuration options to an operator or auto-applies them.
Example: Search request and response
Sample search request (curl):
Sample response (JSON):
Notes
- The MCP server is intended to be used as a read-only, searchable context layer. Administrative actions on Keycloak should still be performed using Keycloak’s APIs with appropriate authentication.
- Tune indexing frequency and fields to balance freshness with load on your Keycloak instance.
For implementation details, examples, and contribution guidelines, see the project repository: https://github.com/idoyudha/mcp-keycloak.