
Keycloak Admin API
io.github.sferarc由 GitHub 账号 sferarc 发布v3.8.0更新于 Nov 6, 2026
Unofficial: one tool per Keycloak admin operation on a realm, read-only unless writes are enabled
概览
非官方 Keycloak Admin API MCP 服务器,按单个 realm 提供管理操作工具,默认只读,可让助手查看用户、组和角色。
- 可以做什么
- 通过每个 Keycloak 管理操作一个工具,查询用户、组、角色及其他 realm 资源
- 读取所配置 realm 的层级设置与对象
- 在启用写入后,可选地列出并执行写入操作,包括删除
- 将暴露的工具限定为指定资源,例如 users、groups、roles
- 把 HTTP 错误作为工具错误返回,并附带状态码和 Keycloak 的报错信息
- 适用场景
- 适合让助手回答关于自建 Keycloak realm 的问题,例如某个角色下有哪些用户,或在对话中查看身份数据。若需要对单个 realm 进行范围受限、以只读为主的访问,而不是完整的脚本化管理,可考虑添加。
- 运行要求
- 通过 npx 在本地运行(需 Node.js)。需要 KEYCLOAK_URL 和 KEYCLOAK_REALM,并提供固定的 KEYCLOAK_TOKEN,或使用带 KEYCLOAK_CLIENT_ID 与 KEYCLOAK_CLIENT_SECRET 的机密客户端(可选 KEYCLOAK_TOKEN_REALM)。服务账号需具备 view-users 等 realm-management 角色。需要能访问 Keycloak 服务器的网络。
安装
在 SourceWeft 中
- 打开 控制台中的 Keycloak Admin API,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
keycloak-api
Unofficial. Not made or endorsed by Keycloak.
Auto-generated, fully typed client for the Keycloak Admin and Account REST APIs.
Generated from the admin OpenAPI spec at https://www.keycloak.org/docs-api/latest/rest-api/openapi.json and the account spec kept in this repository at https://raw.githubusercontent.com/sferarc/openapi/main/packages/keycloak-api/specs/account.yaml; before generating, kubb.config.ts renames operation IDs, camel-cases path parameters, sends raw string bodies unquoted and types the workflow resource path parameter as its enum.
Features
- Fully typed - every endpoint, parameter and response is generated from the official OpenAPI specs
- Admin and Account APIs - separate clients for the two Keycloak surfaces
- Tree-shakable - only the operations you import end up in your bundle
- Runtime agnostic - uses the global
fetch, or bring your own implementation - Effect support - optional Effect bindings for the Admin API via
keycloak-api/effect
Installation
Quick Start
Keycloak is self-hosted, so both clients require the baseUrl of your server. Endpoints are addressed
as "<METHOD> <path>".
src/admin/generated/OPERATIONS.md and src/account/generated/OPERATIONS.md list every admin and account operation with its "<METHOD> <path>" request and the spec's summary, one table per tag. They ship in the package, so grep in node_modules/keycloak-api finds an operation without reading the types.
Admin API
Account API
The Account API is scoped to a single realm, passed at construction time.
Refreshing the token
Keycloak access tokens expire after a few minutes. Pass a function as token, sync or async, and both clients call it before every request, so each call sends the token it returns:
A call rejects with what the function threw, before any request is sent. A call's own config.token still wins.
Custom fetch
Response headers
A call resolves to the parsed body only. To read a response header, pass onResponse in config; it gets the status and headers of the response before the body is read, an error response included. Keycloak answers a create call, such as a new user or client, with 201, an empty body and the new resource's URL, which ends in its id, in Location:
An error thrown inside onResponse rejects the call with an Error whose message starts with onResponse threw on and whose cause is what was thrown.
Errors
A call that gets an HTTP error response rejects with an ApiResponseError, exported from the package, which extends Error: status is the HTTP status code, payload is the parsed JSON error body, or the raw body text, up to 1000 characters, when it is not JSON, and method and path name the request, without its query string. Its message reads <METHOD> <path> returned <status>: <detail>, where the detail is the API's own error message or else the first 200 characters of the body. A request that gets no response at all, for example because the network failed, rejects with an Error whose message names the method, the path and the reason, and whose cause is the original exception. A request cancelled through signal rejects with what the signal was aborted with, as is: the AbortError, or the TimeoutError of AbortSignal.timeout().
Effect
The effect entrypoint exposes every Admin API operation as an Effect, by tag in AdminApiService and by "<METHOD> <path>" in adminEffectByPath, and every Account API operation in AccountApiService and accountEffectByPath. It requires effect 4 as a peer dependency. As with the client class, the layer needs the baseUrl of your server, and token can be a function that returns a fresh token before every call.
Errors are typed as ApiError, NetworkError and ValidationError. An HTTP error response fails with ApiError, which carries the HTTP status; a request that never gets a response, or a token function that throws, fails with NetworkError.
A call can pass its own config, which layers over the layer's: its headers join the layer's, and its other fields, such as onResponse, replace them. An onResponse that throws makes the effect die with the onResponse threw on error as a defect rather than fail with NetworkError.
Account API paths sit under a realm, so an account effect also needs makeAccountLayer(realm), which rebases the server layer's baseUrl onto /realms/<realm> and encodes the realm as KeycloakAccountApi does. One makeApiLayer then serves admin and account effects in the same program:
An account effect run without makeAccountLayer goes to <baseUrl>/account/, which is not a Keycloak endpoint.
MCP server
The package ships keycloak-api-mcp, a stdio MCP server with one tool per admin operation on a realm, so an agent can answer questions such as which users of a realm hold a role. It lists only the read (GET) tools; set KEYCLOAK_MCP_ALLOW_WRITES=1 to add the others, which carry destructiveHint on DELETE. Every tool acts on KEYCLOAK_REALM, which is not a tool argument: the two operations that list and import realms are left out, and a call whose URL resolves outside that realm, such as a group path with .. segments, is refused as a tool error. An HTTP error comes back as a tool error with the status and Keycloak's message.
The service account needs the realm-management roles for what the tools should read, such as view-users.
Without KEYCLOAK_MCP_RESOURCES the server lists about 200 read tools, over the 128 a VS Code chat request can enable, so pick the resources there. An unknown name stops the server with the list of valid ones.
Claude Code, in .mcp.json:
VS Code, in .vscode/mcp.json:
Entrypoints
License
ISC
来源:packages/keycloak-api/README.md,提交 0152cfc
工具
0版本历史
1- v3.8.0最新Nov 6, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分

