Skip to main content
IBM i HTTP authentication enables secure, token-based access to the MCP server with per-user connection pooling. Clients authenticate with IBM i credentials to obtain Bearer tokens for subsequent API requests.
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
When to use simpler auth:
  • Development: Use shared DB2i_USER/DB2i_PASS credentials (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

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

Common Pitfall: When using IBM i HTTP authentication, you may encounter validation errors about DB2i_USER and DB2i_PASS even though the Bearer token provides authentication.Solution: Either omit these variables entirely from your .env file, or set them to placeholder values like TOKEN_AUTH.Why this happens: The validation schema requires these fields to be either undefined or have non-empty values. Empty strings (DB2i_USER="") fail validation. When using token authentication, the Bearer token supplies user credentials, so DB2i_USER and DB2i_PASS are not used.
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:
Store the secrets/ directory outside of version control. Add it to your .gitignore file.
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:
Critical Security Step: The private key (private.pem) must be protected. Anyone with access to this file can decrypt client credentials.
5

Configure Environment Variables

Add the keypair paths to your .env file:
Key Configuration:
  • IBMI_AUTH_KEY_ID: Identifier for this keypair (used for key rotation)
  • IBMI_AUTH_PRIVATE_KEY_PATH: Path to your private key file
  • IBMI_AUTH_PUBLIC_KEY_PATH: Path to your public key file
How the Encryption Works:
  1. Client requests public key from server (/api/v1/auth/public-key)
  2. Client generates a random AES-256-GCM session key
  3. Client encrypts IBM i credentials with the session key
  4. Client encrypts the session key with the server’s RSA public key
  5. Server decrypts the session key using its RSA private key
  6. Server decrypts the credentials using the session key
  7. 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:
Start the Server:
You should see:
Production HTTPS: In production, ensure IBMI_AUTH_ALLOW_HTTP=false and use HTTPS. The server will reject HTTP authentication requests for security.

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.
Quick Setup: The one-liner eval $(node get-access-token.js --quiet) does everything:
  1. Reads your IBM i credentials from .env
  2. Encrypts and sends them to the MCP server
  3. Receives the Bearer token
  4. Automatically sets export IBMI_MCP_ACCESS_TOKEN=your-token
  5. Token is now available in your shell session
Use this token with any MCP client by including the header: Authorization: Bearer $IBMI_MCP_ACCESS_TOKEN
Example Output:
Common Options:
For advanced use cases, the script supports additional configuration:Example with advanced options:
The script automatically:
  • Loads IBM i credentials from .env with 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)
View Source: See the full implementation at get-access-token.js

Using the Token with MCP Clients

Once you have a token, configure your MCP client:

Security Best Practices

  • 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
  • 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
  • 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
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
Update IBMI_AUTH_PRIVATE_KEY_PATH to reference the mounted secret location.
  • HTTPS Only: Never allow IBMI_AUTH_ALLOW_HTTP=true in 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

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.
Possible causes:
  • Token has expired (check IBMI_AUTH_TOKEN_EXPIRY_SECONDS)
  • Token was obtained from a different server instance
  • Authorization header missing or malformed
Check:
Symptom: Server fails to start or auth requests fail with encryption errors.Solutions:
  • Verify file paths in .env are correct
  • Check file permissions: ls -la secrets/
  • Ensure private key is valid: openssl rsa -in secrets/private.pem -check
  • Regenerate keypair if corrupted
Symptom: “Max concurrent sessions reached” errors.Solutions:
  • Increase IBMI_AUTH_MAX_CONCURRENT_SESSIONS
  • Reduce IBMI_AUTH_TOKEN_EXPIRY_SECONDS to 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: For detailed API specifications, see the API Reference.

Next Steps

Configuration Reference

Explore all configuration options for the MCP server

Client Integrations

Connect Claude Desktop, VSCode, Cursor, and other MCP clients

SQL Tools

Create custom SQL operations for authenticated users

Production Deployment

Deploy with Docker, HTTPS, and secrets management