Skip to main content
This guide covers setting up mcp-server-db2i with MCP-compatible clients. The JSON configuration format is the same for all clients - only the file location differs.

Configuration Paths

Cursor

  • macOS/Linux: ~/.cursor/mcp.json
  • Windows: %USERPROFILE%\.cursor\mcp.json
  • Env var syntax: ${env:VAR_NAME}

Claude Desktop

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Claude Code

  • All platforms: ~/.claude.json
  • Project-specific: .mcp.json in project root
  • Env var syntax: ${VAR_NAME}
  • CLI: claude mcp add --scope user db2i -- npx mcp-server-db2i

Setup Options

Store credentials in a separate .env file for security. For production deployments, see Docker Secrets for the most secure approach.
Create a .env file with your credentials:

Using Docker with inline credentials

Security Warning: This stores credentials in plain text in your config file. Only use for local development or testing.

Using docker-compose

Create a .env file in the project root, then:
The docker-compose.yml automatically reads from .env in the same directory. Use environment variable expansion to keep credentials out of config files.
  1. Set credentials in your shell profile (~/.zshrc or ~/.bashrc):
  1. Use ${env:VAR} syntax in your Cursor config:

Using npx with inline credentials

Security Warning: This stores credentials in plain text in your config file. Only use for local development or testing.

Local Development

For development or customization:

Configuration Options

With Default Schema

Set a default schema to avoid specifying it in every query:

With Custom Driver Options

DB2I_ODBC_OPTIONS applies to the default odbc image. With the jt400 image, pass JDBC properties in DB2I_JDBC_OPTIONS instead, for example naming=sql;date format=iso;errors=full. See Configuration.

With Debug Logging

Enable debug logging for troubleshooting:

Example Prompts

Once connected, you can ask the AI assistant:

Schema Exploration

  • “List all schemas that contain ‘PROD’”
  • “Show me all schemas on this system”
  • “What libraries are available?”

Table Discovery

  • “Show me the tables in schema MYLIB”
  • “List all tables that start with ‘CUST’”
  • “What tables are in the QGPL library?”

Column Information

  • “Describe the columns in MYLIB/CUSTOMERS”
  • “What’s the structure of the ORDERS table?”
  • “Show me the data types for MYLIB.INVENTORY”

Indexes and Constraints

  • “What indexes exist on the ORDERS table?”
  • “Show me the primary key for CUSTOMERS”
  • “List all foreign keys in the SALES schema”

SQL Queries

  • “Run this query: SELECT * FROM MYLIB.CUSTOMERS WHERE STATUS = ‘A’”
  • “Count the records in ORDERS where YEAR = 2024”
  • “Find customers with no orders in the last year”

Troubleshooting

Connection Issues

  1. Check hostname resolution: Ensure the IBM i hostname is reachable
  2. Verify credentials: Test with a known-good username/password
  3. Check port: Default is 446, verify firewall allows access
  4. Enable debug logging: Set LOG_LEVEL=debug

Docker Issues

  1. Image not found: Build the image first with docker build -t mcp-server-db2i .
  2. Permission denied: Ensure Docker daemon is running
  3. Network issues: Check Docker network settings if IBM i is not reachable

Tool Errors

  1. Schema not found: Verify schema name is correct (case-sensitive on IBM i)
  2. Table not found: Ensure table exists and user has SELECT permission
  3. Rate limit exceeded: Wait for the window to reset or adjust limits

Viewing Logs

For stdio transport, logs go to stderr. Docker logs can be viewed with:

Multiple Connections

You can configure multiple IBM i connections:
Then specify which connection to use in your prompts: “Using db2i-prod, list all tables in PRODLIB”

Claude Code CLI

Claude Code supports environment variable expansion using ${VAR} syntax, which is the recommended secure approach.

Secure setup with environment variables

  1. Set credentials in your shell profile (~/.zshrc or ~/.bashrc):
  1. Add to ~/.claude.json with variable references:
This keeps credentials out of config files - Claude Code expands ${VAR} at runtime.

Using the CLI