@bdkinc/ibmi-mcp
v0.5.22
Published
Standalone Model Context Protocol (MCP) server for IBM i
Maintainers
Readme
Standalone MCP Host (@bdkinc/ibmi-mcp)
This package contains the standalone Model Context Protocol (MCP) host used for external harnesses, AI agents, and IDE validation.
Prerequisites
To connect using the MCP host, ensure the following requirements are met on both the client PC and the IBM i host:
IBM i Access ODBC Driver The local machine running the MCP server must have the architecture-matched IBM i Access ODBC driver installed.
- ODBC Installation Instructions
- This operating-system driver is distinct from the Node.js
odbcnative addon installed by npm. Both are required: the addon loads the local ODBC driver when the host connects.
SSH Service (Preferred) The SSH server should be running on the IBM i host for the best experience (itoolkit-based tools and secure command execution).
- Start the service using:
STRTCPSVR *SSHD - If SSH is unavailable, the server falls back to plain SQL/ODBC for observability and recommendation tools. Act tools (CL command execution) require SSH.
- Start the service using:
SSH-Compatible Credentials (Preferred) For full functionality, use credentials with an enabled shell. Profiles without passwords or user profiles like
QSECOFRthat are typically restricted from SSH access should not be used directly unless appropriately configured. The user must also conform to PASE password constraints.Required Packages The IBM i host should have
itoolkit-utilsinstalled for running tools securely via SSH. (e.g.,yum install itoolkit-utils)- SQL/ODBC Observe does not need itoolkit-utils. SSH-based CL execution and QCMDCHK do. The runner does not fall back after an ambiguous XMLSERVICE or SSH failure.
Dedicated Service Profile (Recommended)
For production or shared-team use, connect with a dedicated IBM i service profile rather than a personal user account. A service profile isolates audit trails, limits authority to only what the MCP host needs, and prevents accidental use of personal credentials.
Suggested profile setup:
CRTUSRPRF USRPRF(MCPSVC) TEXT('IBM i AI MCP service account')
USRCLS(*USER) PWDEXPITV(*NOMAX) STATUS(*ENABLED)
LMTCPB(*NO) JOBD(QBATCH)Adjust JOBD, authority (GRPPRF, SUPGRPPRF), and object permissions to match your site's security policy. The profile must have PASE shell access for SSH-based itoolkit calls. If you only need SQL/ODBC fallback access, shell access is not required, but many act tools will be unavailable.
Do not commit passwords. Set
IBMI_PASSWORD_SECRETfrom your environment, a secrets manager, or a VS Code input prompt. Never hardcode credentials inmcp.jsonor.envfiles that are checked into version control.
Usage
You can run the stable package directly via npx without cloning the repository. npm 12 requires explicit approval for dependency install scripts, so approve only the odbc package:
npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp --transport stdionpm 11 and earlier normally run dependency install scripts without this flag. During intentional prerelease testing, select the next dist-tag explicitly while keeping the same narrow approval:
npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp@next --transport stdioWhen running via npx, provide your IBM i connection configuration using environment variables:
IBMI_HOST=my-ibmi IBMI_USERNAME=myuser IBMI_PASSWORD_SECRET=mysecret IBMI_CURRENT_SCHEMA=MYLIB npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp --transport stdioThe CLI also supports a few basic flags that are useful when validating external installs:
npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp --help
npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp --versionThe npm odbc dependency already provides a node-pre-gyp install --fallback-to-build install hook. When approved, it downloads the matching native prebuild when available and otherwise falls back to a source build. npm 12 blocks that hook unless odbc is approved; this package does not bypass the consumer's lifecycle policy or add another postinstall hook. Do not use an allow-all lifecycle option.
For an ordinary project installation on npm 12, add a Boolean approval to the installing root's package.json, then install or rebuild:
{
"allowScripts": {
"odbc": true
}
}npm install @bdkinc/ibmi-mcp
npm rebuild odbcnpm 12 rejects command-line --allow-scripts for project-scoped install and rebuild; the installing root's allowScripts policy is the supported form. If ignore-scripts=true is configured, it overrides approvals, so review npm config get ignore-scripts before troubleshooting.
Repairing an incomplete ODBC install
If npm 12 previously reused an npx cache entry where the odbc install hook was blocked, retrying with --allow-scripts=odbc may not repair the already-installed tree. Read the exact _npx entry from the odbc.node loader error; do not delete or search unrelated cache entries. Find the cache root with:
npm config get cacheThen approve and rebuild only odbc inside that entry:
$NpxProject = '<npm cache>\_npx\<entry from error>'
npm pkg set --json 'allowScripts.odbc=true' --prefix "$NpxProject"
npm rebuild odbc --prefix "$NpxProject"The --json flag is required so npm writes the Boolean true, not the string "true". This preserves the cache entry and does not change user or global npm policy. After the rebuild, retry the normal stable launcher with npx --allow-scripts=odbc -y @bdkinc/ibmi-mcp --transport stdio.
If the native addon loads but Windows reports that the ODBC driver is missing or has the wrong architecture, install the matching IBM i Access driver instead of rebuilding the Node addon.
Human-only command approvals
Command approval decisions are not exposed as extra public MCP tools (the facade stays at 32 tools). Operators approve or reject pending requests with human-only CLI subcommands that do not start the host:
# List pending requests (shared durable store with the running host)
ibmi-mcp approvals list --status pending
# Approve with an explicit human identity and ticket/reference
ibmi-mcp approvals approve <request-id> --approver alice --ticket CHG-1001
# Reject
ibmi-mcp approvals reject <request-id> --approver alice --comment "Not authorized"Store location precedence:
--store PATHon the approvals CLIMCP_APPROVAL_STORE_PATHenvironment variableapprovalStorePathin the MCP JSON config file (--config)- User-data default (for example
%APPDATA%\ibmi-mcp\approvals.jsonon Windows,~/Library/Application Support/ibmi-mcp/approvals.jsonon macOS, or$XDG_DATA_HOME/ibmi-mcp/approvals.jsonon Linux)
Requestors cannot approve or reject their own requests. The store is a durable JSON file with atomic writes; it is never under .tmp.
Recovering a stuck approval-store lock
The approval store is guarded by a cross-process exclusive lock implemented as a directory created atomically beside the store file (<store>.lock). While a host or CLI process holds it, other processes wait and back off. Under normal operation the lock is created and released automatically and requires no attention.
A lock can be left behind only if a process is killed at the wrong instant, or if the store lives on a network/shared filesystem where the lock cannot be safely auto-reclaimed. In those cases acquisition fails closed (it times out with a clear Timed out ... waiting for approval store lock error) rather than risk two writers double-executing a command. This is deliberate. Recover manually and carefully:
- Identify the lock artifacts. Next to your approval store JSON (see the store location precedence above), look for:
<store>.lock— the active lock directory. It contains anowner.jsonrecording the ownertoken,pid,hostname, andacquiredAt.<store>.reclaim— a short-lived guard directory used while a stale owner is being inspected. A leftover one indicates a reclaim that did not finish.
- Confirm there is no live local owner. Read
owner.json. If itshostnamematches the machine you are on, check whether the recordedpidis still running. If that process is alive, stop — the lock is in use. Only proceed when the owner process is confirmed gone (or theowner.jsonis missing entirely). Ifhostnameis a different host, you cannot verify liveness locally; coordinate with that host before touching anything. - Wait past the stale threshold. The lock is only considered stale after the owner's
acquiredAtis older than the stale window (default 30 seconds). Wait until you are safely past it so a briefly-paused owner is not interrupted. - Back up the approval JSON first. Copy the approval store file (for example
approvals.json) to a safe location before removing anything, so approval history is preserved if something is inconsistent. - Remove only orphan lock directories. After the checks above pass, delete the
<store>.lockdirectory (and any leftover<store>.reclaimor<store>.stale-*/<store>.release-*directories). Remove only these lock/guard directories — never the approval store JSON itself.
Never remove a live lock. If any owner process is still running, or you cannot prove the owner is gone (different host, permission errors, shared/network filesystem), do not delete the lock directory. Forcing a live lock open can allow two processes to execute the same approved command. When in doubt, leave it locked and let acquisition fail closed. For shared deployments, prefer a local-filesystem path for the approval store to avoid routine fail-closed timeouts.
Application Integration Examples
VS Code (e.g., Roo Code / GitHub Copilot)
For VS Code extensions that support MCP clients, you can configure the server using a mcp.json settings file:
{
"mcpServers": {
"ibmi-ai": {
"command": "npx",
"args": ["--allow-scripts=odbc", "-y", "@bdkinc/ibmi-mcp", "--transport", "stdio"],
"env": {
"IBMI_PROFILE_LABEL": "Local IBM i",
"IBMI_HOST": "your-ibmi-host",
"IBMI_USERNAME": "your-user",
"IBMI_PASSWORD_SECRET": "${input:ibmi-password}",
"IBMI_CURRENT_SCHEMA": "MYLIB",
"MCP_ALLOWED_COMMAND_NAMES": "CRTUSRPRF,CHGUSRPRF,ENDJOB,HLDJOB,RLSJOB,DLTSPLF,HLDSPLF,CHGSPLF,STRTCPSVR,ENDTCPSVR"
}
}
},
"inputs": [
{
"id": "ibmi-password",
"type": "promptString",
"description": "IBM i password",
"password": true
}
]
}Clients that support secret variables can also set IBMI_PASSWORD_SECRET to a client-managed secret reference instead of a prompt input. Use @bdkinc/ibmi-mcp@next in the package argument only when intentionally testing a prerelease.
Claude Desktop
To use the IBM i tools from the Claude Desktop app, edit your Claude config file (%APPDATA%\Claude\claude_desktop_config.json on Windows or ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
Note: Claude Desktop does not support
${input:...}variable syntax. SetIBMI_PASSWORD_SECRETusing a system environment variable, a secrets manager, or a wrapper script — do not hardcode it in this file.
{
"mcpServers": {
"ibmi-ai": {
"command": "npx",
"args": ["--allow-scripts=odbc", "-y", "@bdkinc/ibmi-mcp", "--transport", "stdio"],
"env": {
"IBMI_HOST": "your-ibmi-host",
"IBMI_USERNAME": "your-user",
"IBMI_CURRENT_SCHEMA": "MYLIB",
"MCP_ALLOWED_COMMAND_NAMES": "CRTUSRPRF,CHGUSRPRF,ENDJOB,HLDJOB,RLSJOB,DLTSPLF,HLDSPLF,CHGSPLF,STRTCPSVR,ENDTCPSVR"
}
}
}
}Set IBMI_PASSWORD_SECRET as a system environment variable before launching Claude Desktop, or use a secrets manager to inject it into the process environment.
CL Command Execution
- Execution switch —
MCP_COMMAND_EXECUTION_ENABLEDdefaults totrue; set it tofalseto disable command execution entirely. - Default command gate — With neither policy setting configured, supported non-interactive CL commands are eligible without a command-name allowlist. Direct
CHGCRGPRIrequests use the typed PowerHA workflow. Free-form CL still has the selected profile’s IBM i authority. Live validation, IBM i authority, and approval for the exact command still apply. - Optional allowlist — Set
MCP_ALLOWED_COMMAND_NAMESto a comma-separated list (e.g.,CRTUSRPRF,ENDJOB) to restrict eligible command names. SetMCP_FREEFORM_COMMAND_EXECUTION_ENABLED=falsewith an empty list to disallow generic CL execution. - Explicit free-form mode —
MCP_FREEFORM_COMMAND_EXECUTION_ENABLED=trueoverrides a configured allowlist. It does not bypass approvals or the separate execution switch. - Unconfirmed completion — SQL fallback is only attempted for a known SSH connection setup failure before dispatch. After a reset or timeout with an unknown outcome, verify the target before requesting a new approval.
Audit Log
Every tool invocation is recorded to a JSONL audit log at <cwd>/logs/audit.jsonl (configurable via MCP_AUDIT_LOG_DIR). Each line is a JSON object:
{
"ts": "2025-01-15T10:23:45.123Z",
"tool": "list_ibmi_jobs",
"callerId": "MCPSVC",
"sessionId": "abc123",
"args": {},
"durationMs": 142,
"ok": true
}Fields with names matching password, secret, or token (case-insensitive) are replaced with "<redacted>" before writing. The log file rotates at 50 MB to audit-<timestamp>.jsonl.
The logs/ directory is gitignored. The log directory is created automatically if it does not exist.
Health Endpoints
The HTTP transport exposes two health endpoints:
GET /health— Deep check; connects to IBM i and verifies prerequisites. Use for startup readiness.GET /healthz— Shallow in-process check; returns session count, capacity, and uptime without touching IBM i. Use for liveness probes.
Local Development & Environment Configuration
If you are developing locally inside the source repository, you can set the environment variables via .env files in this directory (e.g. .env, .env.example, .env.local.example).
Typical variables include:
MCP_TRANSPORTMCP_PROFILEMCP_HTTP_*IBMI_HOST,IBMI_PORT,IBMI_DATABASE,IBMI_CURRENT_SCHEMA,IBMI_USERNAME,IBMI_PASSWORD_SECRET,IBMI_LIBRARY_LIST,IBMI_TLS- standalone runtime
MCP_*tuning for sessions and command execution
Legacy MCP_* IBM i connection names still work for one release cycle, but they are deprecated and lose to the equivalent IBMI_* variables when both are set.
Common scripts for local monorepo development:
npm run dev --workspace @bdkinc/ibmi-mcpnpm run build --workspace @bdkinc/ibmi-mcpnpm run start --workspace @bdkinc/ibmi-mcpnpm run test:live-smoke --workspace @bdkinc/ibmi-mcp
Live smoke test requirements:
- Export the same IBM i connection variables used by the standalone host, for example
IBMI_HOST,IBMI_USERNAME, andIBMI_PASSWORD_SECRET. - If you want the smoke test to exercise approval-backed command execution, also provide
MCP_COMMAND_EXECUTION_ENABLED=trueandMCP_FREEFORM_COMMAND_EXECUTION_ENABLED=true. - The script sets
RUN_IBM_I_LIVE_SMOKE=1automatically and runstests/live-smoke.test.tsin a subprocess so it can load the standalone itoolkit runtime correctly under Node.
Behavior Notes
- This standalone host exposes observe, recommend, and act tools.
- Command-backed tools execute as the configured IBM i profile.
- The standalone
itoolkitpath is fixed by the host implementation; there is no standaloneMCP_ITOOLKIT_TRANSPORToverride. plan_run_ibmi_commandandrun_ibmi_commanduse a durable JSON-file approval store shared with theibmi-mcp approvalsCLI.- Human operators list/approve/reject via CLI only; those lifecycle commands are not public MCP tools.
- Approval records survive host restarts. IDs are UUIDs (collision-free across restarts). Requestors cannot self-approve.
- Configure the store with
MCP_APPROVAL_STORE_PATHor configapprovalStorePath; otherwise the user-data default is used. - Existing deployments with a nonempty
MCP_ALLOWED_COMMAND_NAMESkeep that restriction unless they explicitly setMCP_FREEFORM_COMMAND_EXECUTION_ENABLED=true.
