When to use IBM i authentication:
- Multi-user environments: Each user gets their own connection pool with their credentials
- Production deployments: Token-based auth with automatic expiry and session management
- Enhanced security: Credentials encrypted during transmission using RSA/AES
- Audit trails: Per-user tracking of database operations
- Development: Use shared
DB2i_USER/DB2i_PASScredentials (no token auth needed) - Single-user scenarios: JWT or OAuth may be sufficient
How It Works
Authentication Flow
Key Features:- End-to-end encryption: Credentials never transmitted in plain text
- Per-user pools: Each token gets its own dedicated DB2 connection pool
- Token lifecycle: Automatic expiry and cleanup of stale sessions
- Key rotation: Support for multiple keypairs for zero-downtime rotation
Configuration
Environment Variables
| Variable | Description | Default | Required |
|---|---|---|---|
MCP_AUTH_MODE | Must be set to ibmi | none | ✅ Yes |
IBMI_HTTP_AUTH_ENABLED | Enable auth endpoints | false | ✅ Yes |
IBMI_AUTH_KEY_ID | Identifier for RSA keypair | (none) | ✅ Yes |
IBMI_AUTH_PRIVATE_KEY_PATH | Path to RSA private key | (none) | ✅ Yes |
IBMI_AUTH_PUBLIC_KEY_PATH | Path to RSA public key | (none) | ✅ Yes |
IBMI_AUTH_ALLOW_HTTP | Allow HTTP (dev only) | false | No |
IBMI_AUTH_TOKEN_EXPIRY_SECONDS | Token lifetime | 3600 (1hr) | No |
IBMI_AUTH_CLEANUP_INTERVAL_SECONDS | Cleanup interval | 300 (5min) | No |
IBMI_AUTH_MAX_CONCURRENT_SESSIONS | Max sessions | 100 | No |
Complete Reference: See the IBM i Authentication Settings section in the Configuration Reference for all available environment variables and their defaults.
Db2i Credentials: Important Notes
- Option 1: Omit Variables (Recommended)
- Option 2: Placeholder Values
Reference: See GitHub Issue #77 for the original discussion of this validation behavior.
Setup: RSA Encryption Keys
IBM i authentication requires RSA keypairs to protect credentials during transmission. The authentication flow uses RSA and AES encryption to securely exchange IBM i credentials between clients and the server.1
Create Secrets Directory
Create a dedicated directory for storing encryption keys:
2
Generate RSA Private Key
Generate a 2048-bit RSA private key:What this does:
- Creates a new RSA private key with 2048-bit encryption strength
- Saves it to
secrets/private.pem - This key will be used by the server to decrypt credentials sent by clients
3
Extract Public Key
Extract the corresponding public key from the private key:What this does:
- Derives the public key from your private key
- Saves it to
secrets/public.pem - Clients use this public key to encrypt credentials before sending them to the server
4
Set Secure File Permissions
Restrict access to your private key:
5
Configure Environment Variables
Add the keypair paths to your Key Configuration:
.env file:IBMI_AUTH_KEY_ID: Identifier for this keypair (used for key rotation)IBMI_AUTH_PRIVATE_KEY_PATH: Path to your private key fileIBMI_AUTH_PUBLIC_KEY_PATH: Path to your public key file
- Client requests public key from server (
/api/v1/auth/public-key) - Client generates a random AES-256-GCM session key
- Client encrypts IBM i credentials with the session key
- Client encrypts the session key with the server’s RSA public key
- Server decrypts the session key using its RSA private key
- Server decrypts the credentials using the session key
- Server authenticates against IBM i and issues an access token
Key Rotation: To rotate keys, generate a new keypair with a different
IBMI_AUTH_KEY_ID. The server can support multiple keypairs simultaneously, allowing gradual migration without service interruption.Start the Server
After configuring IBM i authentication and generating your RSA keys, start the MCP server with authentication enabled. Complete Configuration Example:- NPM Package
- Build from Source
Usage Examples
Getting an Access Token
The repository includes a helper script to obtain authentication tokens:get-access-token.js
Script Location: The
get-access-token.js script is included in the root of the GitHub repository. Clone the repository or download this file to use the token helper.What it does: This script authenticates with your IBM i credentials and generates a Bearer token, then outputs a command to set the IBMI_MCP_ACCESS_TOKEN environment variable.| Option | Short | Description | Default |
|---|---|---|---|
--user | -u | IBM i username | DB2i_USER from .env |
--password | -p | IBM i password | DB2i_PASS from .env |
--host | -h | IBM i host address | DB2i_HOST from .env |
--server | MCP server address | localhost | |
--port | MCP server port | 3010 | |
--https | Use HTTPS instead of HTTP | HTTP | |
--verbose | -v | Enable verbose output with metadata | (quiet mode) |
--quiet | -q | Output only export command for shell eval | (normal mode) |
Advanced Options
Advanced Options
For advanced use cases, the script supports additional configuration:
Example with advanced options:
| Option | Description |
|---|---|
--duration | Token duration in seconds |
--pool-start | Initial connection pool size |
--pool-max | Maximum connection pool size |
--public-key-path | Path to PEM-encoded server public key (skips HTTP fetch) |
--key-id | Key identifier when using --public-key-path |
- Loads IBM i credentials from
.envwith CLI fallback - Fetches the server’s public key (or uses local file with
--public-key-path) - Encrypts credentials client-side using RSA/AES
- Requests an access token from the MCP server
- Outputs the token (or export command in quiet mode)
get-access-token.js
Using the Token with MCP Clients
Once you have a token, configure your MCP client:- Python (Agno)
- Python (MCP SDK)
- Claude Desktop
- VSCode
Security Best Practices
Production Deployment
Production Deployment
- Always use HTTPS: Set
IBMI_AUTH_ALLOW_HTTP=false - Rotate keys regularly: Generate new keypairs every 90-180 days
- Use strong key sizes: 2048-bit minimum, 4096-bit recommended for high-security environments
- Monitor key access: Enable file auditing on the
secrets/directory - Backup keys securely: Store encrypted backups in a secrets management system
File Permissions
File Permissions
- Private key:
chmod 600 secrets/private.pem(owner read/write only) - Public key:
chmod 644 secrets/public.pem(world-readable is safe) - Secrets directory:
chmod 700 secrets/(owner access only) - Owner: Ensure files are owned by the service account running the MCP server
Version Control
Version Control
- Never commit keys: Add
secrets/to.gitignore - Never commit
.env: Environment files often contain paths to secrets - Use environment-specific keys: Different keypairs for dev/staging/production
- Document setup process: Include key generation in deployment documentation
Secrets Management
Secrets Management
For production environments, consider using a secrets management system:
- AWS Secrets Manager: Store keys in encrypted AWS vault
- HashiCorp Vault: Centralized secrets management with audit logs
- Azure Key Vault: Microsoft’s cloud-based secrets storage
- Kubernetes Secrets: For containerized deployments
IBMI_AUTH_PRIVATE_KEY_PATH to reference the mounted secret location.Network Security
Network Security
- HTTPS Only: Never allow
IBMI_AUTH_ALLOW_HTTP=truein production - Firewall Rules: Restrict access to auth endpoints
- Rate Limiting: Configure rate limits on authentication endpoints
- IP Whitelisting: Restrict auth access to known client IPs when possible
Troubleshooting
Validation Error: DB2i_USER and DB2i_PASS Required
Validation Error: DB2i_USER and DB2i_PASS Required
Symptom: Server fails to start with error requiring
DB2i_USER and DB2i_PASS even though you’re using token authentication.Solution: Either completely omit these variables from your .env file, or set them to placeholder values like TOKEN_AUTH. Do not use empty strings (DB2i_USER="").See the Configuration section above for detailed examples.Why: Validation requires these fields to be either undefined or have non-empty values. When using token auth, credentials come from the Bearer token, not environment variables.401 Unauthorized When Using Token
401 Unauthorized When Using Token
Encryption Key Errors
Encryption Key Errors
Symptom: Server fails to start or auth requests fail with encryption errors.Solutions:
- Verify file paths in
.envare correct - Check file permissions:
ls -la secrets/ - Ensure private key is valid:
openssl rsa -in secrets/private.pem -check - Regenerate keypair if corrupted
Connection Pool Exhaustion
Connection Pool Exhaustion
Symptom: “Max concurrent sessions reached” errors.Solutions:
- Increase
IBMI_AUTH_MAX_CONCURRENT_SESSIONS - Reduce
IBMI_AUTH_TOKEN_EXPIRY_SECONDSto clean up idle sessions faster - Monitor active sessions and adjust cleanup interval
Authentication Endpoints
When enabled (IBMI_HTTP_AUTH_ENABLED=true), the server provides these endpoints:
| Endpoint | Method | Description |
|---|---|---|
/api/v1/auth/public-key | GET | Retrieve server’s RSA public key for client-side encryption |
/api/v1/auth | POST | Authenticate with encrypted IBM i credentials and receive Bearer token |
/healthz | GET | Health check endpoint (no authentication required) |