Keycloak MCP server

Integrates with Keycloak identity management to enable user creation, role assignment, group management, and client listing across different realms
Back to servers
Setup instructions
Provider
Haitham Oumerzoug
Release date
May 26, 2025
Stats
2 stars

The Keycloak MCP server implements the Model Context Protocol for managing Keycloak users and realms. It provides a standardized interface to interact with Keycloak's administrative functions through a set of predefined tools.

Prerequisites

  • Node.js (Latest LTS version recommended)
  • npm
  • A running Keycloak instance

Installation

Via Smithery

Install automatically using Smithery:

npx -y @smithery/cli install @HaithamOumerzoug/keycloak-mcp --client claude

Via NPM

Install and use the server via NPM:

# Direct usage with npx
npx -y keycloak-mcp

# Or global installation
npm install -g keycloak-mcp

Configuration

Configure the server in your MCP configuration file (for Cursor IDE, Cline, or Claude Desktop):

{
  "mcpServers": {
    "keycloak": {
      "command": "npx",
      "args": ["-y", "keycloak-mcp"],
      "env": {
        "KEYCLOAK_URL": "http://localhost:8080",
        "KEYCLOAK_ADMIN": "admin",
        "KEYCLOAK_ADMIN_PASSWORD": "admin"
      }
    }
  }
}

Available Tools

User Management

Create User

Creates a new user in a specified realm.

Inputs:

  • realm: The realm name
  • username: Username for the new user
  • email: Email address for the user
  • firstName: User's first name
  • lastName: User's last name

Delete User

Deletes a user from a specified realm.

Inputs:

  • realm: The realm name
  • userId: The ID of the user to delete

List Users

Lists all users in a specified realm.

Inputs:

  • realm: The realm name

Realm Management

List Realms

Lists all available realms.

Client Management

List Clients

Lists all clients in a specified realm.

Inputs:

  • realm: The realm name

List Client Roles

Lists all roles for a specific client in a realm.

Inputs:

  • realm: The realm name
  • clientUniqueId: The unique ID of the client

Assign Client Role to User

Assigns a client role to a specific user.

Inputs:

  • realm: The realm name
  • userId: The ID of the user
  • clientUniqueId: The unique ID of the client
  • roleName: The name of the role to assign

Group Management

List Groups

Lists all groups in a specified realm.

Inputs:

  • realm: The realm name

Add User to Group

Adds a user to a specific group.

Inputs:

  • realm: The realm name
  • userId: The ID of the user
  • groupId: The ID of the group

Usage Examples

Managing Users

To create a new user, you would provide input like:

{
  "realm": "master",
  "username": "newuser",
  "email": "[email protected]",
  "firstName": "New",
  "lastName": "User"
}

To list all users in a realm:

{
  "realm": "master"
}

Working with Clients and Roles

First, list all clients in a realm:

{
  "realm": "master"
}

Then, you can list roles for a specific client:

{
  "realm": "master",
  "clientUniqueId": "client-id-from-previous-list"
}

To assign a role to a user:

{
  "realm": "master",
  "userId": "user-id",
  "clientUniqueId": "client-id",
  "roleName": "role-name"
}

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "keycloak" '{"command":"npx","args":["-y","keycloak-mcp"],"env":{"KEYCLOAK_URL":"http://localhost:8080","KEYCLOAK_ADMIN":"admin","KEYCLOAK_ADMIN_PASSWORD":"admin"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "keycloak": {
            "command": "npx",
            "args": [
                "-y",
                "keycloak-mcp"
            ],
            "env": {
                "KEYCLOAK_URL": "http://localhost:8080",
                "KEYCLOAK_ADMIN": "admin",
                "KEYCLOAK_ADMIN_PASSWORD": "admin"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "keycloak": {
            "command": "npx",
            "args": [
                "-y",
                "keycloak-mcp"
            ],
            "env": {
                "KEYCLOAK_URL": "http://localhost:8080",
                "KEYCLOAK_ADMIN": "admin",
                "KEYCLOAK_ADMIN_PASSWORD": "admin"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later