mcp-keycloak-admin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mcp-keycloak-admin contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # mcp-keycloak-admin
2
+
3
+ A [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server to
4
+ administer a [Keycloak](https://www.keycloak.org) instance through its Admin
5
+ REST API. Safe by default, configurable, and built with a clean, test-driven
6
+ architecture.
7
+
8
+ Compatible with **Keycloak 26.x** (validated against 26.0.5).
9
+
10
+ > **Project status:** early. The architecture, tooling and safety model are in
11
+ > place and exercised by unit and integration tests. The exposed tool surface is
12
+ > being grown incrementally — see [Tools](#tools) and [Roadmap](#roadmap).
13
+
14
+ ## Why
15
+
16
+ Administering Keycloak from an MCP client (an assistant, an IDE, a custom agent)
17
+ means exposing day-to-day operations — searching users, managing roles, reading
18
+ events — as MCP tools, without handing over a raw admin console. This server
19
+ does that with strong guardrails so destructive actions never happen silently.
20
+
21
+ ## Features
22
+
23
+ - **Two authentication modes**, selectable by configuration:
24
+ - `service_account` — a confidential client with a service account
25
+ (recommended; no admin password stored).
26
+ - `password` — the `admin-cli` client with an admin username/password.
27
+ - **Safe by default:**
28
+ - `READ_ONLY` mode hides every write/destructive tool.
29
+ - `ALLOWED_REALMS` restricts which realms the server may operate on.
30
+ - Destructive operations require explicit confirmation (native MCP
31
+ elicitation, with a `confirm: true` parameter fallback for clients that do
32
+ not support elicitation).
33
+ - **Clean Architecture**: a framework-free domain, application use cases, and
34
+ infrastructure adapters. No business concept travels as a raw string or
35
+ number — every one is a validated value object.
36
+
37
+ ## Requirements
38
+
39
+ - Node.js >= 20
40
+ - A reachable Keycloak 26.x server
41
+
42
+ ## Usage with an MCP client
43
+
44
+ Add the server to your MCP client configuration:
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "keycloak-admin": {
50
+ "command": "npx",
51
+ "args": ["-y", "mcp-keycloak-admin"],
52
+ "env": {
53
+ "KEYCLOAK_BASE_URL": "http://localhost:8080",
54
+ "KEYCLOAK_REALM": "demo-realm",
55
+ "AUTH_MODE": "service_account",
56
+ "KC_CLIENT_ID": "mcp-admin",
57
+ "KC_CLIENT_SECRET": "your-secret"
58
+ }
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ See [docs/setup-keycloak.md](docs/setup-keycloak.md) to create the `mcp-admin`
65
+ client and grant it the least-privilege roles it needs.
66
+
67
+ ## Configuration
68
+
69
+ | Variable | Required | Description |
70
+ | ------------------- | --------------------- | -------------------------------------------------------- |
71
+ | `KEYCLOAK_BASE_URL` | yes | Base URL of the Keycloak server (no trailing slash). |
72
+ | `KEYCLOAK_REALM` | yes | Realm the server operates on. |
73
+ | `AUTH_MODE` | yes | `service_account` or `password`. |
74
+ | `KC_CLIENT_ID` | if `service_account` | Confidential client id (e.g. `mcp-admin`). |
75
+ | `KC_CLIENT_SECRET` | if `service_account` | Client secret. |
76
+ | `KC_ADMIN_USERNAME` | if `password` | Admin username. |
77
+ | `KC_ADMIN_PASSWORD` | if `password` | Admin password. |
78
+ | `KC_ADMIN_REALM` | no (default `master`) | Realm holding the admin user (`password` mode). |
79
+ | `READ_ONLY` | no (default `false`) | When `true`, write/destructive tools are not registered. |
80
+ | `ALLOWED_REALMS` | no | Comma-separated allow-list of realms. Empty = all. |
81
+
82
+ A full example lives in [`.env.example`](.env.example).
83
+
84
+ ## Tools
85
+
86
+ Levels: **[R]** read-only · **[W]** write · **[D]** destructive (requires
87
+ confirmation). Every tool carries the matching MCP annotations
88
+ (`readOnlyHint` / `destructiveHint` / `idempotentHint`).
89
+
90
+ Currently implemented:
91
+
92
+ | Tool | Level | Description |
93
+ | ------------------------------------------- | ----- | ----------------------------------------------------- |
94
+ | `keycloak_user_search` | R | Search realm users by email, username or free text. |
95
+ | `keycloak_user_get` | R | Fetch a single user by id. |
96
+ | `keycloak_user_sessions_list` | R | List a user's active sessions. |
97
+ | `keycloak_user_create` | W | Create a realm user. |
98
+ | `keycloak_user_update` | W | Update a user's email, name or enabled flag. |
99
+ | `keycloak_user_set_enabled` | W | Enable or disable a user. |
100
+ | `keycloak_user_send_action_email` | W | Send a required-actions email. |
101
+ | `keycloak_user_reset_password` | D | Set a new password for a user. |
102
+ | `keycloak_user_logout` | D | Revoke all of a user's sessions. |
103
+ | `keycloak_user_delete` | D | Permanently delete a user (id + username must match). |
104
+ | `keycloak_role_list` | R | List realm roles. |
105
+ | `keycloak_user_roles_get` | R | List a user's realm roles. |
106
+ | `keycloak_user_role_assign` | W | Grant a realm role to a user. |
107
+ | `keycloak_user_role_unassign` | D | Revoke a realm role from a user. |
108
+ | `keycloak_client_list` | R | List the realm clients. |
109
+ | `keycloak_client_get` | R | Fetch a client by its clientId. |
110
+ | `keycloak_client_get_secret` | R | Read a client secret (masked unless `reveal`). |
111
+ | `keycloak_client_scopes_list` | R | List the realm's client scopes. |
112
+ | `keycloak_client_default_scopes_get` | R | List a client's default scopes. |
113
+ | `keycloak_client_mappers_list` | R | List a client's protocol mappers. |
114
+ | `keycloak_client_scope_assign` | W | Add a default scope to a client. |
115
+ | `keycloak_client_scope_unassign` | D | Remove a default scope from a client. |
116
+ | `keycloak_client_regenerate_secret` | D | Regenerate a client secret (old one stops working). |
117
+ | `keycloak_group_list` | R | List the realm's top-level groups. |
118
+ | `keycloak_group_members_list` | R | List the members of a group. |
119
+ | `keycloak_user_groups_list` | R | List the groups a user belongs to. |
120
+ | `keycloak_group_create` | W | Create a top-level group. |
121
+ | `keycloak_group_member_add` | W | Add a user to a group. |
122
+ | `keycloak_group_role_assign` | W | Grant a realm role to a group. |
123
+ | `keycloak_group_member_remove` | D | Remove a user from a group. |
124
+ | `keycloak_group_delete` | D | Delete a group. |
125
+ | `keycloak_idp_list` | R | List identity providers. |
126
+ | `keycloak_idp_get` | R | Fetch an identity provider by alias. |
127
+ | `keycloak_idp_mappers_list` | R | List an identity provider's mappers. |
128
+ | `keycloak_idp_create` | W | Create an identity provider. |
129
+ | `keycloak_idp_delete` | D | Delete an identity provider. |
130
+ | `keycloak_federation_list` | R | List user federation (LDAP/Kerberos) providers. |
131
+ | `keycloak_federation_get` | R | Fetch a federation provider by id. |
132
+ | `keycloak_federation_sync` | W | Trigger a user sync (full or changed). |
133
+ | `keycloak_auth_flows_list` | R | List authentication flows. |
134
+ | `keycloak_auth_required_actions_list` | R | List required actions. |
135
+ | `keycloak_auth_required_action_set_enabled` | W | Enable/disable a required action. |
136
+ | `keycloak_authz_resources_list` | R | List a client's authorization resources. |
137
+ | `keycloak_authz_policies_list` | R | List a client's authorization policies. |
138
+ | `keycloak_authz_permissions_list` | R | List a client's authorization permissions. |
139
+ | `keycloak_events_login` | R | Read recent login events (filterable). |
140
+ | `keycloak_events_admin` | R | Read recent admin events. |
141
+ | `keycloak_realm_get_config` | R | Read key realm configuration flags. |
142
+ | `keycloak_server_info` | R | Read the Keycloak server version. |
143
+
144
+ See [docs/users.md](docs/users.md), [docs/roles.md](docs/roles.md),
145
+ [docs/clients.md](docs/clients.md), [docs/groups.md](docs/groups.md) and
146
+ [docs/events-realm.md](docs/events-realm.md) for parameters and examples, and
147
+ [docs/security.md](docs/security.md) for the safety model.
148
+
149
+ ## Roadmap
150
+
151
+ The architecture is designed to keep growing as thin use cases + tools.
152
+ Remaining candidates: authorization policy/permission CRUD and evaluation,
153
+ authentication flow mutation (copy/add executions), and advanced federation and
154
+ identity-provider configuration. See [docs/development.md](docs/development.md)
155
+ for how to add one.
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ npm install
161
+ npm test # unit tests
162
+ npm run test:integration # spins up a real Keycloak 26 via Testcontainers (needs Docker)
163
+ npm run check # typecheck + lint + format check + unit tests
164
+ npm run build # bundle to dist/
165
+ ```
166
+
167
+ ## Contributing
168
+
169
+ Contributions are welcome — please read [CONTRIBUTING.md](CONTRIBUTING.md).
170
+
171
+ ## License
172
+
173
+ [MIT](LICENSE)