Loading Your Configuration
The server loads one.env file at startup: the file named by the MCP_SERVER_CONFIG environment variable, otherwise .env in the directory the server is started from. Parent directories are not searched.
- NPM Package
- Build from Source
MCP_SERVER_CONFIG resolves from the working directory. If the file does not exist, the server prints a warning and falls back to .env in the working directory.--transport http) override both.Minimal Working Configuration
Start here if you’re setting up for the first time. This minimal configuration is sufficient to get the server running:What do these variables do?
What do these variables do?
Quick Setup
Create your configuration file from the template:.env with your IBM i connection details using the minimal configuration above.
Core Server Configuration
Below is the reference for core server configuration options. Each section includes detailed explanations, examples, and guidance on when to use specific settings.Server Transport
How clients connect to your MCP server. The transport type determines whether clients connect via standard input/output (stdio) for local processes or HTTP for remote/web-based connections. Most production deployments use HTTP transport for flexibility and multi-client support.- HTTP Transport (Recommended)
- Stdio Transport
TLS Listener
By default the server listens on plain HTTP. WithMCP_TLS_CERT_FILE and MCP_TLS_KEY_FILE both set, it listens with HTTPS on the same port and needs no TLS-terminating proxy. This works in every auth mode.
- Setting only one of the two stops startup, as does a file that cannot be read or that does not hold a certificate and its key.
- The files are read once at startup. Restart the server after renewing the certificate.
- A plain-HTTP request to a TLS listener gets no answer. Health checks must use
https; the container image’s built-in health check does not (see Docker). - The built-in IBM i sign-on requires the TLS listener unless
MCP_HTTP_HOSTis a loopback address.
Behind a Reverse Proxy
By default the server ignoresX-Forwarded-For and X-Forwarded-Proto: any caller can write those headers. The client address is the TCP peer.
Behind a reverse proxy or ingress, set MCP_TRUSTED_PROXIES to the proxy’s address, as a comma-separated list of IP addresses and CIDR ranges:
- the client address from
X-Forwarded-For: the right-most entry that is not itself inside the list. Entries further left are whatever the caller sent and are not read. With several proxies in a row, list all of them, or every client appears at the address of the proxy before the last. An entry that is not a plain IP address (one with a port, for example) cannot be used, and the proxy’s own address is taken instead.X-Real-IPis not read. - the scheme from
X-Forwarded-Proto. It is used by the HTTPS check on/api/v1/auth(deprecated IBM i authentication). For a request from a listed proxy only this header counts, also when the proxy’s own connection to the server uses TLS (MCP_TLS_CERT_FILE): the client may have reached the proxy in clear.
/api/v1/auth refuses every request with HTTPS/TLS is required for authentication endpoints.
The built-in IBM i sign-on is stricter: its sign-in page and token endpoint refuse a request that carries X-Forwarded-For, Forwarded or X-Real-IP without coming from a listed proxy, and a request from a listed proxy without a usable X-Forwarded-For entry.
Protocol Versions and Sessions
The server is stateless. One endpoint serves MCP protocol revision2026-07-28 and clients on earlier revisions, over both HTTP and stdio. It issues no Mcp-Session-Id and keeps no per-client state between requests, so there is nothing to configure. The MCP endpoint accepts POST only; GET and DELETE return 405.
Rate Limiting (HTTP Only)
Control request rate limiting for the HTTP transport. Rate limiting prevents abuse and manages server load. For agentic AI workflows that make many parallel tool calls (e.g., Agno AgentOS), you can increase the limit or disable rate limiting entirely.- Default
- Agentic Workflows
- Disabled
- No authentication: every request counts against the client address.
- With authentication (
oauthoribmi): an authenticated request counts against the token’s subject (the client id when the token has no subject), so users behind one address do not share a budget. A request that authentication refuses (401/403) counts against the client address, as do fetches of the OAuth metadata and, with the built-in IBM i sign-on, requests to its sign-in page, token endpoint and client registration. Once an address has used up its budget, further requests from it that authentication refuses get429until the window ends. Requests with a valid token are still served: they never count against the address. POST /api/v1/auth(deprecated IBM i authentication) has its own fixed budget of 10 requests per minute per client address. It followsMCP_RATE_LIMIT_ENABLEDandMCP_RATE_LIMIT_SKIP_DEV.
MCP_TRUSTED_PROXIES to the proxy’s address to use the address the proxy reports. See Behind a Reverse Proxy.Connection Pool Timeouts
OAUTH_IDLE_CLOSE_MINUTES, and a statement is abandoned after a fixed 120 seconds.- Default
- Cloud Deployment
- Disabled
max(10s, timeout/2). When a pool exceeds the idle timeout, it is closed automatically. The next query triggers a transparent re-initialization through the existing lazy-init path — no manual intervention needed. When a statement times out, the pool is marked unhealthy (/healthz reports degraded) and closed, and it is re-created on the next request. Other statements running on that pool fail at once with Request cancelled: connection pool '<id>' was closed while the statement was running. Such a statement had already been sent to IBM i and may or may not have completed, so check before running it again.With the SSH transport, a timed-out query closes the shared SSH session (it has a single SQL job, which may be stuck). In-flight queries on it fail, and the next request re-creates the session.- Lost connections. When a pool has no usable connection left (IBM i IPL, Mapepire restart, network reset), the server re-initializes it once and runs the statement. If that fails the error is
Connection to IBM i was lost and could not be re-established on pool '<id>'. - Rejected sign-on. After IBM i rejects the user or password, the server does not attempt another sign-on with those credentials for 60 seconds, so that repeated tool calls do not disable the user profile. Calls in that time fail with
IBM i sign-on failed: the system rejected the user or password. .... Other initialization failures (host unreachable, for example) are retried after 5 seconds. Both intervals are fixed. Pools that use the same host, user and password sign on one at a time, so several of them starting together make one attempt, and a connection that a pool adds later under load is held back by the same intervals. - Pool start-up. A pool opens one connection first and the remaining starting connections only after it succeeds.
Pagination
Controls the per-fetch page size and the safety ceiling used when SQL tools paginate large result sets.fetchAllRows: true tools and the built-in execute_sql tool share these values. YAML tools override per-call via rowsToFetch; these env vars govern the defaults.
IBMI_PAGINATION_MAX_ROWS; LLM-facing deployments rarely should.Authentication Configuration
Authentication applies to the HTTP transport. The stdio transport does not authenticate.Choosing an Authentication Mode
Local development and stdio → 'none'
Local development and stdio → 'none'
DB2i_USER credentials.With IBM i credentials configured, an unauthenticated HTTP server only starts on a loopback bind (MCP_HTTP_HOST=127.0.0.1, the default) unless you set MCP_ALLOW_UNAUTHENTICATED_HTTP=true.Users with IBM i profiles → 'oauth', built-in sign-on
Users with IBM i profiles → 'oauth', built-in sign-on
OAUTH_ISSUER_URL unset the server is its own OAuth 2.1 authorization server. Users sign on at a page it serves with their IBM i user profile and password, and every tool runs SQL as that user. There is no service account, and DB2i_PASS must be unset.Setup: MCP_RESOURCE_URL, DB2i_HOST, TLS for the server, and a way to verify the Mapepire certificate. See Built-in IBM i Sign-On.Callers from your identity provider → 'oauth', external issuer
Callers from your identity provider → 'oauth', external issuer
OAUTH_ISSUER_URL set the server acts as an OAuth 2.1 resource server as defined by the MCP authorization specification. It verifies JWT access tokens issued by your authorization server (identity provider) and publishes the metadata clients need to find that server.A token identifies the caller only. All SQL runs as the DB2i_USER service account.Setup: MCP_RESOURCE_URL and OAUTH_ISSUER_URL. See External Authorization Server.IBM i token authentication → 'ibmi' (deprecated)
IBM i token authentication → 'ibmi' (deprecated)
oauth replaces it. See IBM i Authentication.Authentication Mode Configuration
MCP_AUTH_MODE, a non-numeric port, and so on): stderr names the variables at fault and the process exits with code 1.
- No Authentication
- OAuth: IBM i Sign-On (Recommended)
- OAuth: External Issuer
- IBM i Authentication (Deprecated)
OAuth Settings
Used whenMCP_AUTH_MODE=oauth. OAUTH_ISSUER_URL selects the flavour.
OAUTH_ISSUER_URL set):
OAUTH_ISSUER_URL unset). OAUTH_JWKS_URI and OAUTH_AUDIENCE stop startup in this flavour; OAUTH_REQUIRED_SCOPES has no effect.
DB2i_HOST, refuses DB2i_PASS and DB2i_SSH_KEY, limits DB2i_JDBC_OPTIONS to a short list of keys, and needs the TLS listener unless MCP_HTTP_HOST is a loopback address. With a loopback MCP_HTTP_HOST and a public MCP_RESOURCE_URL, MCP_TRUSTED_PROXIES must hold a loopback entry (127.0.0.0/8 or ::1) for the proxy on the same host, whether or not the server has a TLS listener. It works with mapepire-server 2.x and requires no particular version.
OAuth Authentication Guide →
IBM i Authentication Settings
IBM i Authentication Guide →
Setting Up RSA Encryption Keys
The deprecated IBM i authentication mode 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.Create Secrets Directory
Generate RSA Private Key
- 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
Extract Public Key
- 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
Set Secure File Permissions
Configure Environment Variables
.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
IBMI_AUTH_KEY_ID, and restart the server. The server loads a single active keypair, so clients must fetch the new public key after rotation.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
- 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.IBM i Database Connection
Connect to IBM i DB2 for i databases via Mapepire. These settings configure the connection to your IBM i system through the Mapepire database server. The server uses these credentials to execute SQL tools and access DB2 for i data. All connections are pooled. SQL runs with these credentials unless users sign on with their own IBM i profile (the built-in IBM i sign-on ofMCP_AUTH_MODE=oauth, or the deprecated IBM i authentication mode).
Connection Settings
- Development
- Production
DB2i_HOST, DB2i_PORT and DB2i_JDBC_OPTIONS are used. DB2i_PASS and DB2i_SSH_KEY stop startup and DB2i_USER is ignored. The Mapepire certificate is verified against DB2i_SERVER_CERT_FILE, DB2i_CA_FILE or Node.js’s trust store, unless DB2i_IGNORE_UNAUTHORIZED=true is set explicitly: users’ passwords are then sent to a server whose identity is not checked, and a warning is logged at startup. The default of true in the table above does not apply to this mode, and DB2i_IGNORE_UNAUTHORIZED=true together with either certificate file stops startup (see OAuth Settings). DB2i_HOST must be a host name or an IPv4 address. DB2i_JDBC_OPTIONS may hold only naming, libraries, date format, date separator, time format, time separator, decimal separator, transaction isolation and access; the server adds prompt=false itself.- User profile must have appropriate database authorities
- Access to QSYS2 system services
- Mapepire daemon must be running on the specified port (not needed with the SSH transport)
SSH Transport
Connect over SSH instead of the Mapepire daemon. The server opens an SSH session to the IBM i and startsmapepire-server on demand through an SSH exec channel (mapepire-js ssh-single transport). No Mapepire daemon or port 8076 is needed.
A connection uses SSH when it has an SSH key. A password means the Mapepire daemon. There is no separate switch:
host as its own user, so one tools file can hold sources for several systems.
- One system
- Several systems
DB2i_SSH_KEY. Existing tools files need no change.ssh-key and ssh-host-key-sha256 are described in the Sources Reference.
DB2i_PASS and a source’s password are not used. This also means a password is never sent to a host whose key was not verified.With DB2i_SSH_KEY set you can delete the DB2i_PASS line from .env: a tools file that says password: ${DB2i_PASS} still loads. Do not leave the line blank (DB2i_PASS=), because a blank value is rejected at startup.- The private key stays on the machine that runs the MCP server. The public key (
.pub) goes on the IBM i, in the~/.ssh/authorized_keysof the user profile that connects: - On the IBM i,
~/.sshmust be700,authorized_keysmust be600, and the home directory must not be group- or world-writable, otherwisesshdsilently ignores the key. - Check it before starting the server:
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes -o BatchMode=yes MYUSER@my-ibmi.company.com "echo OK"must printOKwithout a password prompt. - Supported key formats: OpenSSH-format Ed25519, RSA (2048 bit or more) and ECDSA keys, and RSA in PEM (
BEGIN RSA PRIVATE KEY). Passphrase-protected keys work withDB2i_SSH_PASSPHRASE. - Not supported: ECDSA in PEM (
BEGIN EC PRIVATE KEY) and PKCS#8 (BEGIN PRIVATE KEY). Generate a new key withssh-keygen -t ed25519. - Whether the IBM i accepts a given key type depends on its
sshdconfiguration. - If authentication fails the server logs
All configured authentication methods failed. There is no password fallback, so fix the key. - The server refuses to start when
DB2i_SSH_KEYpoints to a file it cannot read. A YAML source whosessh-keycannot be read fails to load with the source name in the error.
- Get the fingerprint from a trusted channel:
ssh-keyscan -t ed25519 my-ibmi.company.com | ssh-keygen -lf -(use the key type the IBM i offers). - For one system, set
DB2i_SSH_HOST_KEY_SHA256=SHA256:.... For several systems, setssh-host-key-sha256on each YAML source, because each host has its own key. A source without its own value is checked againstDB2i_SSH_HOST_KEY_SHA256. - With a fingerprint set, a different host key is refused and the log says
IBM i SSH host key does not match the configured fingerprint. - Without it any host key is accepted and a warning is logged each time a session is opened.
- Connections to the same system share ONE SSH session and ONE SQL job (per host, user, key, technique and JDBC options). The built-in tools and the YAML sources that point to the same system as the same user share it; each other system gets its own session.
- The first query on a system takes about 10 seconds (SSH connect plus JVM start); later queries reuse the job and are fast.
- Queries on one system run on that single job, so parallel tool calls are served one after another.
- If the SSH session drops, the next request re-creates it (one cold start).
- See Connection Pool Timeouts for what happens when a query times out.
DB2i_JDBC_OPTIONS Env Var
Forward any mapepire JDBC option to the underlying driver via a single environment variable. TheDB2i_JDBC_OPTIONS env var accepts a semicolon-separated list of key=value pairs modeled on DB2 JDBC URL syntax — letting you set library list, naming convention, date format, and any other JDBC property without editing YAML.
Format Rules
- Library List
- Date Format
- Combined Options
libraries= pair.Precedence and YAML Interaction
DB2i_JDBC_OPTIONS is shallow-merged over the jdbc-options field in each YAML source. Env values win on per-key collisions; YAML-only keys are preserved.
naming=system or a standard library list across all environments) without editing per-deployment YAML files.Security: Log Redaction
The server logs only thelibraries field at pool initialization. Other JDBC fields — including potentially sensitive values like key ring password, proxy server, and trace — are intentionally excluded from every log level to prevent credential leakage.
libraries option took effect, inspect driver behavior directly (for example, run SELECT CHAR(CURRENT_DATE) to confirm date format) rather than searching the logs.SQL Tools Configuration
Load and manage YAML-defined SQL tools. These settings control how the server discovers, loads, and reloads SQL tool definitions from YAML configuration files. You can load tools from individual files, entire directories, or use glob patterns to organize tools into logical groups (toolsets) for different use cases. For detailed information on creating SQL tools, see the SQL Tools Overview and Building SQL Tools guides.YAML Tool Settings
YAML Configuration Examples
YAML Configuration Examples
-
Files are merged in sorted path order. With
YAML_ALLOW_DUPLICATE_TOOLS=trueorYAML_ALLOW_DUPLICATE_SOURCES=true, the last file wins. -
Loading is all-or-nothing. A file that fails to parse or validate stops startup with
Invalid tool configuration in <file>: <problems>. On auto-reload the error is logged and the previous tools stay in place. -
A path that does not exist is treated as a glob pattern when it contains
*,?,[,],{or}. Quote patterns on the command line:--tools 'tools/**/*.yaml'. - A YAML tool that has the name of an enabled built-in tool stops startup. Rename the YAML tool or leave the built-in tool off.
-
With the built-in IBM i sign-on every tool runs on the signed-on user’s connection. A source’s
userandpasswordare ignored, itshostmust beDB2i_HOST, and a source that setsjdbc-optionsstops startup.
Built-in Tools
Control access to compiled SQL tools. The server includes built-in tools for schema discovery, query validation, and SQL execution. All are disabled by default (exceptdescribe_sql_object) and must be explicitly enabled via CLI flags or environment variables.
Configuration Variables
- Full Workflow (CLI)
- Schema Discovery Only
- Write Mode (Opt-in)
- YAML Tools Only (Default)
Schema Discovery Tools (--builtin-tools)
Schema Discovery Tools (--builtin-tools)
- list_schemas: Browse available schemas via
QSYS2.SYSSCHEMAS - list_tables_in_schema: Find tables, views, physical files via
QSYS2.SYSTABLES - get_table_columns: Inspect column metadata via
QSYS2.SYSCOLUMNS2 - get_related_objects: Dependency analysis via
SYSTOOLS.RELATED_OBJECTS - validate_query: Multi-step SQL validation via
QSYS2.PARSE_STATEMENT
describe_sql_object (Always Available)
describe_sql_object (Always Available)
QSYS2.GENERATE_SQL:- Input: Object name, library, type (TABLE, VIEW, INDEX, etc.)
- Output: Complete DDL with constraints, indexes, and properties
- Security: Read-only, describes objects without modification
- Use case: Schema discovery, documentation, AI context
execute_sql (--execute-sql)
execute_sql (--execute-sql)
- Readonly by default: Only SELECT/QUERY statements allowed when
IBMI_EXECUTE_SQL_READONLY=true(default) - Write operations opt-in: Set
IBMI_EXECUTE_SQL_READONLY=falseto enable INSERT, UPDATE, DELETE, etc. - PARSE_STATEMENT validation: Uses IBM i’s native SQL parser (
QSYS2.PARSE_STATEMENT) for authoritative statement type detection - AST/Regex validation: Fast pattern matching to catch dangerous SQL keywords
- Fail-closed security: All validation failures result in query rejection
- Query length limit: Maximum 10,000 characters per query
- Use case: Development exploration, debugging queries, ad-hoc data analysis
- Built-in tools: Compiled TypeScript, controlled by feature flags, runtime validation with PARSE_STATEMENT
- YAML tools: User-defined, curated queries with parameters, explicit query control
- Security: Built-in tools use IBM i’s SQL parser for defense-in-depth; YAML tools use explicit query whitelisting
- Recommendation: Use YAML tools in production for explicit query control and parameterization
Observability & Monitoring
Track server performance, debug issues, and monitor operations. Observability features help you understand server behavior through logging, distributed tracing (OpenTelemetry), and performance metrics. These settings are crucial for production deployments and troubleshooting.Server Settings
Basic server identification and environment configuration. These variables set the server’s identity in logs and telemetry data, control the runtime environment, and determine where log files are stored.Logging Configuration
Control log output, verbosity, and file storage. The server uses Pino for structured logging with automatic log rotation and support for both console and file outputs. Logs help you debug issues, track server behavior, and comply with audit requirements.Log Settings
debug: Detailed diagnostic information (verbose)info: General informational messages (recommended)notice: Significant events worth notingwarning: Warning conditions that should be addressederror: Error conditions that need attentioncrit,alert,emerg: Critical system failures
Log Directory Configuration
Where logs are stored depends on how you specify the path:- Default (OS-Standard)
- Absolute Path
- Relative Path
- Tilde Expansion
~/.ibmi-mcp-server/logs/Use for: Production with npx, user-specific installationsBenefits:- Works consistently with
npx @ibm/ibmi-mcp-server - Persists across package updates
- Doesn’t require write permissions to npm cache
- Follows OS conventions for user data
LOGS_DIR does not stop the server. If the directory cannot be created or written to (a read-only container file system, for example), the server prints one line on stderr, Warning: cannot write logs to LOGS_DIR '<path>' (<reason>). File logging is disabled; ..., and logs to stderr instead: at the configured level with the HTTP transport, at warn and above with the stdio transport.Log Files Created
The server writes two log files with automatic rotation:- Logs rotate when they reach 10MB OR at midnight daily (whichever comes first)
- Files are numbered sequentially:
combined.1.log,combined.2.log, etc. The highest number is the file currently being written (there is no un-numbered file) - Current file + 5 previous files are kept (6 total files per log file), including files left by earlier runs of the server: at each rotation the oldest files beyond that are deleted
- Daily rotation re-uses the existing file if still within the same day
combined.log.N and could fill LOGS_DIR with millions of empty files on the day daylight saving time ends, which makes the server slow to start and to stop. If ~/.ibmi-mcp-server/logs holds files named *.log.N, stop every server that uses it and delete them.Log File Examples
Log File Examples
Console Output & Colors
Console behavior depends on environment and transport mode:HTTP Transport (Colored)
HTTP Transport (Colored)
stderrDisable colors: Set NO_COLOR=1 or FORCE_COLOR=0STDIO Transport (Files Only)
STDIO Transport (Files Only)
LOGS_DIR only. If LOGS_DIR cannot be written to, records at warn and above go to stderr as JSON.Why: MCP protocol requires clean JSON-RPC on stdout with no ANSI codesProduction (JSON)
Production (JSON)
stderr (HTTP transport only) and log filesNO_COLOR=1 to disable all colored output, useful for CI/CD pipelines and log aggregation systems.Filtering Logs
Logs append across server restarts (rather than creating timestamped files), so use the structured fields of each record to filter. Records written while a request is handled carry itsrequestId:
OpenTelemetry
Enable tracing. WithOTEL_ENABLED=true the server records one span per tool execution (tool_execution:<tool name>) and one span per outgoing fetch call (the OAuth issuer metadata and JWKS requests), and exports them to an OTLP endpoint such as Jaeger or a collector. Incoming HTTP requests are not traced. Without OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, each finished span is written to the server log as a Trace Span End record at info level.
NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, ALL- Jaeger
- OTLP Collector
Environment-Specific Examples
Development Environment
Development Environment
Production Environment: IBM i Sign-On
Production Environment: IBM i Sign-On
Production Environment: External Issuer
Production Environment: External Issuer
Docker Compose
Docker Compose