Skip to main content

Keycloak Identity MCP Server and Agent for Agentic AI!

Project description

Keycloak Agent

MCP Server | Agent

PyPI - Version MCP Server License GitHub

Keycloak Identity and Access Management MCP Server + Agent for the agent-utilities 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 you to restrict the set of exposed tools in order to prevent blowing up the LLM's context window.

You 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 your transport connection URL:
    • ?tools=tool1,tool2
    • ?tags=tag1

When query strings or parameters are supplied, 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 you want to run:

Extra Installs Use when
keycloak-agent[mcp] Slim MCP server only (agent-utilities[mcp] — FastMCP/FastAPI) You only run the MCP server (smallest install / image)
keycloak-agent[agent] Full agent runtime (agent-utilities[agent,logfire] — Pydantic AI + the epistemic-graph engine) You run the integrated agent
keycloak-agent[all] Everything (mcp + agent + logfire) Development / both surfaces
# MCP server only (recommended for tool hosting — slim deps)
uv pip install "keycloak-agent[mcp]"

# Full agent runtime (Pydantic AI + epistemic-graph engine)
uv pip install "keycloak-agent[agent]"

# Everything (development)
uv pip install "keycloak-agent[all]"      # or: python -m pip install "keycloak-agent[all]"

Container images (:mcp vs :agent)

One multi-stage docker/Dockerfile builds two right-sized images, selected by --target:

Image tag Build target Contents Entrypoint
knucklessg1/keycloak-agent:mcp --target mcp keycloak-agent[mcp]slim, no engine/pydantic-ai/dspy/llama-index/tree-sitter keycloak-mcp
knucklessg1/keycloak-agent:latest --target agent (default) keycloak-agent[agent]full agent runtime + epistemic-graph engine keycloak-agent
docker build --target mcp   -t knucklessg1/keycloak-agent:mcp    docker/   # slim MCP server
docker build --target agent -t knucklessg1/keycloak-agent:latest docker/   # full agent

Knowledge-graph database (epistemic-graph)

The full agent ([agent] / :latest) embeds the epistemic-graph engine (pulled in transitively via agent-utilities[agent]). For production — or to share one knowledge graph across multiple agents — run epistemic-graph as its own database container and point the agent at it instead of embedding it. Deployment recipes (single-node + Raft HA), connection config, and the full database architecture (with diagrams) are documented in the epistemic-graph deployment guide. The slim [mcp] server does not require the database.


Usage

You can launch the FastMCP server in stdio mode via Python module execution:

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 launch, execute:

python -m keycloak_agent.mcp_server

MCP Configuration Examples

Install the slim [mcp] extra. All examples install keycloak-agent[mcp] — the MCP-server extra that pulls only the FastMCP / FastAPI tooling (agent-utilities[mcp]). It deliberately excludes the heavy agent runtime (pydantic-ai, the epistemic-graph engine, dspy, llama-index), so uvx / container installs are far smaller. Use the full [agent] extra only when you need the integrated Pydantic AI agent.

stdio Transport (local IDEs — Cursor, Claude Desktop, VS Code)

{
  "mcpServers": {
    "keycloak-mcp": {
      "command": "uvx",
      "args": [
        "--from",
        "keycloak-agent[mcp]",
        "keycloak-mcp"
      ],
      "env": {
        "MCP_TOOL_MODE": "condensed",
        "ATTACK_DETECTIONTOOL": "True",
        "AUTHENTICATIONTOOL": "True",
        "CLIENTSTOOL": "True",
        "COMPONENTSTOOL": "True",
        "GROUPSTOOL": "True",
        "IDPSTOOL": "True",
        "INFOTOOL": "True",
        "KEYCLOAK_AGENT_BASE_URL": "http://localhost:8080",
        "KEYCLOAK_AGENT_PASSWORD": "admin_secure_password",
        "KEYCLOAK_AGENT_USERNAME": "admin",
        "KEYCLOAK_CLIENT_ID": "",
        "KEYCLOAK_CLIENT_SECRET": "",
        "KEYCLOAK_REALM": "master",
        "KEYCLOAK_TOKEN": "",
        "KEYCLOAK_URL": "http://localhost:8080",
        "ORGANIZATIONSTOOL": "True",
        "REALMSTOOL": "True",
        "ROLESTOOL": "True",
        "USERSTOOL": "True"
      }
    }
  }
}

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": "0.0.0.0",
        "PORT": "8000",
        "MCP_TOOL_MODE": "condensed",
        "ATTACK_DETECTIONTOOL": "True",
        "AUTHENTICATIONTOOL": "True",
        "CLIENTSTOOL": "True",
        "COMPONENTSTOOL": "True",
        "GROUPSTOOL": "True",
        "IDPSTOOL": "True",
        "INFOTOOL": "True",
        "KEYCLOAK_AGENT_BASE_URL": "http://localhost:8080",
        "KEYCLOAK_AGENT_PASSWORD": "admin_secure_password",
        "KEYCLOAK_AGENT_USERNAME": "admin",
        "KEYCLOAK_CLIENT_ID": "",
        "KEYCLOAK_CLIENT_SECRET": "",
        "KEYCLOAK_REALM": "master",
        "KEYCLOAK_TOKEN": "",
        "KEYCLOAK_URL": "http://localhost:8080",
        "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"
    }
  }
}

Deploying the Streamable-HTTP server via Docker:

docker run -d \
  --name keycloak-mcp-mcp \
  -p 8000:8000 \
  -e TRANSPORT=streamable-http \
  -e HOST=0.0.0.0 \
  -e PORT=8000 \
  -e MCP_TOOL_MODE=condensed \
  -e ATTACK_DETECTIONTOOL=True \
  -e AUTHENTICATIONTOOL=True \
  -e CLIENTSTOOL=True \
  -e COMPONENTSTOOL=True \
  -e GROUPSTOOL=True \
  -e IDPSTOOL=True \
  -e INFOTOOL=True \
  -e KEYCLOAK_AGENT_BASE_URL=http://localhost:8080 \
  -e KEYCLOAK_AGENT_PASSWORD=admin_secure_password \
  -e KEYCLOAK_AGENT_USERNAME=admin \
  -e KEYCLOAK_CLIENT_ID="" \
  -e KEYCLOAK_CLIENT_SECRET="" \
  -e KEYCLOAK_REALM=master \
  -e KEYCLOAK_TOKEN="" \
  -e KEYCLOAK_URL=http://localhost:8080 \
  -e ORGANIZATIONSTOOL=True \
  -e REALMSTOOL=True \
  -e ROLESTOOL=True \
  -e USERSTOOL=True \
  knucklessg1/keycloak-agent:mcp

Auto-generated from the code-read env surface (MCP_TOOL_MODE + package vars) — do not edit.

Additional Deployment Options

keycloak-agent can also run as a local container (Docker / Podman / uv) or be consumed from a remote deployment. The Deployment guide has full, copy-paste mcp_config.json for all four transports — stdio, streamable-http, local container / uv, and remote URL:

  • Local container / uv — launch the server from mcp_config.json via uvx, docker run, or podman run, or point at a local streamable-http container by url.
  • Remote URL — connect to a server deployed behind Caddy at http://keycloak-mcp.arpa/mcp using the "url" key.

Contributing

Please audit all code changes against ecosystem guidelines in CONTRIBUTING.md if available, 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.

Deploy with agent-os-genesis

This package can be provisioned for you — skill-guided — by the agent-os-genesis universal skill (its single-package deploy mode): it picks your install method, seeds secrets to OpenBao/Vault (or .env), trusts your enterprise CA, registers the MCP server, and verifies it — the same machinery that stands up the whole Agent OS, narrowed to just this package. Ask your agent to "deploy keycloak-agent with agent-os-genesis".

Install mode Command
Bare-metal, prod (PyPI) uvx keycloak-mcp · or uv tool install keycloak-agent
Bare-metal, dev (editable) uv pip install -e ".[all]" · or pip install -e ".[all]"
Container, prod deploy knucklessg1/keycloak-agent:latest via docker-compose / swarm / podman / podman-compose / kubernetes
Container, dev (editable) deploy docker/compose.dev.yml (source-mounted at /src; edits live on restart)

Secrets are read-existing + seeded via vault_sync — you are only prompted for what's missing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keycloak_agent-1.0.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keycloak_agent-1.0.1-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file keycloak_agent-1.0.1.tar.gz.

File metadata

  • Download URL: keycloak_agent-1.0.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for keycloak_agent-1.0.1.tar.gz
Algorithm Hash digest
SHA256 86dbe780478f900ff40d73f8a98230fe9f0347bd22645168e82b9a6bf1aae6db
MD5 766356984ad8d342bf99e968a8414193
BLAKE2b-256 c54aaa929fb6fe0cbe8e17e0e33cf911fcdfd646af271c510a4b1e26f6436c92

See more details on using hashes here.

File details

Details for the file keycloak_agent-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: keycloak_agent-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for keycloak_agent-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d197cb15961fec8d90b909b022cb1757e724736b19f150c79a7319a2217ebf34
MD5 aa9d99de7ac19613ef1fc7806d1af541
BLAKE2b-256 a0558288a3d920100cd8d7644a5a59b4d93753035864685d563a9aaca5929e5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page