Skip to main content
Glama
mcp-keycloak

mcp-keycloak

mcp-keycloak

CI License: MIT npm

A Model Context Protocol server for Keycloak. It lets an MCP-capable client (Claude Desktop, Claude Code, etc.) inspect and manage Keycloak realms, users, clients, roles, and groups — with security controlled entirely by flags.

The design goal is safe by default: it starts read-only, scopes to an allowlist of realms, protects sensitive realms from mutation, and gates destructive operations behind an explicit opt-in.

Features

  • Multi-realm — every tool takes a realm argument; scope it with an allowlist.

  • Access modes — read-only → read-write → admin, layered so a mode never exposes tools above its level.

  • Security flags — realm allowlist, protected realms, delete gating, dry-run, and JSON audit logging (see below).

  • Two auth strategies — confidential-client service account (recommended) or admin username/password.

  • Zero heavy dependencies — a thin fetch-based Admin REST client, plus the MCP SDK and zod.

Related MCP server: keycloak-mcp

Security model

Concern

Flag

Default

Effect

What can the server do at all?

KEYCLOAK_MODE

read-only

read-only exposes only read tools; read-write adds mutations; admin adds destructive tools. Tools above the mode are never registered.

Which realms are in scope?

KEYCLOAK_REALM_ALLOWLIST

(all)

Comma-separated. When set, any operation on a realm outside the list is refused.

Which realms are read-only forever?

KEYCLOAK_PROTECTED_REALMS

master

Protected realms can be read but never mutated or deleted, regardless of mode.

Can it delete?

KEYCLOAK_ALLOW_DELETE

false

delete_* tools require this and admin mode.

Preview without touching Keycloak

KEYCLOAK_DRY_RUN

false

Write/admin tools validate + log intent, then return without calling Keycloak.

Audit trail

KEYCLOAK_AUDIT_LOG

true

Emits a JSON line to stderr per guarded operation (ALLOW / DENY / DRY_RUN).

Interactive confirmation

(automatic)

—

Destructive & high-impact actions prompt the human to approve via MCP elicitation before running. The prompt shows the tool, the exact arguments (secrets redacted) and a fingerprint; the target user's version is pinned across the prompt and the action is refused if it changed; a prompt nobody answers is a refusal.

Self-signed Keycloak certificate

KEYCLOAK_TLS_REJECT_UNAUTHORIZED

true

Set false only for a throwaway lab: certificate verification is then disabled for requests to Keycloak only (not process-wide) and a warning is printed.

Require a human

KEYCLOAK_REQUIRE_HUMAN_APPROVAL

false

When true, destructive ops are refused if the client cannot elicit (instead of falling back to the *_ALLOW_* gate alone).

These layers are independent — for example admin mode with KEYCLOAK_ALLOW_DELETE=false can create and update users but cannot delete them.

Tools

Read (read-only+): list_realms, get_realm, list_users, get_user, count_users, list_clients, list_realm_roles, list_groups

Write (read-write+): create_user, update_user, reset_password, logout_user

Admin (admin): delete_user

Quickstart — add to your agent

Published on npm as @dockndevai/mcp-keycloak. No clone or build needed — your MCP client runs it on demand with npx. Start in read-only mode; see .env.example for every variable and docs/CLIENTS.md for the full per-client guide.

Claude Code (CLI)

claude mcp add keycloak -e KEYCLOAK_URL="https://keycloak.example.com" -e KEYCLOAK_CLIENT_ID="admin-cli" -e KEYCLOAK_CLIENT_SECRET="your-secret" -e KEYCLOAK_MODE="read-only" -- npx -y @dockndevai/mcp-keycloak

Claude Desktop · Cursor · Windsurf — same block in claude_desktop_config.json, .cursor/mcp.json, or ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "keycloak": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-keycloak"
      ],
      "env": {
        "KEYCLOAK_URL": "https://keycloak.example.com",
        "KEYCLOAK_CLIENT_ID": "admin-cli",
        "KEYCLOAK_CLIENT_SECRET": "your-secret",
        "KEYCLOAK_MODE": "read-only"
      }
    }
  }
}

OpenAI Codex CLI — in ~/.codex/config.toml:

[mcp_servers.keycloak]
command = "npx"
args = ["-y", "@dockndevai/mcp-keycloak"]
env = { KEYCLOAK_URL = "https://keycloak.example.com", KEYCLOAK_CLIENT_ID = "admin-cli", KEYCLOAK_CLIENT_SECRET = "your-secret", KEYCLOAK_MODE = "read-only" }

VS Code (GitHub Copilot, Agent mode) — in .vscode/mcp.json:

{
  "servers": {
    "keycloak": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-keycloak"
      ],
      "env": {
        "KEYCLOAK_URL": "https://keycloak.example.com",
        "KEYCLOAK_CLIENT_ID": "admin-cli",
        "KEYCLOAK_CLIENT_SECRET": "your-secret",
        "KEYCLOAK_MODE": "read-only"
      }
    }
  }
}

Configure

Copy .env.example and fill it in, or set the variables directly in your MCP client config. A confidential client with the realm-management roles you need is the recommended credential.

Run from source (development)

Prefer the published package above. To run from a clone:

npm install
npm run build
node dist/index.js   # with the environment variables set

Develop

npm run dev        # watch mode
npm test           # unit tests for the security policy
npm run typecheck

Publishing

This server ships a server.json for the official MCP registry and an mcpName for npm ownership validation. See PUBLISHING.md for publishing to npm and listing on the MCP registry, Smithery, Glama, Cursor, and PulseMCP.

License

MIT

Available Tools

8 tools
count_usersCount usersA
Read-onlyIdempotent

Return the number of users in a realm, optionally matching a search term.

Inputs: realm (required), search.

get_realmGet realm settingsA
Read-onlyIdempotent

Fetch the configuration of a single realm. Secrets (SMTP password, codeSecret, identity-provider and LDAP credentials, secret-shaped attributes) are replaced with [REDACTED].

Inputs: realm (required).

get_userGet user by idA
Read-onlyIdempotent

Fetch a single user representation by their Keycloak id. Secret-shaped attribute values and credentials are replaced with [REDACTED].

Inputs: realm (required), userId (required).

list_clientsList clientsA
Read-onlyIdempotent

List OAuth/OIDC clients configured in a realm. Client secrets, registration access tokens, rotated secrets, private keys and other secret-shaped fields are replaced with [REDACTED].

Inputs: realm (required), clientId.

list_groupsList groupsB
Read-onlyIdempotent

List groups in a realm. Secret-shaped attribute values are replaced with [REDACTED].

Inputs: realm (required), search.

list_realm_rolesList realm rolesA
Read-onlyIdempotent

List the realm-level roles defined in a realm. Secret-shaped attribute values are replaced with [REDACTED].

Inputs: realm (required).

list_realmsList realmsA
Read-onlyIdempotent

List all realms visible to the configured credentials. Realms outside the allowlist are filtered out.

Inputs: no named parameters.

list_usersList / search usersA
Read-onlyIdempotent

List users in a realm. Supports free-text search and pagination. Secret-shaped attribute values and credentials are replaced with [REDACTED].

Inputs: realm (required), max, first, search.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool maps to a distinct resource+action pair: list_realms/get_realm differ by scope, list_users/get_user/count_users differ by granularity and verb, and groups, clients, and realm roles are clearly separate resources. The only near-neighbors (list_groups vs list_realm_roles) are well differentiated by Keycloak's domain semantics and the descriptions reinforce it.

    Naming Consistency5/5

    All eight tools follow a strict snake_case verb_noun convention (get_realm, list_users, count_users, list_clients, list_realm_roles). No camelCase or verb-style mixing anywhere in the set.

    Tool Count5/5

    Eight tools is well within the ideal 3-15 range and each one corresponds to a meaningful inspection target (realms, groups, users, clients, roles). Nothing looks redundant or bolted on.

    Completeness3/5

    The surface is purely read-only: there is no way to create, update, or delete users, groups, clients, or roles, nor to assign/remove role mappings, which are core Keycloak admin operations. There are also smaller gaps such as no get_group, get_client, or group-membership listing, so agents needing any mutation will hit a dead end.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      An MCP server for Keycloak Admin REST API, enabling user, group, event, and security management through service account authentication.
      33
      62 PyPI
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that lets an AI assistant inspect and modify Keycloak realm, client, and protocol-mapper configuration across multiple Keycloak hosts.
      7
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables administration of Keycloak identity and access management through MCP, allowing management of realms, clients, users, roles, groups, identity providers, and sessions from any MCP client.
      Apache 2.0
    • A
      license
      C
      quality
      D
      maintenance
      A comprehensive MCP server for Keycloak administration, offering 80+ tools to manage users, realms, clients, roles, groups, sessions, events, organizations, and more directly from AI assistants.
      86
      MIT