Keycloak as an MCP authorization server

A Keycloak MCP authorization server issues tokens that let AI agents call Model Context Protocol servers under controlled identities and scopes. This page covers the options, setup sequence, security controls and limits to confirm before rollout.

On this page

How a Keycloak MCP authorization server fits agent access control

An organization that wants AI agents, coding assistants and workplace tools to call Model Context Protocol (MCP) servers under named users and bounded scopes needs an authorization server that issues those tokens. Keycloak can act as that authorization server, so the agent or tool obtains an access token for a specific user, the MCP server validates it, and access is limited to the scopes the client was granted. This page covers how that arrangement is built with Keycloak: which MCP-related capabilities exist, how resource indicators and client ID metadata documents are used, and which experimental features must be enabled before they work.

MCP support depends on the Keycloak version and on the features enabled in your deployment. The current Keycloak release is 26.8.1, but MCP-related behavior is tied to specific releases and to feature flags that may be experimental, so the reader should not assume a capability from a general Keycloak description. Before design work starts, confirm in the Keycloak documentation for the exact release you plan to run which MCP specification revision is covered, which features must be enabled and what their support status is. The Keycloak server administration guide is the starting point for that check, and the result should be recorded in the design document because it determines the client registration model and the token validation work on the MCP server side.

The decision to make first is whether your agents will register with Keycloak dynamically or whether an administrator will pre-register each client. That choice shapes how much you rely on experimental features and how much governance you need around client creation. Confirm with your Keycloak vendor or support channel which path is supported for your release, and plan a test realm where you can verify that a token issued for one user and one MCP server cannot be replayed against another. Treat any feature that the documentation marks as experimental as a risk to be reviewed by your security team, not as a production default.

How an agent gets a token for an MCP server

This general request flow, not a vendor-verified specification, starts with the MCP client in the agent host reading the Keycloak metadata document to find its endpoints. The client sends the user's browser to Keycloak to sign in and consent, then receives an authorization code. It exchanges that code at the token endpoint, naming the target resource, and receives an access token. The client calls the MCP server with that token, and the server checks the token audience before it serves the request. The trust boundary sits between the agent host and the MCP server. Confirm the exact flow against the current MCP specification and your Keycloak configuration.

General flow from MCP client to Keycloak token issuance and MCP server check.

Configuration options and when each fits

This table compares the ways an MCP deployment can register and identify its clients, and the conditions under which each one fits. Read each row against the MCP clients you plan to allow, since the client's own support often decides the choice more than Keycloak's settings do. Confirm each feature against the Keycloak version you run before you commit to a design.

OptionWhen it fitsWhat the MCP client must supportWhat to confirm in Keycloak docs
Pre-registered confidential clientA known, server-side MCP client (for example, an internal agent platform) that can keep a client secret or key safe.Ability to hold a client secret and run the OAuth 2.0 authorization code flow from a backend component.Client authentication methods, secret rotation steps and the client settings the Keycloak version exposes in the Admin Console.
Public client for desktop or CLI agentsDeveloper tools that run on user machines and cannot protect a secret, so they rely on PKCE.Authorization code flow with PKCE and a loopback or custom redirect URI.PKCE enforcement settings, allowed redirect URI rules and any client policy that restricts public clients.
Dynamic client registrationLarge or fast-changing sets of MCP clients where manual onboarding would become a bottleneck.Calling the registration endpoint and storing the issued client identifier and any secret it returns.Whether anonymous or initial-access-token registration is enabled, and which trusted hosts and policies apply in your version.
Client ID metadata documentsMCP clients hosted at a stable HTTPS address that publish their own metadata, so the server can trust the metadata without prior registration.Fetching and validating a metadata document from the client identifier URL before using it.Whether the feature is available as an experimental option in your version, the feature flag name and the required setting to enable it.
Resource indicators (RFC 8707)Any MCP server that must accept only tokens issued for that server, which limits token reuse across services.Sending a resource parameter in authorization and token requests that names the MCP server URI.How the audience of issued tokens is set from the resource parameter and how the MCP server checks the audience claim.
Pre-registration plus resource indicatorsControlled rollouts where each agent is approved in advance and every token must target one MCP server.Confidential or public client support, plus the resource parameter in each flow.Client scopes and audience mappers that place the MCP server identifier into the access token.

Which Keycloak release line to plan an MCP rollout against

Start by choosing the exact release you will run. The current Keycloak release is 26.8.1, published October 13, 2026, while the Red Hat build of Keycloak product page showed 26.6 as its latest version. A team choosing between the upstream project and Red Hat's supported distribution may therefore be planning against different release lines, so confirm which one your support contract covers before you write the design. Keycloak plans four minor releases a year and says breaking changes in a minor release will be opt-in. That lowers the chance of a surprise, but it does not remove the need to pin a version and test MCP sign-in flows against that exact build. Record the version in your change records and repeat the agent sign-in tests before each minor upgrade.

The 26.8 upgrade notes contain three changes that matter for an identity provider in front of agents. SMTP connections now require StartTLS with no plaintext fallback, so the mail relay used for verification and recovery messages must support it. Backchannel logout tokens from external providers must have their signatures validated, so any brokered identity provider that sends logout tokens needs correct keys and issuer settings. Login failures are also persisted to the database by default, which adds write load and retention questions for your database team. Read the Keycloak upgrading guide and check each change against your environment before you approve a target version.

Treat any experimental MCP-related feature as a separate decision. Keycloak features that are not yet stable must be enabled explicitly, and their behavior can change between releases. Before you enable one, read the release notes for that version to confirm its status and any changed behavior, then test it in a staging realm while production stays on the stable configuration. Put feature flags in your deployment configuration under version control so a later upgrade cannot change them silently. Confirm the current status of each flag with the Keycloak project for your chosen release, and do not assume that a flag name from an older article still applies.

How to set up Keycloak for MCP servers step by step

This sequence takes a team from confirming the Keycloak release and its MCP documentation to a tested, monitored test realm that issues tokens scoped to the MCP servers. Each step ends with a check you can run yourself, so sign-off rests on evidence.

  1. Confirm the release and MCP support

    Start by recording the Keycloak version you run and reading the official documentation for that version to see which MCP specification revision, authorization features and resource indicator behavior it describes. The current release is 26.8.1, published October 13, 2026, but MCP-related details can change faster than the core server, so confirm them against the docs for your exact version and write the answers into your design record. The check passes when you can name the version and the MCP features it documents, with the page you read attached to the record.

  2. Deploy a non-production realm

    Create a dedicated realm in a non-production environment for MCP work, kept separate from the master realm and from any realm that holds workforce accounts. Deploy Keycloak with TLS on all communication and a reverse proxy, following the production guide, so the test setup matches the shape you plan to promote. Your identity or platform engineering team owns this step. The check is that administrators can sign in to the realm's admin console through the intended hostname and that the realm's OpenID Connect discovery document loads over HTTPS.

  3. Enable experimental features only after verification

    Keycloak gates some features behind feature flags, and MCP-related support may depend on one. Before you set any flag, confirm its exact name and whether your release classes it as preview, experimental or supported, using the documentation for that version. Enable it only in the non-production instance, record the flag, its status and the reason in your change log, and plan to retest the feature at each upgrade. The check is that the flag shows as enabled in your server configuration and that the behavior you need works in a test request.

  4. Register the MCP server and agent clients

    Register the MCP server as a resource with its own identifier, then create one client for each agent or application that calls it. Grant each agent client only the scopes its tasks need, and keep client secrets or key material in your secrets store, never in agent configuration files. The identity administrator performs this work with the MCP server team. The check is a client inventory where every agent maps to a named client and a scope list showing which scopes each client may request.

  5. Map audience to the MCP server identifier

    Add an audience mapper to the client or client scope so access tokens carry the MCP server's identifier in the aud claim, which is how the server confirms that a token was issued for it. Agree on the identifier convention with the MCP server team and use the same value in the server's configuration. Resource indicator handling and client ID metadata documents depend on the release, so check those settings against that version's documentation. The check is a test token that lists the MCP server identifier in aud and contains only the scopes you assigned.

  6. Test sign-in with an MCP client

    Connect an MCP client that your agents use to the test server and complete the sign-in flow it performs, so you exercise the discovery, registration and token steps that clients actually run. Decode the access token in the test environment with a JWT inspector and confirm that the aud, scope, iss, exp and client identifier claims match the design. Then send a token issued for a different audience to the MCP server and confirm the server refuses it. The check is one successful call with the expected token and one refused call with the wrong audience, both recorded in your test log.

  7. Enable metrics and admin logging before promotion

    Before promoting the setup, start Keycloak with metrics enabled so Prometheus-format data is served at /metrics on the management interface, and add the optional HTTP request and cache histograms if your monitoring needs them. Turn on admin event logging for the realm so changes to clients and scopes are recorded, and decide where those events will be forwarded. The check is a successful request to the metrics endpoint from your monitoring network and a test change to an MCP client that produces an admin event you can find in the log.

What each team checks before an agent reaches an MCP tool

This team owns the Keycloak layout that every MCP authorization decision depends on. Before any agent connects, they decide how realms are separated, which client types exist, how long tokens live, and how requests reach Keycloak through the reverse proxy. Those choices determine what a token can prove and how long a stolen one stays useful.

  • Realm boundaries: Decide whether MCP clients share a realm with workforce users or sit in a dedicated realm, and keep administrative accounts out of the realm that issues agent tokens.
  • Client types: Confirm which MCP clients are public and which are confidential, and record how each one obtains and stores its credentials.
  • Token lifetimes: Set access token and session lifetimes for agent flows, since an agent may run unattended for longer than a human session.
  • TLS and reverse proxy paths: Expose only the public frontend paths through the proxy, and serve the admin console and Administration REST API on a different hostname or context path, as the production guide calls for.

Hand the realm, client and lifetime settings to the security team for review, and confirm with the AI team which clients need the public endpoints before you publish them.

Security controls an MCP authorization setup needs

An MCP authorization server issues tokens that reach tools, data and admin functions on behalf of users and agents. The controls below connect token scope, network exposure, login defenses and feature choices, and a gap in any one of them can undo the others.

Audience binding per MCP server

Each token should name the MCP server it is meant for, so a token issued for one server is rejected by another. Without this check, a token captured from a low-sensitivity server can be replayed against a more sensitive one. Confirm that each MCP server validates the audience claim on every request and rejects tokens whose audience does not match its own identifier. Test this by presenting a token from one server to another and confirming the request fails. Review the resource indicator settings used when clients request tokens.

Keycloak server docs

Least-privilege scopes per tool

Scopes should map to what each MCP tool can do, not to a broad grant that lets an agent read and write everything. Define one scope per capability, such as reading tickets or creating a record, and attach only the scopes a given client and user role need. Ask the team to list every tool, its scope and its data class in writing. Then check that a token issued for a read-only workflow cannot call a write tool. Treat any scope that covers several tools as a finding to justify.

TLS and separated admin hostnames

All traffic between clients, the MCP authorization server and MCP servers should use TLS. Keycloak's production guidance also calls for a reverse proxy with path restrictions and for exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. Check that the admin hostname does not resolve from public networks, that the proxy blocks admin paths on the public hostname, and that certificates are valid on every hop the tokens travel.

Production guide

Metrics on the management interface only

Keycloak exposes Prometheus-format metrics at /metrics when metrics are enabled, and those endpoints can reveal request volumes, client activity and cache behavior. Enable them with the metrics setting on the management interface, not on the public listener. Confirm that a request to /metrics through the public hostname fails and that only the monitoring network can scrape the management port. Ask who owns the scrape configuration and who can read the dashboards built from it.

Metrics guide

Brute force and login failure handling

Agent-facing sign-in paths and user logins both need lockout and failure tracking. Keycloak's 26.8 upgrade notes state that login failures are persisted to the database by default, which gives security teams a record to review. Set brute force detection on the realm that serves MCP clients, decide how temporary lockouts affect automated agents, and test that repeated failed attempts trigger the configured response. Confirm that failure events reach your log or SIEM pipeline.

Experimental features in production

The MCP support in Keycloak depends on features that are marked experimental, and their behavior can change between releases. Enabling them in production means accepting that a minor upgrade may alter how client IDs, metadata or resource indicators are handled. Keep a written list of every experimental feature flag in use, the reason for it, and the test that proves it still works after each upgrade. Plan a staging environment that matches production before any change to these flags.

Release update policy

How much effort an MCP authorization rollout takes

What makes an MCP authorization rollout take more or less effort?

The main drivers are the number of MCP servers, the number of agent clients, whether each client supports the registration method you choose, and how many scopes and tools each server exposes. Each MCP server is a resource that needs its own audience, scopes and token checks, so effort grows with the count of servers and scopes. Each agent client needs a registration path, redirect or grant settings, and testing. Clients that cannot use the registration method you pick add custom work or a fallback design. Ask for these counts in writing before you compare quotes, because they set the scope more than anything else.

What does our team need to provide before the work starts?

Name an owner for each MCP server, each agent client and the Keycloak realm, so approvals and scope decisions have a single person to answer them. Provide test users with realistic roles and a non-production environment where Keycloak, the MCP servers and at least one agent client can run together. Decide which MCP specification version the rollout targets, because that choice determines which Keycloak features and clients are in play. Confirm the Keycloak version you run or plan to run, since the release line you choose affects the build. Missing any of these items usually adds time to the discovery phase rather than to the build itself.

Can our own team build an MCP authorization setup without a partner?

Yes, if your engineers already know Keycloak administration and OAuth 2.0 well, including authorization code flows, token validation and resource-specific audiences. A small pilot with one MCP server and one agent client is a reasonable way to learn the flow before expanding. The caveat is that the MCP-related features in Keycloak are experimental, so they need extra testing, a plan for changes between releases and a fallback if a feature changes or is removed. Teams without this OAuth experience usually benefit from a partner for design review and security testing, while the day-to-day operation stays in-house.

What work recurs after the MCP authorization setup goes live?

Three tasks recur. The first is Keycloak version upgrades, which the project ships on a regular cadence, so plan a test cycle for each upgrade and check experimental features again each time. The second is client reviews, where owners confirm which agent clients still need access, which scopes they hold and whether their redirect and grant settings are still correct. The third is secret rotation for confidential clients and any signing or client credentials used by MCP servers. Set a calendar for these tasks at go-live so they do not depend on memory.

What should we ask a partner to include in a written scope?

Ask for a written list of the MCP servers, agent clients and scopes in scope, along with the MCP specification version and the Keycloak release that the design targets. The scope should name which experimental features are enabled, the test plan for each one, and the non-production environment used for testing. Request the deliverables in detail: realm and client configuration, token validation checks for each MCP server, documentation for owners, and a handover session. Ask how upgrades, client reviews and secret rotation are handled after go-live, and whether they are included or offered separately. DeployOpen agrees scope, deliverables and timelines in writing before work starts, and provides a quote from that written scope.

How do we confirm the effort estimate is realistic before committing?

Run a short discovery phase that inventories MCP servers, agent clients, scopes and tools, and records which clients support the registration method you intend to use. Use the output to test one representative server and one client end to end in a non-production environment. The discovery results should show whether the inventory matches the scope you were quoted, and whether any experimental feature is needed for your design. If the inventory grows during discovery, ask for a revised written scope rather than absorbing the change informally. This keeps the cost tied to the actual number of servers and clients.

Limits to confirm in your environment before you commit

Keycloak's MCP-related capabilities depend on the release you deploy, the features you enable and the clients your agents use. The cards below list the checks that connect those dependencies, and each one should be confirmed against the Keycloak documentation for your exact version and with your MCP client vendors before the design is final.

MCP spec version support

Confirm which Model Context Protocol specification versions the Keycloak release you plan to run supports for authorization. MCP specifications change, and an authorization server that tracks an older revision may not match what your servers and clients expect. Check the version in your design against the Keycloak documentation for your release, then test a full sign-in and token flow against each MCP server you plan to protect. Record the result in the design document so that a later Keycloak upgrade triggers a repeat of this check.

Keycloak docs

Experimental feature status

Identify every MCP-related setting that is marked experimental in the release you choose, and decide whether your organization can accept it. Experimental features may change or be removed in a later release, which affects upgrade planning and how long you can rely on the design. Ask whether the feature is covered by the support terms of your chosen distribution, and document which experimental switches you enable so that they are reviewed during each upgrade.

Client registration and metadata method

Verify that each MCP client in use supports the client registration and metadata method your Keycloak configuration relies on. Some clients expect dynamic registration, others expect pre-registered client IDs, and newer metadata document approaches depend on the client fetching and trusting a document from a URL. Test each client against a non-production realm, and ask the vendor in writing which method it implements and which Keycloak features it has been tested with.

Community or Red Hat build status

Decide whether the Keycloak release you plan to run is the community project or the Red Hat build of Keycloak, because support terms and release timing can differ between them. The Red Hat build is based on the open source project, but the version it ships and the MCP features it includes may not match the latest community release. Confirm with Red Hat which features and versions are supported for your subscription before you commit to a design that depends on them.

Red Hat build page

Token lifetime for long-running agents

Review access token lifetimes, refresh token behavior and session idle and maximum settings against how long your agents run without a user present. An agent that runs a multi-hour task may lose access mid-task if tokens expire, or may hold access longer than your policy allows if lifetimes are set generously. Confirm how refresh behavior works for each client type in your MCP setup, and test a long-running task end to end before approving the design.

Audit coverage for MCP activity

Confirm that Keycloak's login and admin events capture the MCP-related activity your security team needs to investigate, such as which client requested a token for which resource and which administrator changed a client registration. Event capture alone may not show what a tool call did inside an MCP server, so decide which system records that activity. Check event retention settings and how events reach your SIEM before you rely on them for incident response.

How DeployOpen scopes and delivers an MCP authorization setup

DeployOpen treats Keycloak as an MCP authorization server as a scoped engagement inside your own infrastructure. We agree the MCP server, client and agent inventory, the Keycloak version and the experimental features you accept before any build starts, then deliver the configuration, testing and handover in writing.

How we scope

  • Inventory the MCP servers, AI clients and agents that will request tokens, and the resources each one must reach.
  • Confirm the MCP specification version, resource indicator needs and client registration approach your servers and clients support.
  • Agree in writing which experimental Keycloak features you will enable, who approves them and how they are reviewed.

How we build

  • Configure Keycloak realms, clients, scopes and resource indicators to match the agreed MCP authorization design in your environment.
  • Test token audience, scope and consent behavior with each MCP server and client, including denied and expired token cases.
  • Review the admin console and Administration REST API exposure, TLS and reverse proxy settings against Keycloak production guidance.

How we hand over

  • Deliver written configuration records, client and scope inventories, and the list of enabled experimental features with their risks.
  • Document the upgrade path for each Keycloak minor release, including which opt-in breaking changes affect the MCP setup.
  • Walk your platform, security and identity teams through operating the setup and the runbook for rotating client secrets and keys.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped to your Keycloak version and MCP servers.
  • Ask any quote to separate one-time build effort from recurring upgrade, testing and support work for the MCP setup.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.