Skip to main content

Keycloak Agent

MCP Server | Agent

PyPI - Version MCP Server License GitHub

Keycloak Identity and Access Management MCP Server + Agent for the scion-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

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 --tools or --toolsets (or their disabled counterparts --disabled-tools and --disabled-toolsets) during startup.
  • Environment Variables: Define standard environment variables:
    • MCP_ENABLED_TOOLS / MCP_DISABLED_TOOLS
    • MCP_ENABLED_TAGS / MCP_DISABLED_TAGS
  • HTTP SSE Request Headers: Pass custom headers during transport initialization:
    • x-mcp-enabled-tools / x-mcp-disabled-tools
    • x-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 (scion-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>Scion 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 use keycloak-agent[mcp] to add FastMCP / FastAPI through scion-sdk; the required Scion SDK core still carries epistemic-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_HOSTS in AgentConfig.

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 scion-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 scion-sdk set — do not edit.

Available MCP Tools

Typed tools (one per operation)

MCP Tool family Description
keycloak_list_realms, keycloak_get_realm, keycloak_create_realm, keycloak_delete_realm Realms.
keycloak_list_users, keycloak_get_user, keycloak_create_user, keycloak_reset_password, keycloak_delete_user Users.
keycloak_list_clients, keycloak_get_client, keycloak_find_client_by_client_id, keycloak_create_client, keycloak_get_client_secret, keycloak_regenerate_client_secret, keycloak_regenerate_client_secret_by_client_id, keycloak_delete_client OIDC clients.
keycloak_agent_groups_*, keycloak_agent_roles_*, keycloak_agent_organizations_* Groups, roles and organizations.
keycloak_agent_idps_*, keycloak_agent_authentication_*, keycloak_agent_components_*, keycloak_agent_attack_detection_* Identity providers, authentication flows, components, brute-force protection.
keycloak_agent_info_list_methods, _search_methods, _method_details Admin API catalog.
keycloak_ingest_realms, _users, _clients, _groups Mirror records into the knowledge graph.

Destructive tools take confirm=true.

Metadata

Release files for keycloak-agent 2.3.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keycloak-agent 2.3.11
File Size Uploaded Provenance Actions
keycloak_agent-2.3.11.tar.gz 49.5 kB Without provenance Details for keycloak_agent-2.3.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keycloak-agent 2.3.11
File Interpreter ABI Platform Actions
keycloak_agent-2.3.11-py3-none-any.whl Python 3 none any Details for keycloak_agent-2.3.11-py3-none-any.whl

Total release size: 113.8 kB

Release files / keycloak_agent-2.3.11.tar.gz

Download URL keycloak_agent-2.3.11.tar.gz
Size 49.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3971235d7e6d5f8299b0de86b81946e324fcea2a23b07c1be99d514fd41844e6
BLAKE2b-256 checksum
How to use checksums
7ee8c47b7747d7147a0f7e98531c92f3f60eca4ad0d4da2b9ca5d264b410eac1
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.11-py3-none-any.whl

Download URL keycloak_agent-2.3.11-py3-none-any.whl
Size 64.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5efaa16e09fabdc5020a767b27bc253bebc3d3950200c2ce278a2675585548eb
BLAKE2b-256 checksum
How to use checksums
febe47f190ed754fe330b0c43253824f29c5eb8c9d65cbb7ca83802399e71856
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.11

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page