mcp-server-db2i
Enables AI assistants to query and inspect IBM DB2 for i databases using read-only SQL commands and schema inspection tools. It provides secure access to table metadata, views, and indexes via the JT400 JDBC driver.
README
mcp-server-db2i
A Model Context Protocol (MCP) server for IBM DB2 for i (DB2i). This server enables AI assistants like Claude and Cursor to query and inspect IBM i databases using the JT400 JDBC driver.
Features
- Read-only SQL queries - Execute SELECT statements safely with automatic result limiting
- Schema inspection - List all schemas/libraries with optional filtering
- Table metadata - List tables, describe columns, view indexes and constraints
- View inspection - List and explore database views
- Secure by design - Only SELECT queries allowed, credentials via environment variables
- Docker support - Run as a container for easy deployment
Available Tools
| Tool | Description |
|---|---|
execute_query |
Execute read-only SELECT queries |
list_schemas |
List schemas/libraries (with optional filter) |
list_tables |
List tables in a schema (with optional filter) |
describe_table |
Get detailed column information |
list_views |
List views in a schema (with optional filter) |
list_indexes |
List SQL indexes for a table |
get_table_constraints |
Get primary keys, foreign keys, unique constraints |
Note:
list_indexesandget_table_constraintsquery theQSYS2SQL catalog views and only return SQL-defined objects. Legacy DDS Logical Files and Physical File constraints are not included. This is standard DB2 for i behavior.
Filter Syntax
The list tools support pattern matching:
CUST- Contains "CUST"CUST*- Starts with "CUST"*LOG- Ends with "LOG"ORD*FILE- Starts with "ORD", ends with "FILE"
Installation
Prerequisites
- Node.js 18 or higher
- Java Runtime Environment (JRE) 11 or higher (for JDBC)
- Access to an IBM i system
Option 1: npm (recommended)
npm install -g mcp-server-db2i
Option 2: From source
git clone https://github.com/Strom-Capital/mcp-server-db2i.git
cd mcp-server-db2i
npm install
npm run build
Option 3: Docker
docker build -t mcp-server-db2i .
Configuration
Create a .env file or set environment variables:
# Required
DB2I_HOSTNAME=your-ibm-i-host.com
DB2I_USERNAME=your-username
DB2I_PASSWORD=your-password
# Optional - Database
DB2I_PORT=446 # Default: 446
DB2I_DATABASE=*LOCAL # Default: *LOCAL
DB2I_SCHEMA=your-default-schema # Default schema for all tools (can be overridden per-call)
DB2I_JDBC_OPTIONS=naming=system;date format=iso
# Optional - Logging
LOG_LEVEL=info # debug, info, warn, error, fatal (default: info)
NODE_ENV=production # production = JSON logs, development = pretty logs
LOG_PRETTY=true # Override: force pretty (true) or JSON (false) logs
LOG_COLORS=true # Override: force colors on/off (auto-detected by default)
# Optional - Rate Limiting
RATE_LIMIT_WINDOW_MS=900000 # Time window in ms (default: 900000 = 15 minutes)
RATE_LIMIT_MAX_REQUESTS=100 # Max requests per window (default: 100)
RATE_LIMIT_ENABLED=true # Set to 'false' to disable (default: true)
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
DB2I_HOSTNAME |
Yes | - | IBM i hostname or IP address |
DB2I_USERNAME |
Yes | - | IBM i user profile |
DB2I_PASSWORD |
Yes | - | User password |
DB2I_PORT |
No | 446 |
JDBC port (446 is standard for IBM i) |
DB2I_DATABASE |
No | *LOCAL |
Database name |
DB2I_SCHEMA |
No | - | Default schema/library for tools. If set, you don't need to specify schema in each tool call. |
DB2I_JDBC_OPTIONS |
No | - | Additional JDBC options (semicolon-separated) |
LOG_LEVEL |
No | info |
Log level: debug, info, warn, error, fatal |
NODE_ENV |
No | - | Set to production for JSON logs, otherwise pretty-printed |
LOG_PRETTY |
No | - | Override log format: true = pretty, false = JSON |
LOG_COLORS |
No | auto | Override colors: true/false (auto-detects TTY by default) |
RATE_LIMIT_WINDOW_MS |
No | 900000 |
Rate limit time window in milliseconds (15 min) |
RATE_LIMIT_MAX_REQUESTS |
No | 100 |
Maximum requests allowed per window |
RATE_LIMIT_ENABLED |
No | true |
Set to false or 0 to disable rate limiting |
JDBC Options
Common JDBC options for IBM i (JT400/JTOpen driver):
| Option | Values | Description |
|---|---|---|
naming |
system, sql |
system uses / for library separator, sql uses . for schema separator |
libraries |
LIB1,LIB2,... |
Library list for resolving unqualified names |
date format |
iso, usa, eur, jis, mdy, dmy, ymd |
Date format for date fields |
time format |
iso, usa, eur, jis, hms |
Time format for time fields |
errors |
full, basic |
Level of detail in error messages (full helps debugging) |
translate binary |
true, false |
Whether to translate binary/CCSID data |
secure |
true, false |
Enable SSL/TLS encryption |
Example: naming=system;date format=iso;errors=full
Usage with Cursor
Add to your Cursor MCP settings (~/.cursor/mcp.json):
Using Docker (recommended)
{
"mcpServers": {
"db2i": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "DB2I_HOSTNAME=your-host",
"-e", "DB2I_USERNAME=your-user",
"-e", "DB2I_PASSWORD=your-password",
"mcp-server-db2i:latest"
]
}
}
}
Using Docker with env file
{
"mcpServers": {
"db2i": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--env-file", "/path/to/your/.env",
"mcp-server-db2i:latest"
]
}
}
}
Using docker-compose
Create a .env file in the project root, then:
{
"mcpServers": {
"db2i": {
"command": "docker-compose",
"args": ["run", "--rm", "mcp-server-db2i"],
"cwd": "/path/to/mcp-server-db2i"
}
}
}
The docker-compose.yml automatically reads from .env in the same directory.
Using npx (after npm install)
{
"mcpServers": {
"db2i": {
"command": "npx",
"args": ["mcp-server-db2i"],
"env": {
"DB2I_HOSTNAME": "your-host",
"DB2I_USERNAME": "your-user",
"DB2I_PASSWORD": "your-password"
}
}
}
}
Local development
{
"mcpServers": {
"db2i": {
"command": "npx",
"args": ["tsx", "/path/to/mcp-server-db2i/src/index.ts"],
"env": {
"DB2I_HOSTNAME": "your-host",
"DB2I_USERNAME": "your-user",
"DB2I_PASSWORD": "your-password"
}
}
}
}
Example Queries
Once connected, you can ask the AI assistant:
- "List all schemas that contain 'PROD'"
- "Show me the tables in schema MYLIB"
- "Describe the columns in MYLIB/CUSTOMERS"
- "What indexes exist on the ORDERS table?"
- "Run this query: SELECT * FROM MYLIB.CUSTOMERS WHERE STATUS = 'A'"
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run build
# Run production build
npm start
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Lint code
npm run lint
# Lint and fix
npm run lint:fix
# Type check
npm run typecheck
Security
- Read-only access: Only SELECT statements are permitted
- No credentials in code: All sensitive data via environment variables
- Query validation: AST-based SQL parsing plus regex validation blocks dangerous operations
- Result limiting: Default limit of 1000 rows prevents large result sets
- Rate limiting: Configurable request throttling to prevent abuse (100 req/15 min default)
- Structured logging: Automatic redaction of sensitive fields like passwords
Compatibility
- IBM i V7R3 and later (V7R5 recommended)
- Works with any IBM i system accessible via JDBC over TCP/IP
Related Projects
- IBM ibmi-mcp-server - IBM's official MCP server for IBM i systems. Offers YAML-based SQL tool definitions, AI agent frameworks, and production deployment options. Requires Mapepire to be installed on your IBM i system, but if you can manage that prerequisite, it's worth checking out for more advanced use cases.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details.
Acknowledgments
- node-jt400 - JT400 JDBC driver wrapper for Node.js
- Model Context Protocol - The protocol specification
- @modelcontextprotocol/sdk - Official TypeScript SDK
- IBM ibmi-mcp-server - SQL security validation patterns inspired by their approach to AST-based query validation
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。