I administer Keycloak often enough to know the admin console by heart, and seldom enough to forget where each setting lives. So I wrote keycloak-mcp, an MCP server that exposes the Keycloak Admin REST API as tools. An MCP client such as Claude Code can then inspect and change a Keycloak instance from a request in plain language.

Version 0.2.0 came out today, the first release from its new home in the strengthened organization. Version 0.3.0 followed a few hours later with a Helm chart for the shared server.

The project had a second purpose. I had used MCP servers for months without knowing what the protocol offers beyond tools, and writing one was the best way to find out. The biggest surprise was that a server can ship its own skills, with no plugin to distribute next to it.

What it does

Ask “Which groups is asmith in, in realm acme?” and the model makes two calls:

searchUsers({ realm: "acme", search: "asmith" })
getUserGroups({ realm: "acme", userId: <asmith's id> })

and answers /engineering. The 92 tools cover realms, users, clients, client scopes and their mappers, identity providers and their mappers, authentication flows, required actions, sessions, events, roles and groups.

It’s written in Java 25 on Quarkus with the Quarkus MCP server extension. Releases ship as distroless images on GHCR, a JVM build and a native build, for amd64 and arm64. One build serves two transports, stdio and Streamable HTTP, and they differ in whose permissions the tools use.

Your permissions, on a shared server

Over stdio, Claude Code starts the server as a local process for each session. The server signs in to Keycloak with an admin identity of its own, set in its environment. A service account fits best: a confidential client with the client credentials grant, no password, a secret you can rotate, and only the admin roles the tools need. Whoever types the request, the tools act with that account’s roles.

That’s fine on my laptop. In a team it means one shared account with broad roles, and an admin event log where every change has the same author.

So the same build also runs as a shared server over Streamable HTTP, deployed once, for example at https://keycloak.example.com/mcp. This server has no Keycloak identity of its own. Each user adds it to Claude Code and signs in through the browser, on the same Keycloak login page they use for the admin console:

claude mcp add --transport http --client-id keycloak-mcp --callback-port 33418 \
  keycloak https://keycloak.example.com/mcp

A token must carry the mcp-admin realm role to reach /mcp, so you choose who may use the server at all. On every request the server exchanges the user’s token at Keycloak (standard token exchange, RFC 8693) for one the Admin REST API accepts, and calls Keycloak with that. Nothing falls back to a configured account: the admin identity from the environment is used only over stdio.

The model ends up with exactly the permissions you have in the admin console. If your roles let you view the users of acme and nothing else, the tools can list those users, and a client change fails with Keycloak returned 403 Forbidden and changes nothing. The MCP server keeps no permission model of its own, so there’s nothing to keep in sync with Keycloak. Admin events record each change with the user’s id, so the audit trail shows who asked. The IP address they record is the server’s, though, not the user’s.

CI jobs and claude -p have no browser to sign in with. For those, a small helper script gets a token with the password grant for a dedicated Keycloak user. That user goes through the same exchange, with mcp-admin and only the admin roles the job needs, so automation follows the same rules as people.

The shared server runs anywhere the image runs, and on Kubernetes there’s a Helm chart, published on GHCR next to the images and versioned on its own. It needs the Keycloak URL, the public URL of the MCP endpoint, and a Secret you create that holds the token exchange client’s secret:

helm install keycloak-mcp oci://ghcr.io/strengthened/charts/keycloak-mcp --version 0.1.0 \
  -n keycloak-mcp \
  --set keycloakUrl=https://keycloak.example.com \
  --set publicUrl=https://keycloak.example.com/mcp \
  --set exchangeClientSecret.existingSecret=keycloak-mcp-exchange

The chart can also create that Secret from a value, but then Helm keeps the secret in its release, where helm get values shows it. The pod meets the Pod Security “restricted” profile, and the values schema rejects overrides that would break it. The probes call health endpoints that 0.3.0 added on port 9000. They answer without a token, so no Service, Ingress or HTTPRoute of the chart routes to that port. Readiness is down while the server can’t reach Keycloak.

MCP sessions live in the memory of the pod that created them. With more than one replica, the proxy in front must keep each session on its pod, or the client loses it, so without sticky sessions keep one replica.

Security

The write tools change a live server, and the model picks which tool to call and with which arguments. A tool description that says “don’t touch master” is a request the model can ignore. So every rule in this section lives in the server, where the model can’t argue with it.

The master realm is off limits

The master realm holds the administrators of the whole Keycloak instance. A mistake there can lock everyone out, so no write tool accepts it. Quarkus MCP server has tool guardrails, checks that run on a call’s arguments before the tool method, and one small class does the job:

public class ProtectMaster implements ToolInputGuardrail {

    @Override
    public void apply(ToolInputContext context) {
        if ("master".equals(context.getArguments().getValue("realm"))) {
            throw new ToolCallException(context.getTool().name()
                    + " is refused for the master realm, which holds the Keycloak administrators. Nothing was changed.");
        }
    }
}

Every write tool carries @ToolGuardrails(input = ProtectMaster.class), and its description says “Refused for the master realm” so the model knows before it tries. The read tools still work on master. The refusal ends with “Nothing was changed.”, like every refusal in the server, so the model can tell you the realm is untouched.

Secrets stay out of the chat

Everything a tool returns goes into the conversation: the model provider receives it, and the client keeps it in its history. I don’t want Keycloak secrets in either place by default.

getClient returns a client without its secret. Identity provider config comes back with clientSecret replaced by Keycloak’s mask, **********, and an update that doesn’t supply a new secret sends the mask back, so Keycloak keeps the stored one. setUserPassword never returns the password.

Two tools do return a live client secret: getClientSecret and regenerateClientSecret. They’re hidden unless the server runs with MCP_CLIENT_SECRETS_ENABLED=true. A ToolFilter drops them from tools/list, so the model doesn’t know they exist, and it also refuses them in tools/call if a client asks by name anyway. When they’re on, the server refuses to start if MCP traffic logging or REST client logging is enabled, because the log would then hold every secret the tools return.

Destructive tools ask first

Deleting a user, a client or a realm role can’t be undone, and the same goes for logging out every session of a realm or rebinding the browser flow. These tools ask the user before they run, through an MCP elicitation: the server sends the client a small form with one required checkbox, “I understand, proceed”, and a message that names the action, the target, the realm and the consequence. The client shows it as a dialog.

The request goes from the server to the client in the middle of a tool call, so the answer comes from the person at the keyboard and not from the model. The server checks it before it touches Keycloak, and no answer within 60 seconds counts as a no:

switch (response.action()) {
    case ACCEPT -> {
        if (!Boolean.TRUE.equals(response.content().getBoolean(FIELD))) {
            throw refused(tool + " was not confirmed: the user declined.");
        }
    }
    case DECLINE -> throw refused(tool + " was not confirmed: the user declined.");
    case CANCEL -> throw refused(tool + " was not confirmed: the user dismissed the dialog.");
}

Not every client supports elicitation, and without it the server refuses the destructive tools outright. For those clients there’s MCP_CONFIRM_MODE=flag: a guardrail rejects any destructive call whose confirm argument isn’t the JSON boolean true. That’s weaker, because the model writes the argument itself and nobody sees a dialog. The dialog isn’t airtight either: a client can answer it without asking you, for example through a Claude Code Elicitation hook. The risks page says both, and asks you to review each call before you approve it.

What MCP taught me

I started with the usual picture of MCP: a server is a bag of tools. The specification has more primitives than that, and keycloak-mcp ended up using most of them.

Resources are read-only data the client can attach to the conversation. keycloak-mcp offers keycloak://realms and a template, keycloak://realms/{realm}, that the server can complete as you type. In Claude Code you type @keycloak:keycloak://realms/acme and the realm’s settings land in the context, without a tool call:

@ResourceTemplate(uriTemplate = "keycloak://realms/{realm}", name = "realm",
        mimeType = "application/json")
RealmDetail realm(String realm) { ... }

@CompleteResourceTemplate("realm")
List<String> completeRealm(String realm) {
    return realmService.namesStartingWith(realm);
}

Skills surprised me the most. A tool description explains one call. Auditing a realm or debugging a failed sign-in takes a sequence of reads and a way to interpret them, and that knowledge usually lives in an Agent Skill.

When I built java-toolkit, its skills had to ship as a Claude Code plugin through a marketplace: a second artifact, installed separately, with its own version. For keycloak-mcp I expected the same thing, a plugin next to the server. It turns out the MCP Skills extension (io.modelcontextprotocol/skills, protocol revision 2026-07-28) lets the server serve the skills itself:

@Singleton
@Startup
@McpExtension(id = "io.modelcontextprotocol/skills")
public class SkillsExtension {

    @McpExtensionMethod("skills/list")
    ListResult list(@McpExtensionMethodArg(name = "cursor") Optional<String> cursor) { ... }

    @McpExtensionMethod("skills/get")
    GetResult get(@McpExtensionMethodArg(name = "uri") String uri) { ... }
}

The server offers four skills: safe-changes, login-troubleshooting, flow-change and security-audit, which restates the checks of kcwarden. Each one is a SKILL.md with reference files, packaged in the jar. The files are also plain MCP resources at skill://keycloak/<skill>/..., and the skills extension delivers them through those resources. The client loads a skill only when a job needs it, so the four cost no context until then. In Claude Code they show up as slash commands, and the model can load one by itself when a request matches its description:

/keycloak:security-audit acme
/keycloak:login-troubleshooting jdoe in acme

So there’s no plugin to install. One claude mcp add gives you the tools, the resources and the instructions for using them, and they always come from the same build. When I rename a tool, the skill that mentions it changes in the same commit and ships in the same release. A user can’t end up with skills from 0.2 and a server from 0.3.

Because the skills are part of the build, I can test them like code. SkillCatalog checks every file at startup: the frontmatter name must match the directory, the description must fit in 1,024 characters, and every file listed in the index must exist. A bad skill stops the server from starting, and a unit test catches it before that.

Older clients don’t list skills and see the files only as resources. For them the server also offers three prompts, audit-realm, troubleshoot-login and setup-client: shorter fixed instructions that show up as slash commands too. I expect to drop them once clients catch up.

Try it

Read Before you use it first, and point the server at a test Keycloak before a real one. Changes take effect at once, and the model can get them wrong. Connect Claude Code covers the images, the admin service account for stdio, and a shared HTTP server with browser sign-in. The chart README covers Ingress and Gateway API routes, network policies and upgrades. The repository also has a compose file that starts Keycloak with a sample realm to play with.

The project is under the EUPL-1.2. If a tool does something you didn’t expect, open an issue with the prompt and the tool calls.

Leave a comment