Overview
The MCP Server with LangGraph provides automated setup scripts for configuring Keycloak, identity federation, and JWT management. These scripts streamline deployment and ensure consistent configuration across environments.All setup scripts are located in the
/scripts/setup/ directory and require appropriate environment variables to be configured.setup_keycloak.py
Initializes Keycloak with realm, clients, users, and OpenFGA synchronization.Purpose
Automates the initial Keycloak setup for the MCP Server with LangGraph, including:- Realm creation (
langgraph-agent) - Client configuration with service accounts enabled
- Default test users (alice, bob, admin)
- Role mappings (admin, premium, user)
- Optional OpenFGA tuple synchronization
Usage
Environment Variables
Required Variables
Required Variables
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_SERVER_URL | http://localhost:8082 | Keycloak server URL |
KEYCLOAK_ADMIN_USERNAME | admin | Keycloak admin username |
KEYCLOAK_ADMIN_PASSWORD | admin | Keycloak admin password |
KEYCLOAK_REALM | langgraph-agent | Realm name to create/configure |
Optional Variables
Optional Variables
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_CLIENT_ID | langgraph-client | OAuth2/OIDC client ID |
KEYCLOAK_CLIENT_SECRET | (generated) | Client secret (auto-generated if not provided) |
SYNC_TO_OPENFGA | false | Enable automatic OpenFGA tuple creation |
OPENFGA_API_URL | - | OpenFGA API endpoint (if syncing) |
What It Creates
1
Realm Setup
Creates the
langgraph-agent realm with:- Access token lifespan: 15 minutes (900s)
- Refresh token lifespan: 30 minutes (1800s)
- Service account refresh token: 30 days (2592000s)
- Login and registration enabled
2
Client Configuration
Creates OAuth2/OIDC client with:
- Client ID:
langgraph-client - Service accounts enabled (for service principals)
- Direct access grants enabled
- Standard flow enabled
- Client credentials flow enabled
3
Default Users
Creates test users:
- alice (password:
alice123) - Premium user - bob (password:
bob123) - Standard user - admin (password:
admin123) - Administrator
4
Role Definitions
Creates client roles:
admin- Full administrative accesspremium- Premium tier featuresuser- Standard user access
Example
Related ADRs
setup_ldap_federation.py
Configures Keycloak to federate users from LDAP or Active Directory.Purpose
Enables enterprise LDAP/Active Directory integration where users authenticate against their existing directory service, and Keycloak issues JWTs. This allows centralized identity management without duplicating user databases.Usage
Environment Variables
Keycloak Connection
Keycloak Connection
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_SERVER_URL | http://localhost:8082 | Keycloak server URL |
KEYCLOAK_ADMIN_USERNAME | admin | Admin username |
KEYCLOAK_ADMIN_PASSWORD | admin | Admin password |
KEYCLOAK_REALM | langgraph-agent | Target realm |
LDAP Connection (Required)
LDAP Connection (Required)
| Variable | Required | Description |
|---|---|---|
LDAP_CONNECTION_URL | ✅ | LDAP server URL (e.g., ldap://ad.example.com:389) |
LDAP_BIND_DN | ✅ | Service account DN for binding |
LDAP_BIND_PASSWORD | ✅ | Service account password |
LDAP_USERS_DN | ✅ | Base DN for user search |
LDAP Configuration (Optional)
LDAP Configuration (Optional)
| Variable | Default (AD) | Default (LDAP) | Description |
|---|---|---|---|
LDAP_USERNAME_ATTRIBUTE | sAMAccountName | uid | Username attribute |
LDAP_USER_OBJECT_CLASSES | person,organizationalPerson,user | inetOrgPerson,organizationalPerson | User object classes |
LDAP_VENDOR | ad | other | LDAP vendor (ad/other) |
What It Configures
User Federation
- LDAP user provider configuration
- Attribute mapping (email, name, phone, etc.)
- Username and UUID mapping
- Read-only federation (users managed in LDAP)
Group Synchronization
- LDAP group mapper
- Group hierarchy preservation
- Automatic role assignment
- Periodic sync (hourly changed, daily full)
Attribute Mappers
- Standard attributes (email, firstName, lastName)
- Extended attributes (department, title, phone)
- Custom mappings from
/config/ldap_mappers.yaml
Sync Schedule
- Full sync: Every 24 hours
- Changed sync: Every hour
- Batch size: 1000 users
- Connection pooling enabled
Active Directory Example
Generic LDAP Example
Configuration File
The script uses/config/ldap_mappers.yaml for attribute mapping configuration. See Configuration Files Reference for details.
Related ADRs
setup_saml_idp.py
Configures SAML 2.0 identity provider integration (e.g., ADFS, Okta, Azure AD).Purpose
Enables SAML-based Single Sign-On (SSO) from enterprise identity providers. Users authenticate via their corporate SSO portal, and Keycloak issues JWTs for MCP Server access.Usage
Environment Variables
Keycloak Connection
Keycloak Connection
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_SERVER_URL | http://localhost:8082 | Keycloak server URL |
KEYCLOAK_ADMIN_USERNAME | admin | Admin username |
KEYCLOAK_ADMIN_PASSWORD | admin | Admin password |
KEYCLOAK_REALM | langgraph-agent | Target realm |
SAML Configuration (Required)
SAML Configuration (Required)
| Variable | Required | Description |
|---|---|---|
SAML_ALIAS | ✅ | Identity provider alias (e.g., adfs, okta) |
SAML_SSO_URL | ✅ | SAML SSO endpoint URL |
SAML_ENTITY_ID | ✅ | Identity provider entity ID |
SAML_CERTIFICATE | ✅ | X.509 certificate (PEM format) |
Optional Settings
Optional Settings
| Variable | Default | Description |
|---|---|---|
SAML_NAME_ID_FORMAT | urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress | Name ID format |
SAML_WANT_ASSERTIONS_SIGNED | true | Require signed assertions |
SAML_FORCE_AUTHN | false | Force re-authentication |
Supported Providers
- ADFS
- Okta
- Azure AD
What It Creates
- SAML identity provider configuration in Keycloak
- Attribute mappers (email, firstName, lastName, roles)
- SP metadata for configuration in external IdP
- Trust relationship between Keycloak and SAML IdP
Testing
After configuration, test SAML authentication:Related ADRs
setup_oidc_idp.py
Configures OpenID Connect identity provider integration (Google, GitHub, custom OIDC providers).Purpose
Enables OAuth 2.0 / OpenID Connect based authentication from social providers (Google, GitHub) or enterprise OIDC providers (Auth0, Keycloak).Usage
Environment Variables
Keycloak Connection
Keycloak Connection
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_SERVER_URL | http://localhost:8082 | Keycloak server URL |
KEYCLOAK_ADMIN_USERNAME | admin | Admin username |
KEYCLOAK_ADMIN_PASSWORD | admin | Admin password |
KEYCLOAK_REALM | langgraph-agent | Target realm |
Provider-Specific Variables
Provider-Specific Variables
Google:GitHub:Custom OIDC:
Provider Examples
GitHub
Custom
Configuration File
The script can use/config/oidc_providers.yaml for managing multiple OIDC providers. See Configuration Files Reference.
Related ADRs
update_kong_jwks.py
Updates Kong Gateway with the latest Keycloak JWKS (JSON Web Key Set) for JWT validation.Purpose
Synchronizes Keycloak’s public keys with Kong Gateway to enable JWT validation. This script is typically run as a Kubernetes CronJob to automatically rotate keys.Usage
Environment Variables
| Variable | Default | Description |
|---|---|---|
KEYCLOAK_SERVER_URL | http://keycloak:8080 | Keycloak server URL |
KEYCLOAK_REALM | langgraph-agent | Realm name |
KONG_ADMIN_URL | http://kong-admin:8001 | Kong Admin API URL |
KONG_CONSUMER_NAME | jwt-consumer | Kong consumer for JWT plugin |
What It Does
1
Fetch JWKS
Retrieves the current JSON Web Key Set from Keycloak’s OIDC discovery endpoint:
2
Convert to PEM
Converts JWK format to PEM format required by Kong’s JWT plugin.
3
Update Kong Consumer
Updates the Kong consumer’s public key via Admin API:
4
Verify
Tests JWT validation to ensure the update was successful.
Automated Updates
Deploy as a Kubernetes CronJob for automatic key rotation:Troubleshooting
Connection Refused
Connection Refused
Ensure Keycloak and Kong are accessible from the script’s execution environment. Check service names and ports in Kubernetes.
Invalid Key Format
Invalid Key Format
Verify Keycloak is returning valid JWKs:
Kong Consumer Not Found
Kong Consumer Not Found
Create the Kong consumer first:
Related ADRs
Common Patterns
Prerequisites Check
All scripts include health checks for dependencies:Idempotent Execution
Scripts can be run multiple times safely:- Existing resources are updated, not duplicated
- Configuration changes are applied incrementally
- No data loss on re-runs
Error Handling
All scripts provide detailed error messages:Dry Run Mode
Some scripts support dry-run for validation:Best Practices
Use Environment Files
Secrets Management
Never commit credentials to git. Use:
- Kubernetes Secrets
- External Secrets Operator
- Infisical
- Vault
Script Chaining
Version Control
Track configuration files in git:
/config/ldap_mappers.yaml/config/oidc_providers.yaml/config/role_mappings.yaml