Keycloak Agent
MCP Server | Agent
Keycloak Identity and Access Management MCP Server + Agent for the agent-connector-sdk ecosystem. Built with the standardized dynamic-facade architecture, custom API routing, and FastMCP tool registration.
Documentation — Installation, deployment, usage across the API, CLI, and MCP interfaces, and guidance for provisioning the Keycloak platform are maintained in the official documentation.
Table of Contents
- Overview
- Features
- Installation
- Usage
- Environment Variables
- MCP Tools
- Architecture
- Deployment
- Contributing
- License
Overview
Keycloak MCP provides a high-performance, model-optimized interface to Keycloak capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.
Features
- Dynamic Facade Orchestration: Integrates multi-inheritance clients cleanly under a single facade.
- Battle-Tested Resilience: Out-of-the-box credential authentication, connection polling, and request retry strategies.
- FastMCP Declarative Tools: Fast, native schema registration with full inline validation.
- Complete Test Intent Diversity: Deep, automated unit, integration, and mock tests ensuring high code coverage.
⚙️ Dynamic Tool Selection & Visibility
This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows the operator to restrict the set of exposed tools to prevent blowing up the LLM's context window.
The operator can configure tool filtering via multiple input channels:
- CLI Arguments: Pass
--toolsor--toolsets(or their disabled counterparts--disabled-toolsand--disabled-toolsets) during startup. - Environment Variables: Define standard environment variables:
MCP_ENABLED_TOOLS/MCP_DISABLED_TOOLSMCP_ENABLED_TAGS/MCP_DISABLED_TAGS
- HTTP SSE Request Headers: Pass custom headers during transport initialization:
x-mcp-enabled-tools/x-mcp-disabled-toolsx-mcp-enabled-tags/x-mcp-disabled-tags
- HTTP SSE Request Query Parameters: Append query parameters directly to the operator's transport connection URL:
?tools=tool1,tool2?tags=tag1
When query strings or parameters are provided, an LLM-free Knowledge Graph resolution layer (using DynamicToolOrchestrator) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.
Installation
Pick the extra that matches what the operator want to run:
| Extra | Installs | Use when |
|---|---|---|
keycloak-agent[mcp] |
Connector-focused MCP server (agent-connector-sdk — FastMCP/FastAPI + epistemic-graph[full]) |
The operator only run the MCP server (smallest install / image) |
keycloak-agent[all] |
Everything (mcp + agent + logfire) |
Development / both surfaces |
# Connector-focused MCP server (includes the shared graph engine)
uv pip install "keycloak-agent[mcp]"
# Agent runtime (adds model orchestration to the shared graph engine)
# Everything (development)
uv pip install "keycloak-agent[all]" # or: python -m pip install "keycloak-agent[all]"
Container images (:mcp)
One multi-stage docker/Dockerfile builds the MCP-only image (--target mcp):
| Image tag | Build target | Contents | Entrypoint |
|---|
</code></pre>
<h3 id="user-content-knowledge-graph-database-epistemic-graph">Knowledge-graph database (<code>epistemic-graph</code>)<a href="#user-content-knowledge-graph-database-epistemic-graph" aria-label="Link to heading 'Knowledge-graph database (epistemic-graph)'" data-heading-content="Knowledge-graph database (epistemic-graph)" class="anchor"></a></h3>
<p>Agent Connector SDK core dependency (<code>epistemic-graph[full]</code>). The <code>[mcp]</code> extra keeps
deployments can use the bundled engine. For production or shared state, run
<strong>epistemic-graph as a dedicated database service</strong> and configure the runtime to use it.
Deployment recipes (single-node + Raft HA), connection configuration, and architecture
diagrams are documented in the
<a href="https://knuckles-team.github.io/epistemic-graph/deployment/">epistemic-graph deployment guide</a>.</p>
<hr />
<h2 id="user-content-usage">Usage<a href="#user-content-usage" aria-label="Link to heading 'Usage'" data-heading-content="Usage" class="anchor"></a></h2>
<p>The operator can start the FastMCP server in stdio mode via Python module execution:</p>
<pre><code class="language-python">import asyncio
from keycloak_agent.mcp_server import get_mcp_instance
async def main():
mcp = get_mcp_instance()
# Execute stdio loop or launch server
print("MCP Server ready.")
if __name__ == "__main__":
asyncio.run(main())
For direct shell start, ran:
python -m keycloak_agent.mcp_server
MCP Configuration Examples
Install the connector-focused
[mcp]extra. Examples usekeycloak-agent[mcp]to add FastMCP / FastAPI throughagent-connector-sdk; the required Agent Connector SDK core still carriesepistemic-graph[full]. The[agent-runtime]extra additionally enables model orchestration.
stdio Transport (local IDEs — Cursor, Claude Desktop, VS Code)
{
"mcpServers": {
"keycloak-mcp": {
"command": "uvx",
"args": [
"--from",
"keycloak-agent[mcp]",
"keycloak-mcp"
],
"env": {
"ATTACK_DETECTIONTOOL": "True",
"AUTHENTICATIONTOOL": "True",
"CLIENTSTOOL": "True",
"COMPONENTSTOOL": "True",
"GROUPSTOOL": "True",
"IDPSTOOL": "True",
"INFOTOOL": "True",
"INGESTTOOL": "True",
"KEYCLOAK_REALM": "master",
"ORGANIZATIONSTOOL": "True",
"REALMSTOOL": "True",
"ROLESTOOL": "True",
"USERSTOOL": "True"
}
}
}
}
Runtime references require an alias-aware launcher such as Arbora. Other launchers must omit those entries and inject the resolved values through their own runtime secret boundary.
Streamable-HTTP Transport (networked / production)
{
"mcpServers": {
"keycloak-mcp": {
"command": "uvx",
"args": [
"--from",
"keycloak-agent[mcp]",
"keycloak-mcp",
"--transport",
"streamable-http",
"--port",
"8000"
],
"env": {
"TRANSPORT": "streamable-http",
"HOST": "127.0.0.1",
"PORT": "8000",
"ATTACK_DETECTIONTOOL": "True",
"AUTHENTICATIONTOOL": "True",
"CLIENTSTOOL": "True",
"COMPONENTSTOOL": "True",
"GROUPSTOOL": "True",
"IDPSTOOL": "True",
"INFOTOOL": "True",
"INGESTTOOL": "True",
"KEYCLOAK_REALM": "master",
"ORGANIZATIONSTOOL": "True",
"REALMSTOOL": "True",
"ROLESTOOL": "True",
"USERSTOOL": "True"
}
}
}
}
Alternatively, connect to a pre-deployed Streamable-HTTP instance by url:
{
"mcpServers": {
"keycloak-mcp": {
"url": "http://localhost:8000/keycloak-mcp/mcp"
}
}
}
Run a reviewed container image as a least-privilege stdio child (no listener or published port):
docker run -i --rm \
--read-only \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--pids-limit=256 \
--tmpfs /tmp:rw,noexec,nosuid,nodev,size=64m \
-e TRANSPORT=stdio \
-e ATTACK_DETECTIONTOOL=True \
-e AUTHENTICATIONTOOL=True \
-e CLIENTSTOOL=True \
-e COMPONENTSTOOL=True \
-e GROUPSTOOL=True \
-e IDPSTOOL=True \
-e INFOTOOL=True \
-e INGESTTOOL=True \
-e KEYCLOAK_REALM=master \
-e ORGANIZATIONSTOOL=True \
-e REALMSTOOL=True \
-e ROLESTOOL=True \
-e USERSTOOL=True \
registry.example.invalid/keycloak-agent@sha256:<digest> keycloak-mcp
For containerized network HTTP, supply an authenticated TLS ingress (or
direct server TLS), exact MCP_ALLOWED_HOSTS, and an exact trusted-proxy
CIDR policy through the operator-owned deployment profile. The generator
does not emit an unauthenticated non-loopback listener.
Auto-generated from the code-read env surface (package vars) — do not edit.
Additional Deployment Options
keycloak-agent can run as a local stdio process or container, or behind a remote
network boundary. The
Deployment guide carries
the detailed transport contract.
- Local container — launch a reviewed immutable image as a least-privilege stdio child with no listener or published port.
- Remote URL — connect through an operator-supplied authenticated HTTPS
ingress. Keep its URL, outbound identity references, trust profile, and exact
MCP_ALLOWED_HOSTSinAgentConfig.
Contributing
Please audit all code changes against the repository's contribution and review requirements, and run:
pre-commit run --all-files
Documentation
The complete documentation is published as the official documentation site and is the recommended reference for installation, deployment, and day-to-day operation.
| Page | Contents |
|---|---|
| Installation | pip, source, extras, prebuilt Docker image |
| Deployment | run the MCP server and agent, Compose, Caddy + Technitium, env config |
| Usage | the MCP tools, the Api client, the CLI |
| Backing Platform | deploy Keycloak with Docker |
| Overview | the dynamic facade and tool surface |
| Concepts | concept registry (CONCEPT:KEY-*) |
AGENTS.md is the canonical contributor/agent guidance.
License
This project is licensed under the MIT License. See the LICENSE file for complete details.
Governed capability contract
This package ships a compact canonical skill surface with specialist procedures
kept as referenced workflows. The current MCP tools, skill metadata,
connector_manifest.yml, ontology, mappings, shapes, fixtures, migrations,
tool-schema fingerprints, and certification metadata form one versioned
capability contract. Validate them together; do not rely on stale tool names or
historical per-task skill wrappers.
Runtime endpoints, credentials, certificate trust, tenant identity, retention, and observability policy are deployment inputs and are never packaged values. See Configuration, trust, and privacy before enabling a network transport, connector ingestion, Arbora delegation, or trace export.
Environment Variables
Package environment variables
| Variable | Example | Description |
|---|---|---|
KEYCLOAK_URL |
— | Keycloak base Admin URL (required) |
KEYCLOAK_REALM |
master |
Keycloak realm name |
TLS_PROFILE |
private-pki |
TLS verification is mandatory. Select a named runtime profile from AgentConfig. |
TLS_PROFILES_REF |
secret://runtime/tls-profiles |
|
KEYCLOAK_AGENT_USERNAME |
— | Admin account username |
KEYCLOAK_AGENT_PASSWORD |
secret-injected | Admin account password |
KEYCLOAK_TOKEN |
secret-injected | Static bearer token |
KEYCLOAK_CLIENT_ID |
— | A service-account client whose bearer is minted from Keycloak's token endpoint and auto-refreshed. Set both to use client-credentials instead of basic auth. |
KEYCLOAK_CLIENT_SECRET |
secret-injected | |
KEYCLOAK_CLIENT_AUDIENCE |
— | Token audience the minted bearer is scoped to. Defaults to KEYCLOAK_CLIENT_ID (self-audience) when unset. |
ATTACK_DETECTIONTOOL |
True |
These names match the authoritative "Toggle Env Var" column in the README MCP tools table (condensed action-routed surface). |
AUTHENTICATIONTOOL |
True |
|
CLIENTSTOOL |
True |
|
COMPONENTSTOOL |
True |
|
GROUPSTOOL |
True |
|
IDPSTOOL |
True |
|
INFOTOOL |
True |
|
INGESTTOOL |
True |
|
ORGANIZATIONSTOOL |
True |
|
REALMSTOOL |
True |
|
ROLESTOOL |
True |
|
USERSTOOL |
True |
|
KEYCLOAK_AGENT_TLS_PROFILE |
— | |
KEYCLOAK_AGENT_TLS_PROFILE_REF |
— |
Inherited agent-connector-sdk variables (apply to every connector)
| Variable | Example | Description |
|---|---|---|
TRANSPORT |
stdio |
MCP transport: stdio | streamable-http | sse |
HOST |
127.0.0.1 |
Loopback bind host (set an authenticated ingress explicitly) |
PORT |
8000 |
Bind port (HTTP transports) |
MCP_ENABLED_TOOLS |
— | Comma-separated tool allow-list |
MCP_DISABLED_TOOLS |
— | Comma-separated tool deny-list |
MCP_ENABLED_TAGS |
— | Comma-separated tag allow-list |
MCP_DISABLED_TAGS |
— | Comma-separated tag deny-list |
EUNOMIA_TYPE |
none |
Authorization mode: none | embedded | remote |
EUNOMIA_POLICY_FILE |
mcp_policies.json |
Embedded Eunomia policy file |
EUNOMIA_REMOTE_URL |
— | Remote Eunomia authorization server URL |
ENABLE_OTEL |
False |
Enable OpenTelemetry export |
OTEL_EXPORTER_OTLP_ENDPOINT |
— | OTLP collector endpoint |
MCP_CLIENT_AUTH |
— | Outbound MCP child auth: oidc-client-credentials | basic | none |
OIDC_CLIENT_ID |
— | OIDC client id (service-account auth) |
OIDC_CLIENT_SECRET_REF |
secret://identity/oidc-client-secret |
Runtime secret reference for the OIDC service account |
MCP_BASIC_AUTH_USERNAME |
— | HTTP Basic username (MCP_CLIENT_AUTH=basic) |
MCP_BASIC_AUTH_PASSWORD_REF |
secret://identity/mcp-basic-password |
Runtime secret reference for HTTP Basic auth (MCP_CLIENT_AUTH=basic) |
DEBUG |
False |
Verbose logging |
PYTHONUNBUFFERED |
1 |
Unbuffered stdout (recommended in containers) |
MCP_URL |
http://localhost:8000/mcp |
URL of the MCP server the agent connects to |
PROVIDER |
— | Operator-configured LLM provider for the agent |
MODEL_ID |
— | Operator-configured model id for the agent |
ENABLE_WEB_UI |
True |
Serve the AG-UI web interface |
24 package + 23 inherited variable(s). Auto-generated from .env.example + the shared agent-connector-sdk set — do not edit.
Available MCP Tools
Intent tools
| MCP Tool | Kind | Description |
|---|---|---|
keycloak_agent_attack_detection |
intent | Manage Keycloak Agent brute force and attack detection operations. |
keycloak_agent_authentication |
intent | Manage Keycloak Agent authentication and authenticator flow operations. |
keycloak_agent_clients |
intent | Manage Keycloak Agent clients operations. |
keycloak_agent_components |
intent | Manage Keycloak Agent components operations. |
keycloak_agent_groups |
intent | Manage Keycloak Agent groups operations. |
keycloak_agent_idps |
intent | Manage Keycloak Agent identity providers operations. |
keycloak_agent_info |
intent | Inspect and discover available Keycloak API methods, paths, and signatures at runtime. |
keycloak_agent_organizations |
intent | Manage Keycloak Agent organizations operations. |
keycloak_agent_realms |
intent | Manage Keycloak Agent realms operations. |
keycloak_agent_roles |
intent | Manage Keycloak Agent roles and scope mappings. |
keycloak_agent_users |
intent | Manage Keycloak Agent users operations (Users, Role Mappings, Client Role Mappings). |
keycloak_ingest_clients |
intent | List clients in a realm and ingest them as :Client nodes (+ :inRealm). |
keycloak_ingest_groups |
intent | List groups in a realm and ingest them as :Group nodes (+ :hasSubGroup). |
keycloak_ingest_realms |
intent | List all realms and ingest them into epistemic-graph as :Realm nodes. |
keycloak_ingest_users |
intent | List users in a realm and ingest them as :User nodes (+ :inRealm links). |
15 intent tool(s) · 0 operation(s). Call an operation as act(action='<operation>', params={...}) (ask for reads); find(action='describe', params={'action': '<operation>'}) returns its arguments. An operation is enabled unless its <DOMAIN>TOOL toggle is set false. Auto-generated — do not edit.
Metadata
Release files for keycloak-agent 2.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| keycloak_agent-2.3.4.tar.gz | 38.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keycloak_agent-2.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 88.1 kB
Release files / keycloak_agent-2.3.4.tar.gz
| Download URL | keycloak_agent-2.3.4.tar.gz |
|---|---|
| Size | 38.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
daf256156121e2e0211009c43f4410bba254dcf68b3fbe1609b155d5e22010d8
|
|
BLAKE2b-256 checksum How to use checksums |
fe0033e0a93e6c66f0e72cb8d37e0feaebff6070a0aae4f1c08f19e1e1925c70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / keycloak_agent-2.3.4-py3-none-any.whl
| Download URL | keycloak_agent-2.3.4-py3-none-any.whl |
|---|---|
| Size | 49.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be84f6d3d6611b9a1f202d737a719e97b55a500d8956e520a347a4c3d5223752
|
|
BLAKE2b-256 checksum How to use checksums |
a8a7240c01b45a748e280eb27605bc261fdbf4161512110b68f7483a432d85d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for keycloak-agent 2.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.