Skip to main content

MCP server for KeyCloak Admin REST API via Service Account

Project description

keycloak-mcp

English | 日本語

MCP (Model Context Protocol) server for KeyCloak Admin REST API.

Uses Client Credentials Grant (Service Account) — no user password or TOTP required. Infinispan-safe: does not create user sessions or use the userinfo endpoint.

Features

User Management

Tool Description
count_users Get total user count in the realm
search_users Search users by username, email, or name
get_user Get detailed user information by username
reset_password Reset a user's password
reset_passwords_batch Reset passwords for multiple users from CSV
get_user_sessions Get active sessions for a user

Group Management

Tool Description
list_user_groups List groups a user belongs to
list_users_by_group List all members of a group

Security Monitoring

Tool Description
get_brute_force_status Check if a user is locked by brute force detection
get_login_failures_by_ip Login failure statistics by source IP

Event Analytics

Tool Description
get_events Get KeyCloak events with filters (type, user, date)
get_login_stats Login success/failure statistics with pagination
get_login_stats_by_hour Login statistics by hour (local time)
get_login_stats_by_client Login statistics by client (SP)
get_password_update_events Password update event history

Session & Client

Tool Description
get_session_stats Active session count per client
get_client_sessions Active sessions for a specific client
list_clients List all SAML/OIDC clients
get_realm_roles List all realm-level roles

Setup

# uv
uv pip install keycloak-mcp

# pip
pip install keycloak-mcp

Or from source:

git clone https://github.com/shigechika/keycloak-mcp.git
cd keycloak-mcp

# uv
uv sync

# pip
pip install -e .

Configuration

Set the following environment variables:

Variable Description Default
KEYCLOAK_URL KeyCloak base URL (e.g., https://sso.example.com) required
KEYCLOAK_REALM Realm name master
KEYCLOAK_CLIENT_ID Service Account client ID required
KEYCLOAK_CLIENT_SECRET Client secret required

KeyCloak Client Setup

  1. Create a new client in KeyCloak Admin Console
  2. Enable Client authentication and Service account roles
  3. Assign realm roles: view-users, view-events, view-clients, manage-users (for password reset)

Usage

Claude Code

Add to .mcp.json:

{
  "mcpServers": {
    "keycloak-mcp": {
      "type": "stdio",
      "command": "keycloak-mcp",
      "env": {
        "KEYCLOAK_URL": "https://sso.example.com",
        "KEYCLOAK_CLIENT_ID": "keycloak-mcp",
        "KEYCLOAK_CLIENT_SECRET": ""
      }
    }
  }
}

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "keycloak-mcp": {
      "command": "keycloak-mcp",
      "env": {
        "KEYCLOAK_URL": "https://sso.example.com",
        "KEYCLOAK_CLIENT_ID": "keycloak-mcp",
        "KEYCLOAK_CLIENT_SECRET": ""
      }
    }
  }
}

Direct Execution

export KEYCLOAK_URL=https://sso.example.com
export KEYCLOAK_CLIENT_ID=keycloak-mcp
export KEYCLOAK_CLIENT_SECRET=your-secret
keycloak-mcp

Development

git clone https://github.com/shigechika/keycloak-mcp.git
cd keycloak-mcp

# uv
uv sync --dev
uv run pytest -v
uv run ruff check .

# pip
python3 -m venv .venv
.venv/bin/pip install -e . && .venv/bin/pip install pytest pytest-cov respx ruff
.venv/bin/pytest -v
.venv/bin/ruff check .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keycloak_mcp-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keycloak_mcp-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file keycloak_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: keycloak_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for keycloak_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2914d0eeda980981a445530f69733a6079c35b2a4b852d5f44eae6d578e8d94
MD5 c6c842a0eb336444050b6c11ae0e45f4
BLAKE2b-256 1aae789885a04affc50bc90ce1e2d6f415b6bae1c2ff2c8ff5fda4b28aa158c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for keycloak_mcp-0.1.0.tar.gz:

Publisher: release.yml on shigechika/keycloak-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keycloak_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: keycloak_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for keycloak_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b00f4be161f1538adfaf7bd381b9f4f746ccdf4ebe18f95615b76677eb989335
MD5 442f234fc95568e4e36e07a04d2f54c3
BLAKE2b-256 664052eaa389978f44bc6b019ebadf42e19fdb6b34b7eb63ecfdcd7bf17625d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for keycloak_mcp-0.1.0-py3-none-any.whl:

Publisher: release.yml on shigechika/keycloak-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page