Keycloak
Keycloak is an open-source identity and access management solution that supports multiple protocols, including OpenID Connect (OIDC). As an OIDC provider, it implements the standard userinfo endpoint to retrieve user identity information.
Prerequisites
Although Keycloak can be installed in various ways (bare metal, kubernetes, etc.), for this guide, we'll use Docker for a quick and straightforward setup.
Run a Keycloak instance using Docker following the official documentation:
docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.2.4 start-dev
Get issuer URL
- Access the Keycloak Admin Console (http://localhost:8080/admin) and log in with these credentials:
- Username:
admin - Password:
admin
- Username:
- Navigate to "Realm settings" in the left menu
- Click "Endpoints" then "OpenID Endpoint Configuration"
- The
issuerfield in the JSON document will contain your issuer URL
For a realm named mcp-realm, the issuer URL should look like:
http://localhost:8080/realms/mcp-realm
Create a realm and test user
-
Create a new Realm:
- Click "Create Realm" in the top-left corner
- Enter a name in the "Realm name" field (e.g.,
mcp-realm) - Click "Create"
-
Create a test user:
- Click "Users" in the left menu
- Click "Create new user"
- Fill in the user details:
- Username: e.g.,
testuser - First name and Last name can be any values
- Username: e.g.,
- Click "Create"
- In the "Credentials" tab, set a password and uncheck "Temporary"
Configure scopes
If your MCP server requires custom scopes (e.g., for RBAC):
- In the Keycloak Admin Console, navigate to "Client scopes"
- Click "Create client scope"
- Define the scope name (e.g.,
create:todos,read:todos,delete:todos) - Assign these scopes to clients or roles as needed
Retrieving user identity
As an OIDC provider, Keycloak exposes a standard userinfo endpoint that allows applications to retrieve claims about the authenticated user.
To fetch an access token that can be used to access the userinfo endpoint, at least two scopes are required: openid and profile.
Register MCP client
While Keycloak supports dynamic client registration, its client registration endpoint does not support CORS, preventing most MCP clients from registering directly. Therefore, you'll need to manually register your client.
Register a client for VS Code
- In the Keycloak Admin Console, click "Clients" in the left menu
- Click "Create client"
- Fill in the client details:
- Client type: Select "OpenID Connect"
- Client ID: Enter a name (e.g.,
vscode) - Click "Next"
- On the "Capability config" page:
- Ensure "Standard flow" is enabled
- Click "Next"
- On the "Login settings" page:
- Add
http://127.0.0.1/*to "Valid redirect URIs" - Add
https://vscode.dev/redirectto "Valid redirect URIs" - Click "Save"
- Add
- Copy the "Client ID" for later use