Keycloak Power
The first comprehensive Keycloak Power for Kiro IDE. Manage Keycloak through its Admin REST API and give Kiro grounded workflows for identity architecture, SSO federation, JWT claims, Organizations, and SaaS authorization.
Features
- Administer realms, clients, users, roles, groups, sessions, events, and client scopes.
- Configure OIDC, SAML, Google, Microsoft Entra ID, Okta, generic external IdPs, and LDAP/AD guidance.
- Create and operate Keycloak Organizations for Keycloak 26+ multi-tenant B2B/B2B2C deployments; manage isolated Organization Groups on Keycloak 26.6+.
- Provision secure BFF clients, fixed SaaS client roles, version-gated LDAP federation inspection, sanitized configuration baselines, and minimal token contracts.
- Govern changes through environment profiles, capability/permission discovery, target-bound plans, preconditions, audit correlation, snapshots, encrypted artifacts, selective copy and compensating rollback.
- Manage client scopes, mapper contracts, realms, clients, LDAP/AD, broker IdPs, authentication flows, roles, groups, Organizations, identity reconciliation and cryptographic JWT verification through explicit plan/apply workflows.
- Inspect JWT structure and claims locally without sending tokens to any service.
- Design authentication flows, MFA, protocol mappers, and authorization middleware contracts.
- Use focused skills that distinguish Keycloak authentication from SaaS-domain authorization.
Requirements
- Kiro IDE with custom Powers enabled.
- Keycloak 21+ for core Admin REST API operations; Keycloak 26+ and Organizations enabled for organization tools; Keycloak 26.6+ for Organization Groups. The power returns
unsupported_featurewith the minimum upgrade for older servers. - A confidential client with Service Accounts Enabled and a client secret.
- A service account granted the least-privilege
realm-managementroles required by the operations you intend to perform. The server uses only Client Credentials Grant; it never uses Resource Owner Password Credentials. - Node.js 22+ to run the bundled MCP server.
Quick start
- Build the server:
Set-Location .\mcp-server npm ci npm run build - In Kiro, open Powers, select Add Custom Power, select Import from folder, and choose the
keycloak-powerdirectory. - Make these values available to the MCP process:
KEYCLOAK_URL=https://keycloak.example.com KEYCLOAK_REALM=master KEYCLOAK_CLIENT_ID=kiro-keycloak-admin KEYCLOAK_CLIENT_SECRET=<service-account-secret> - Start a new Kiro chat and ask, for example, “Liste os realms do Keycloak” or “Configure Organizations para um SaaS B2B”.
KEYCLOAK_URL may include a reverse-proxy context path, for example https://sso.example.com/auth; trailing slashes are normalized. KEYCLOAK_REALM is the realm where the admin client exists (commonly master), not necessarily the realm being managed.
Configure the Keycloak service account
- In the admin console, create a confidential OpenID Connect client, such as
kiro-keycloak-admin, in the administration realm. - Turn on Client authentication and Service accounts roles; do not enable Direct Access Grants for this Power.
- On Credentials, generate and save the client secret in a secret manager. Do not commit it to the repository or
mcp.json. - On Service account roles, select client
realm-managementand assign only necessary permissions. Typical read-only discovery needsquery-realms,query-clients,query-users, andview-realm; realm mutation also needs roles such asmanage-realm,manage-clients,manage-users, ormanage-identity-providers. - Verify connectivity by asking Kiro to call
get_server_info.
Environment configuration
| Variable | Required | Meaning |
|---|---|---|
KEYCLOAK_URL | Yes | Base URL of the Keycloak server. |
KEYCLOAK_REALM | Yes | Realm that authenticates the service account. |
KEYCLOAK_CLIENT_ID | Yes | Confidential client ID for the service account. |
KEYCLOAK_CLIENT_SECRET | Yes | Secret for Client Credentials Grant. |
KEYCLOAK_TIMEOUT_MS | No | Per-request timeout, bounded by the server. |
KEYCLOAK_ENVIRONMENT | Recommended | Logical environment label bound into plans and audit events. |
KEYCLOAK_PROFILE | No | Logical profile name for the active process. |
KEYCLOAK_ALLOWED_HOSTS | Recommended | Comma-separated Keycloak hosts allowed for the active profile. |
KEYCLOAK_ALLOWED_REALMS | Recommended | Comma-separated target realms allowed for the active profile. |
KEYCLOAK_SECRET_SINK_COMMAND | For secret generation/rotation | Trusted executable receiving a JSON secret record on stdin. |
KEYCLOAK_SECRET_SINK_ARGS | No | JSON array of non-secret arguments passed to the sink executable. |
KEYCLOAK_SECRET_RESOLVER_COMMAND | For secretRef-backed writes | Trusted executable returning one referenced secret on stdout; the value never enters a tool result. |
KEYCLOAK_AUDIT_SINK_COMMAND | Recommended for durable audit | Trusted executable receiving sanitized audit events on stdin. |
KEYCLOAK_ARTIFACT_KEY | For encrypted artifacts | 32-byte base64url/64-hex key held outside the repository. |
KEYCLOAK_PROTECTED_REALMS | Recommended | Comma-separated realms that clone/copy workflows must not mutate as sources. |
KEYCLOAK_EXTERNAL_ALLOWED_HOSTS | For metadata/JWKS tests | Explicit hosts allowed for external discovery/JWKS validation. |
KEYCLOAK_USER_FEDERATION_TESTED_VERSION | For user-federation adapters | Exact version covered by an operator-run integration test. |
KEYCLOAK_USER_FEDERATION_TEST_PATH | For connection test | Exact, version-tested realm-relative Admin REST suffix; no default is assumed. |
The Power manifest contains no secret. Use Kiro's environment/secrets configuration or your operating system's environment to provide the values at runtime.
Secret delivery and version gates
create_bff_client requires KEYCLOAK_SECRET_SINK_COMMAND whenever it creates, reconciles, or rotates a BFF client. It sends a JSON record containing type, secretRef, realm, clientId, and the secret through the sink process's stdin, ignores sink stdout/stderr, and returns only { deliveredToVault: true, secretRef }. If Keycloak succeeds and the sink fails, rerun the same target without rotateSecret; the tool reads the current secret again and retries delivery without returning it to chat. Configure the command as a trusted local vault adapter; the MCP server does not implement a vendor-specific vault client or persist secrets.
list_user_federation_providers, get_user_federation_provider, and list_user_federation_mappers require KEYCLOAK_USER_FEDERATION_TESTED_VERSION to exactly match the connected server. test_user_federation_connection additionally requires KEYCLOAK_USER_FEDERATION_TEST_PATH, set only after testing that realm-relative path against that exact Keycloak version. It never accepts a bind password in input.
| Skill | Use it for |
|---|---|
admin-api | Safe, ordered Keycloak Admin REST API administration. |
setup-realm | Realm bootstrap and security baseline. |
setup-client | OIDC/SAML client design and redirect safety. |
identity-providers | Google, Entra ID, OIDC, SAML, and Okta federation. |
organizations | Keycloak 26+ Organizations and B2B multi-tenancy. |
authentication-flows | Browser flows, required actions, OTP, and WebAuthn. |
token-debug | Local JWT decoding and claim diagnosis. |
user-federation | LDAP and Active Directory federation planning. |
protocol-mappers | Claims, audiences, group membership, tenant, and organization mappings. |
saas-authorization | Multi-tenant API authorization architecture. |
troubleshooting | Events, sessions, client, token, and IdP diagnosis. |
MCP tools
| Domain | Tools |
|---|---|
| Realms | list_realms, get_realm, validate_realm, plan_realm, create_managed_realm, update_managed_realm, plan_realm_clone, clone_realm, plan_delete_realm, delete_managed_realm (legacy direct mutators are blocked) |
| Clients | list_clients, get_client, update_client (legacy direct mutation blocked; use plan_client + apply_plan), get_client_secret (blocked to prevent secret retrieval) |
| BFF clients | plan_bff_client, create_bff_client, validate_bff_client (confidential Authorization Code + PKCE S256; secrets go only to the configured vault sink) |
| Users | list_users, get_user, plan_user_operation, apply_user_operation, plan_role_mapping, apply_role_mapping, plan_identity_reconciliation (legacy direct mutators are blocked) |
| Roles | list_roles, get_role, plan_role, update_role, delete_role, plan_role_mapping, apply_role_mapping, plan_saas_default_roles, provision_saas_default_roles, assign_saas_client_role, remove_saas_client_role |
| Groups | list_groups, plan_group, update_group, delete_group, remove_user_from_group, get_group_members (legacy direct mutators are blocked) |
| Organization Groups | get_organization_groups_capability, list_organization_groups, create_organization_group, move_organization_group, delete_organization_group, assign_organization_group_member (Keycloak 26.6+ only; no realm-group fallback) |
| Identity providers | list_identity_providers, get_identity_provider, validate_identity_provider_metadata, plan_identity_provider, create_managed_identity_provider, update_managed_identity_provider, delete_managed_identity_provider, plan_clone_identity_provider, clone_identity_provider, generate_broker_callback, get_identity_provider_mapper_types, list_identity_provider_mappers |
| User federation | list_user_federation_providers, get_user_federation_provider, plan_user_federation_provider, create_user_federation_provider, update_user_federation_provider, delete_user_federation_provider, plan_clone_user_federation_provider, clone_user_federation_provider, list_user_federation_mappers, list_user_federation_mappers_full, plan_create_user_federation_mapper, create_user_federation_mapper, update_user_federation_mapper, delete_user_federation_mapper, test_user_federation_connection, plan_sync_user_federation, sync_user_federation |
| Organizations | list_organizations, get_organization, plan_organization, update_organization, delete_organization, plan_organization_member, add_member_to_organization_managed, remove_member_from_organization_managed, plan_organization_identity_provider, list_organization_identity_providers, add_identity_provider_to_organization_managed, remove_identity_provider_from_organization_managed |
| Authentication | list_auth_flows, get_auth_flow, get_auth_flow_tree, plan_clone_auth_flow, clone_auth_flow, plan_create_auth_flow, create_auth_flow, plan_create_auth_subflow, create_auth_subflow, plan_auth_execution, apply_auth_execution_plan, plan_bind_auth_flow, bind_auth_flow, list_required_actions, update_required_action, validate_flow_safety |
| Sessions and events | get_user_sessions, get_server_info, get_realm_events |
| Tokens | decode_token, get_token_endpoint_info, test_discovery, test_jwks, validate_token_signature, inspect_claim_inventory, test_token_endpoint, validate_token_contract |
| Protocol mappers | list_protocol_mappers, plan_create_protocol_mapper, create_managed_protocol_mapper, plan_update_protocol_mapper, update_protocol_mapper, plan_delete_protocol_mapper, delete_protocol_mapper, get_effective_token_contract, plan_clone_protocol_mapper, clone_protocol_mapper (legacy direct create blocked) |
| Artifacts and governance | get_environment_profile, validate_connection, get_server_capabilities, get_admin_permissions, create_snapshot, export_encrypted_baseline, import_encrypted_baseline, plan_resource_copy, copy_resource, get_audit_events |
| Baseline and token contract | export_sanitized_baseline, diff_sanitized_baseline, validate_token_contract |
Tool inputs are validated for required strings and JSON-shaped configuration values. Every REST request surfaces Keycloak's HTTP status and message to make permissions, malformed request bodies, and unsupported server features diagnosable.
Example Kiro conversations
List the clients in the saas realm and show the redirect URIs for portal-web.
Create the acme organization with alias acme, domain acme.example, and add alice as a member.
Decode this JWT and explain why the API isn't receiving the tenant_id claim.
I need a client for an SPA. Use Authorization Code with PKCE, safe origins, and a groups mapper.
Development
Set-Location .\mcp-server
npm ci
npm run build
The server speaks MCP over standard input/output. Do not write log messages to stdout; diagnostics belong on stderr. See CONTRIBUTING.md for development, security, and pull-request rules.
Privacy and support
- Privacy policy: PRIVACY.md. This Power does not collect telemetry and only communicates with the
KEYCLOAK_URLyou configure. - Support and bug reports: open an issue at github.com/Lucas-magalhaes1/keycloak-power/issues.
Documentation sources
The implementation follows the Keycloak documentation and Admin API reference. Organization guidance follows Keycloak's Organizations announcement. Content was rephrased for compliance with licensing restrictions.
License
Copyright 2026 Lucas Magalhães. Licensed under Apache-2.0.
Governed administration
The extended server keeps the existing read tools for compatibility and adds a plan-first control plane. Start with get_environment_profile, validate_connection, get_server_capabilities, and get_admin_permissions. A mutating workflow should then call a plan_* tool, show its sanitized diff and requiredConfirmation, optionally call create_snapshot, and only then call the matching apply tool with planId, planDigest, and the exact confirmation. Plans are held in memory for the current MCP process, include an expiry and a precondition fingerprint, and fail when the target changed after planning.
Core governance tools include plan_resource_operation, get_plan, list_plans, apply_plan, rollback_operation, get_audit_events, create_snapshot, list_snapshots, get_snapshot, plan_snapshot_restore, export_encrypted_baseline, import_encrypted_baseline, plan_resource_copy, and copy_resource. Generic plans reject token/credential endpoints and plaintext secret-shaped fields. Encrypted artifacts use AES-256-GCM with KEYCLOAK_ARTIFACT_KEY; the key and decrypted content never appear in the MCP response.
Extended catalog
| Area | Tools |
|---|---|
| Discovery and governance | get_environment_profile, validate_connection, get_server_capabilities, get_admin_permissions, plan_resource_operation, get_plan, list_plans, apply_plan, rollback_operation, get_audit_events |
| Realms and copy | validate_realm, plan_realm, create_managed_realm, update_managed_realm, plan_realm_clone, clone_realm, plan_delete_realm, delete_managed_realm, create_snapshot, plan_snapshot_restore |
| Clients and profiles | plan_client, validate_client, plan_delete_client, delete_client, plan_clone_client, clone_client, plan_rotate_client_secret, rotate_client_secret, plan_client_profile |
| Client scopes | list_client_scopes, get_client_scope, plan_client_scope, create_client_scope, update_client_scope, plan_delete_client_scope, delete_client_scope, plan_clone_client_scope, clone_client_scope, list_client_scope_mappers, plan_create_client_scope_mapper, create_client_scope_mapper, plan_update_client_scope_mapper, update_client_scope_mapper, plan_delete_client_scope_mapper, delete_client_scope_mapper, plan_attach_client_scope, attach_client_scope, plan_detach_client_scope, detach_client_scope |
| Protocol mappers/contracts | plan_create_protocol_mapper, create_managed_protocol_mapper, plan_update_protocol_mapper, update_protocol_mapper, plan_delete_protocol_mapper, delete_protocol_mapper, get_effective_token_contract, plan_clone_protocol_mapper, clone_protocol_mapper |
| LDAP/AD federation | plan_user_federation_provider, create_user_federation_provider, update_user_federation_provider, delete_user_federation_provider, plan_delete_user_federation_provider, plan_clone_user_federation_provider, clone_user_federation_provider, list_user_federation_mappers_full, plan_create_user_federation_mapper, create_user_federation_mapper, update_user_federation_mapper, delete_user_federation_mapper, plan_sync_user_federation, sync_user_federation |
| Identity providers/broker | validate_identity_provider_metadata, plan_identity_provider, create_managed_identity_provider, update_managed_identity_provider, delete_managed_identity_provider, plan_clone_identity_provider, clone_identity_provider, generate_broker_callback, list_identity_provider_mapper_types_safe |
| Flows and required actions | get_auth_flow_tree, plan_clone_auth_flow, clone_auth_flow, plan_create_auth_flow, create_auth_flow, plan_create_auth_subflow, create_auth_subflow, plan_auth_execution, apply_auth_execution_plan, plan_bind_auth_flow, bind_auth_flow, list_required_actions, update_required_action, validate_flow_safety |
| Users and authorization | plan_user_operation, apply_user_operation, plan_role_mapping, apply_role_mapping, plan_identity_reconciliation, plan_role, update_role, delete_role, plan_group, update_group, delete_group, remove_user_from_group |
| Organizations | plan_organization, plan_organization_member, add_member_to_organization_managed, remove_member_from_organization_managed, plan_organization_identity_provider, add_identity_provider_to_organization_managed, remove_identity_provider_from_organization_managed, list_organization_identity_providers |
| Token diagnostics | test_discovery, test_jwks, validate_token_signature, inspect_claim_inventory, test_token_endpoint, validate_token_contract |
| Artifacts/copy | export_sanitized_baseline, diff_sanitized_baseline, export_encrypted_baseline, import_encrypted_baseline, plan_resource_copy, copy_resource |
Secret references
For write operations that need a Keycloak credential, pass a reference such as clientSecretRef, bindCredentialSecretRef, certificateRef, or secretRef. The configured resolver receives the reference and operation metadata through stdin and returns the value only to the in-process request handler. Secret generation and rotation send the generated value to the sink and return only delivery metadata. If the resolver or sink is not configured, the operation fails closed before mutation or before a generated credential can be accepted.
Compatibility and rollback limits
The server probes read capabilities and reports 401/403/404 separately. LDAP test/sync adapters require an exact operator-tested version and explicit test path; Organization Groups require Keycloak 26.6+. Built-in authentication flows are read-only for clone workflows and must be copied before changes. Rollback uses captured before representations where the Admin REST operation is reversible; it does not claim to restore deleted users, external LDAP/Entra state, sessions, already issued tokens, external IdP registrations or secrets invalidated by rotation.