Skip to main content

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

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 access
  • premium - Premium tier features
  • user - Standard user access

Example


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

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.

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

Supported Providers

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:

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

Google:
GitHub:
Custom OIDC:

Provider Examples

Google

GitHub

Custom

Configuration File

The script can use /config/oidc_providers.yaml for managing multiple OIDC providers. See Configuration Files Reference.

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

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

Ensure Keycloak and Kong are accessible from the script’s execution environment. Check service names and ports in Kubernetes.
Verify Keycloak is returning valid JWKs:
Create the Kong consumer first:

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

See Also