Overview
MCP Server with LangGraph supports pluggable authentication with two built-in providers:InMemory Provider
Development & TestingPre-defined users for local development. Fast, zero-config.
Keycloak SSO
ProductionEnterprise OpenID Connect/OAuth2 authentication. NEW in v2.1.0 🆕
Quick Start
InMemory Authentication (Development)
Perfect for local development and testing:alice- Premium user, admin of organization:acmebob- Standard user, member of organization:acmeadmin- System administrator
Keycloak SSO (Production) 🆕
NEW in v2.1.0: Enterprise-grade authentication with Keycloak.Features
OpenID Connect / OAuth2
OpenID Connect / OAuth2
Standards-compliant OIDC/OAuth2 flows with authorization code grant and refresh tokens.
Single Sign-On (SSO)
Single Sign-On (SSO)
Centralized identity management across all applications in your organization.
JWKS Verification
JWKS Verification
Public key verification without shared secrets. Token validation using Keycloak’s JWKS endpoint.
Token Refresh
Token Refresh
Automatic refresh token rotation for long-lived sessions without re-authentication.
Role Mapping
Role Mapping
Flexible role and group mapping from Keycloak to OpenFGA permissions.
Setup
1
Deploy Keycloak
- Docker: http://localhost:8080/admin (admin/admin)
- Kubernetes: Port-forward and access
2
Initialize Keycloak
Run the setup script to create realm and client:This creates:
- Realm:
mcp-server-langgraph - Client:
langgraph-client(confidential, OIDC) - Redirect URIs: Configured for your domain
3
Configure Environment
4
Test Authentication
Authentication Modes
Token Mode (Stateless)
- Overview
- Configuration
- Usage
JWT tokens issued by Keycloak or InMemory provider.Benefits:
- Stateless (no server-side session storage)
- Works with Cloud Run and other serverless platforms
- Lower infrastructure costs (no Redis required)
- Shorter token lifetimes (refresh required)
- No concurrent session limits
- Cannot revoke individual tokens
Session Mode (Stateful) 🆕
- Overview
- Configuration
- Usage
Server-side sessions with Redis or in-memory storage.Benefits:
- Longer session lifetimes (24+ hours)
- Sliding expiration windows
- Concurrent session limits per user
- Instant session revocation
- User session tracking
- Redis instance (production)
- Or in-memory storage (development only)
Security Best Practices
Production Checklist
Production Checklist
- Use Keycloak (not InMemory)
- Set
KEYCLOAK_VERIFY_SSL=true - Use strong JWT secret (256-bit):
openssl rand -base64 32 - Enable session mode with Redis for sensitive applications
- Configure appropriate token/session TTLs
- Enable HTTPS/TLS for all endpoints
- Store secrets in secret manager (not .env files)
- Rotate secrets regularly
- Monitor authentication failures
- Set up rate limiting
Token Security
Token Security
JWT Tokens:
- Use HS256 or RS256 algorithm
- Set reasonable expiration (1-4 hours)
- Include user ID and permissions
- Validate signature on every request
- Don’t store sensitive data in tokens
- Longer TTL than access tokens
- Rotate on refresh
- Revoke on logout
- Secure storage (HttpOnly cookies)
Session Security
Session Security
Redis Sessions:
- Use password authentication
- Enable TLS/SSL in production
- Set appropriate TTL (balance UX vs security)
- Implement sliding windows carefully
- Limit concurrent sessions per user
- Clear sessions on password change
- Monitor session creation rate
Keycloak Hardening
Keycloak Hardening
- Deploy with PostgreSQL (not H2)
- Enable SSL/TLS
- Use strong admin password
- Configure proper redirect URIs
- Enable brute force protection
- Set up backup and recovery
- Regular security updates
- Monitor admin console access
Troubleshooting
Invalid credentials
Invalid credentials
Symptom:
401 UnauthorizedSolutions:Token expired
Token expired
Symptom:
401 Unauthorized - Token expiredSolutions:- Request new token
- Use refresh token (Keycloak)
- Increase JWT_EXPIRATION_SECONDS
- Enable session mode with longer TTL
Keycloak connection refused
Keycloak connection refused
Symptom:
Connection refused to KeycloakSolutions:Session not found
Session not found
Symptom:
Session not found errorsSolutions:- Check Redis connectivity
- Verify SESSION_TTL_SECONDS not too short
- Check session was created successfully
- Verify session ID format
- Check Redis memory not full
Next Steps
Authorization
Configure OpenFGA fine-grained permissions
Keycloak Guide
Complete Keycloak integration guide
Session Management
Setup Redis session store
API Reference
Authentication API endpoints
Production Ready: With Keycloak SSO and Redis sessions, your authentication is enterprise-grade!