Mcp Keycloak

io.github.dockndevai由 GitHub 帳號 dockndevai 發布v0.3.3更新於 Oct 26, 2026

Keycloak admin for AI agents — realms, users, clients, roles; safe-by-default governance.

已驗證STDIO僅桌面開發者工具安全與監控

概覽

AI 產生的概覽

Keycloak 管理 MCP 伺服器,讓助理檢視領域、使用者、用戶端、角色與群組,預設唯讀並具多層安全開關。

可以做什麼
  • 列出並讀取領域,包含單一領域的設定
  • 搜尋、分頁與統計領域內的使用者,並依 id 取得單一使用者
  • 列出領域內設定的 OAuth/OIDC 用戶端,不含用戶端密鑰
  • 列出領域層級角色與群組
  • 在讀寫或管理模式建立與更新使用者、重設密碼、強制登出以及刪除使用者
適用情境
適合讓 AI 用戶端回答關於 Keycloak 身分設定的問題,例如有哪些領域、使用者是誰、設定了哪些用戶端與角色,或在對話中進行受控的使用者變更。建議先以唯讀模式執行,確有需要修改時再提高模式。
執行需求
透過 npx 從 npm 套件在本機執行,需要 Node.js。必須提供 KEYCLOAK_URL(Keycloak 伺服器基礎位址,結尾不加斜線)以及憑證:使用 KEYCLOAK_CLIENT_SECRET 搭配 KEYCLOAK_CLIENT_ID 的服務帳號密鑰,或管理員使用者名稱/密碼。選用開關包括存取模式、領域允許清單、受保護領域、刪除開關、試執行與稽核記錄。需要能連線至 Keycloak 伺服器的網路。
安裝前請注意
此伺服器持有 Keycloak 管理憑證(KEYCLOAK_CLIENT_SECRET 或使用者名稱/密碼),可讀取並在較高模式下變更身分資料。KEYCLOAK_MODE 預設為唯讀;讀寫模式增加建立使用者、更新、重設密碼與登出,管理模式搭配 KEYCLOAK_ALLOW_DELETE 才能刪除使用者。請設定領域允許清單與受保護領域,並注意稽核記錄會寫入 stderr。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Mcp Keycloak,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

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.

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).
Interactive confirmation(automatic)—Destructive & high-impact actions prompt the human to approve via MCP elicitation before running; clients without elicitation fall back to the *_ALLOW_* gate.

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)

bash
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:

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:

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:

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:

bash
npm installnpm run buildnode dist/index.js   # with the environment variables set

Develop

bash
npm run dev        # watch modenpm test           # unit tests for the security policynpm 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

來源:README.md,提交 c2481a2

工具

8

list_realms

List realms

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

無需輸入參數。

get_realm

Get realm settings

Fetch the configuration of a single realm.

輸入參數realm必填

list_users

List / search users

List users in a realm. Supports free-text search and pagination. Passwords and secrets are never returned by Keycloak.

輸入參數maxfirstrealm必填search

get_user

Get user by id

Fetch a single user representation by their Keycloak id.

輸入參數realm必填userId必填

count_users

Count users

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

輸入參數realm必填search

list_clients

List clients

List OAuth/OIDC clients configured in a realm. Client secrets are not included.

輸入參數realm必填clientId

list_realm_roles

List realm roles

List the realm-level roles defined in a realm.

輸入參數realm必填

list_groups

List groups

List groups in a realm.

輸入參數realm必填search

版本歷史

3
  1. v0.3.3最新Oct 26, 2026
  2. v0.3.0Sep 29, 2026
  3. v0.2.2Sep 16, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分