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 分