Back to Browse

mcp-keycloak MCP Server

by dockndevai
SecurityModerate5.2LocalNew
Free

Multi-realm Keycloak admin for AI agents — safe-by-default access modes.

About

MCP server for Keycloak. Inspect and manage realms, users, clients, roles, and groups through natural language, with safe-by-default security: read-only / read-write / admin access modes (tools above the current mode are never even registered), realm allowlists, protected realms that can be read but never mutated, explicit delete gating, dry-run, and JSON audit logging. Auth via a confidential-client service account or admin user.

Security Report

5.2
Moderate5.2Moderate Risk

mcp-keycloak is a well-designed security-first MCP server for Keycloak with a comprehensive layered security model. Authentication is properly implemented with token caching and automatic refresh. Code quality is high with excellent input validation, proper error handling, and well-tested security policies. The server uses environment variable-based configuration with sensible defaults (read-only mode, protected realms, delete disabled). Minor findings include TLS certificate verification bypass capability and lack of explicit sanitization in some error responses, but these are intentional design choices or low-severity issues that do not materially impact security. Supply chain analysis found 3 known vulnerabilities in dependencies (0 critical, 3 high severity). Package verification found 1 issue.

7 files analyzed · 8 issues found

Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.

Permissions Required

This plugin requests these system permissions. Most are normal for its category.

HTTP Network Access

Connects to external APIs or services over the internet.

env_vars

Check that this permission is expected for this type of plugin.

How to Install

Add this to your MCP configuration file:

{
  "mcpServers": {
    "mcp-keycloak": {
      "args": [
        "-y",
        "@dockndevai/mcp-keycloak"
      ],
      "command": "npx"
    }
  }
}

Getting Started

Once installed, try these example prompts and explore these capabilities:

  • 1"List the users in the app realm"
  • 2"Show the clients configured in realm customers"
  • 3"How many users are in the app realm?"
  • 4Tool: create_user — create a user in a realm (requires read-write mode)

Documentation

View on GitHub

From the project's GitHub README.

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 modesread-onlyread-writeadmin, 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.

Security model

ConcernFlagDefaultEffect
What can the server do at all?KEYCLOAK_MODEread-onlyread-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_REALMSmasterProtected realms can be read but never mutated or deleted, regardless of mode.
Can it delete?KEYCLOAK_ALLOW_DELETEfalsedelete_* tools require this and admin mode.
Preview without touching KeycloakKEYCLOAK_DRY_RUNfalseWrite/admin tools validate + log intent, then return without calling Keycloak.
Audit trailKEYCLOAK_AUDIT_LOGtrueEmits a JSON line to stderr per guarded operation (ALLOW / DENY / DRY_RUN).

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

Reviews

No reviews yet

Be the first to review this server!