Keycloak Model Context Protocol

io.github.ChristophEnglisch由 GitHub 账号 ChristophEnglisch 发布v1.1.0更新于 Oct 29, 2026

Manage Keycloak users, groups, roles and realms through the Keycloak Admin REST API.

发布方自己的服务:model.tools — Zero-Auth Agent Utilities

概览

AI 生成的概览

让助手通过 Keycloak Admin REST API 管理 Keycloak 的领域、用户、组、角色、会话、客户端和事件,并对写操作设有防护。

可以做什么
  • 列出并查看领域,包括领域设置的安全子集和安全摘要
  • 搜索、读取、创建、更新和删除用户,并发送操作邮件
  • 列出组及成员,将用户加入或移出组
  • 列出角色和用户角色,分配或撤销角色
  • 查看客户端,列出用户会话并注销用户
  • 读取登录事件和管理员事件,检查暴力破解锁定状态并解锁账户
适用场景
适合让助手协助日常 Keycloak 身份管理工作:查询用户及其角色、办理员工入职或离职、审计领域安全设置,或排查登录失败与账户锁定。
运行要求
以 npm 包形式通过 stdio 在本地运行,需要 Node.js 22 或更高版本以及可访问的 Keycloak 服务器。需要 KEYCLOAK_URL 和一组凭据:KEYCLOAK_CLIENT_ID 配 KEYCLOAK_CLIENT_SECRET(推荐的服务账号方式),或 KEYCLOAK_USERNAME 配 KEYCLOAK_PASSWORD。可选设置可控制工具集、只读模式、领域白名单和超时。
安装前请注意
它以所提供 Keycloak 账户的权限行事,应使用仅授予所需 realm-management 角色的专用服务账号客户端,切勿使用初始管理员账号。写工具会更改身份、凭据、权限和会话,并可删除用户或撤销角色;默认需要确认,但模型可自行设置 confirm,只有客户端的批准提示才能证明有人同意。尽量启用只读模式和领域白名单,并将 Keycloak 中的名称和描述视为不可信数据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Keycloak Model Context Protocol,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Keycloak MCP Server

[npm version] [CI] [License: MIT]

A Model Context Protocol (MCP) server for Keycloak administration. It lets an AI assistant such as Claude manage users, groups, roles and sessions, and inspect clients, events and the security posture of your realms, through the Keycloak Admin REST API, with least-privilege authentication and guardrails around every write.

[!WARNING] This server acts with the permissions of the Keycloak account you give it. Use a dedicated service-account client with only the roles you need, never the bootstrap admin. Every tool that changes data asks for confirmation by default, and a read-only mode is available. See Security.

Highlights

  • 24 tools in 7 toolsets, enabled per toolset. The default set (core, groups, roles) is small; everything else is opt-in.
  • Least-privilege auth. client_credentials with a service account is the recommended grant; the password grant stays available. No credential defaults, so a missing setting fails fast.
  • Guardrails. Read-only mode, realm allowlist, write protection for the master realm, and a preview-then-confirm: true flow for every change. Grants of administrative rights are detected through composite roles and parent groups.
  • 4 guided prompts (onboarding, offboarding, security audit, failed-login investigation) and MCP resources for realms and users, with realm-name completion.
  • Structured, paginated output with output schemas; secrets and credentials are never returned or logged.
  • Works with Claude Desktop, Claude Code, VS Code, Cursor and any stdio MCP client. Requires Node.js 22 or newer.

How it works

Your MCP client starts the server as a local child process and talks to it over stdio. Every tool call passes the guards, then goes through a single gateway that owns the Keycloak login and caches the access token.

[Architecture: the MCP client talks JSON-RPC over stdio to the server, whose guards, toolsets and gateway call the Keycloak token endpoint and Admin REST API]

What a confirmed call looks like

Every tool that changes data is destructive (it deletes or revokes) or sensitive (it changes identity, credentials, rights or protection mechanisms, for example user_update or user_role_assign). Called without confirm: true, such a tool only returns a preview of what would happen and changes nothing. After you approve, the assistant repeats the call with confirm: true.

The model can set confirm: true itself, even on its first call. The server then still computes the preview and returns it with the result, but only your client's approval prompt proves that a human agreed. All these tools carry destructiveHint, so clients that ask before destructive calls ask here too.

[Sequence of a destructive call: the first user_delete call returns a preview and changes nothing, the repeated call with confirm: true deletes the user]

Quick start

Requirements: Node.js 22 or newer, a Keycloak server your machine can reach (tested with Keycloak 24.0 to 26.8), and an MCP client.

1. Prepare Keycloak (3 steps)

In the realm you want to administer (here demo):

  1. Create a client mcp-admin with Client authentication on and only Service accounts roles enabled (turn off Standard flow and Direct access grants).
  2. Assign roles. On the client's Service accounts roles tab, assign client roles of realm-management. For a first read-only trial: view-users, query-users, query-groups, view-realm.
  3. Copy the secret from the client's Credentials tab.

Step-by-step instructions with Admin Console click paths, kcadm.sh commands and a local Docker Keycloak: docs/getting-started.md.

2. Configure your MCP client

Example for Claude Code (other clients: docs/clients.md):

bash
claude mcp add --transport stdio \  --env KEYCLOAK_URL=https://keycloak.example.com \  --env KEYCLOAK_AUTH_REALM=demo \  --env KEYCLOAK_CLIENT_ID=mcp-admin \  --env KEYCLOAK_CLIENT_SECRET="$KEYCLOAK_CLIENT_SECRET" \  keycloak -- npx -y keycloak-model-context-protocol@1

Or as JSON (Claude Desktop, claude_desktop_config.json):

json
{  "mcpServers": {    "keycloak": {      "command": "npx",      "args": ["-y", "keycloak-model-context-protocol@1"],      "env": {        "KEYCLOAK_URL": "https://keycloak.example.com",        "KEYCLOAK_AUTH_REALM": "demo",        "KEYCLOAK_CLIENT_ID": "mcp-admin",        "KEYCLOAK_CLIENT_SECRET": "<client-secret>"      }    }  }}

3. Ask your first question

List the realms you can access, then show me the first 10 users of realm demo.

If you get an answer, you are done. If not, see docs/troubleshooting.md.

Configuration

All settings are environment variables. Only KEYCLOAK_URL and one set of credentials are required.

VariableDefaultPurpose
KEYCLOAK_URL(required)Base URL of the Keycloak server
KEYCLOAK_AUTH_REALMmasterRealm where the login account or client lives
KEYCLOAK_CLIENT_ID / KEYCLOAK_CLIENT_SECRETnoneclient_credentials login (recommended)
KEYCLOAK_USERNAME / KEYCLOAK_PASSWORDnonePassword grant login (client defaults to admin-cli)
KEYCLOAK_GRANT_TYPEautoclient_credentials or password; detected from what you set
KEYCLOAK_MCP_TOOLSETScore,groups,rolesEnabled toolsets, or all
KEYCLOAK_MCP_READ_ONLYfalseRegister read-only tools only
KEYCLOAK_MCP_REALMSallComma-separated allowlist of target realms
KEYCLOAK_MCP_ALLOW_MASTER_WRITEfalseAllow write tools in the master realm
KEYCLOAK_MCP_REQUIRE_CONFIRMATIONtrueDestructive and sensitive tools need confirm: true
KEYCLOAK_MCP_TIMEOUT_MS30000HTTP timeout for Keycloak requests
KEYCLOAK_MCP_LOG_LEVELinfodebug, info, warn or error (stderr)

Full reference with examples, validation rules and the tool-to-role matrix: docs/configuration.md.

Toolsets and tools

Tools are named <domain>_<verb>. Only the default toolsets are enabled unless you set KEYCLOAK_MCP_TOOLSETS. In read-only mode only tools of kind read are registered.

ToolsetDefaultTools
coreyesrealm_list, realm_get, user_search, user_get, user_create (sensitive), user_update (sensitive), user_delete (destructive), user_send_actions_email (sensitive)
groupsyesgroup_list, group_members_list, user_group_add (sensitive), user_group_remove (destructive)
rolesyesrole_list, user_roles_list, user_role_assign (sensitive), user_role_revoke (destructive)
clientsnoclient_list, client_get
sessionsnouser_sessions_list, user_logout (destructive)
eventsnoevent_list, admin_event_list
securitynouser_brute_force_status, user_brute_force_unlock (sensitive)

Details for every tool (parameters, outputs, required roles): docs/tools-reference.md.

Prompts and resources

Prompts are guided workflows built on the tools. They appear in your client's prompt picker (in Claude Code as slash commands). The realm argument autocompletes.

PromptWhat it does
onboard_employeeCreate a user, add groups and roles, send the welcome e-mail
offboard_employeeReview, end sessions and disable a departing employee's account (does not delete)
audit_realm_securityRead-only security review with prioritized findings
investigate_failed_loginsAnalyze failed logins and lockout status without changing anything

Resources are read-only JSON documents, filtered by the same realm allowlist:

URIContent
keycloak://realmsNames of accessible realms
keycloak://realms/{realm}Safe subset of the realm settings
keycloak://realms/{realm}/security-summaryBrute-force, password policy, SSL, OTP, event flags, client exposure counts (no secrets)
keycloak://realms/{realm}/users/{userId}One user's basic fields (no attributes, no credentials)

Security

  • Least privilege first. Use a service-account client scoped to one realm with only the realm-management roles you need. A role matrix is in docs/configuration.md.
  • Every change needs confirmation (KEYCLOAK_MCP_REQUIRE_CONFIRMATION=true): destructive and sensitive tools show a preview first. Grants of administrative rights, also through composite roles and parent groups, profile changes and action e-mails for accounts with administrative rights, and changes to the server's own account need a confirmation that KEYCLOAK_MCP_REQUIRE_CONFIRMATION=false does not turn off. Role and group grants, profile changes and action e-mails for the server's own account are refused.
  • Account takeover protection: a changed e-mail address is marked as unverified unless stated otherwise, action e-mail links are valid for at most 24 hours, and previews name the recipient address and whether the target account has administrative rights.
  • Blast-radius limits: KEYCLOAK_MCP_READ_ONLY, KEYCLOAK_MCP_REALMS, and write protection for master (off by default).
  • No secrets in output or logs. Credentials are masked on stderr; tools never return client secrets, user credentials or attributes.
  • Prompt injection: treat names and descriptions coming from Keycloak as data. The shipped prompts say so explicitly; keep write tools disabled when you do not need them.

Threat model, hardening checklist and how to report a vulnerability: docs/security.md and SECURITY.md.

Example prompts

  • "Which realms can you see? Show me the settings of realm demo."
  • "Find all users in demo whose e-mail ends with @example.com and who are disabled."
  • "Create user jdoe (Jane Doe, [email protected]) in demo, add her to group engineering and send her an e-mail to set a password."
  • "Who is in the group ops, and which roles does alice have, including composite roles?"
  • "Run the audit_realm_security prompt for demo." (needs clients and events toolsets for the full audit)
  • "There were many failed logins last night. Investigate realm demo."
  • "Offboard bob in demo: end his sessions and disable the account."

Documentation

DocumentContent
docs/getting-started.mdLocal Keycloak, service-account setup, first run, MCP Inspector
docs/configuration.mdEnvironment reference, role matrix, role profiles, TLS
docs/clients.mdClaude Desktop, Claude Code, VS Code, Cursor, generic clients
docs/tools-reference.mdEvery tool in detail
docs/security.mdThreat model and hardening
docs/troubleshooting.mdSymptoms, causes, fixes
docs/architecture.mdComponents, flows, design decisions
CHANGELOG.mdRelease notes

Upgrade from 0.x

Version 1.0 changes the defaults: credentials are required (no admin/admin fallback), destructive tools ask for confirmation, and the tools were renamed to <domain>_<verb> (for example create-user became user_create, delete-user became user_delete). The old KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD variables still work but are deprecated. See the migration guide.

Contributing and license

Contributions are welcome. See CONTRIBUTING.md and the Code of Conduct. Released under the MIT License.

来源:README.md,提交 b2c37f7

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

3
  1. v1.1.0最新Oct 29, 2026
  2. v1.0.3Oct 26, 2026
  3. v1.0.2Oct 25, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

其他 Model 集成