A MCP server implementation for Db2 for i
Project description
db2i-mcp-server
A Model Context Protocol (MCP) server implementation for Db2 for i that enables AI agents to interact with Db2 for i databases through Claude and other MCP-compatible AI assistants.
Overview
The Db2i MCP Server provides a standardized interface for AI assistants to work with Db2 for i databases, enabling intelligent data exploration, querying, and analysis capabilities. This server acts as a bridge between AI assistants and your Db2 for i data, leveraging the Mapepire database driver for seamless connectivity.
Key Features
- Db2 for i Integration: Connects directly to Db2 for i databases using Mapepire
- Data Exploration: Discover and explore available tables in your schema
- Safe Query Execution: Execute SQL queries with built-in safeguards
- MCP-Compatible: Works with Claude and other AI assistants supporting the Model Context Protocol
Components
Resources (In Progress)
(example for testing): The server implements a simple note storage system with:
- Custom note:// URI scheme for accessing individual notes
- Each note resource has a name, description and text/plain mimetype
- Notes persist during the session for referring to important information
Prompts
- query: Executes a SQL query against the Db2 for i database
- Steps and rules for constructing the query to answer user questions
(example for testing): The server generates prompts dynamically based on available notes:
- summarize-notes: Creates summaries of all stored notes
- Optional "style" argument to control detail level (brief/detailed)
- Generates prompt combining all current notes with style preference
Tools
The server implements the following database interaction tools:
-
list-usable-tables: Lists all usable tables in the configured schema
- Call this first to discover available tables before querying
- Filters tables based on configuration (include/ignore lists)
-
describe-table: Returns the definition and sample rows for a specific table
- Provides DDL schema definition and column information
- Shows sample data rows to understand the table structure
-
run-sql-query: Executes a SQL query and returns the results
- Limited to SELECT statements for data safety
- Handles parameters and formatting of results
-
add-note: Adds a new note to the server (example tool for testing)
- Takes "name" and "content" as required string arguments
- Updates server state and notifies clients of resource changes
Setup and Configuration
Prerequisites
Mapepire Configuration
Create a .env file with your DB2 for i connection details:
cd examples/mcp/db2i-mcp-server
cp .env.example .env
# Mapepire Credentials
HOST=hostname
DB_USER=username
PASSWORD=password
DB_PORT=8076 # default port for Mapepire
SCHEMA=schema_name
READONLY=True # Only read access is supported
ENABLE_LOGGING=True
LOG_LEVEL=DEBUG
Testing Your Mapepire Connection
You can test the Mapepire connection before starting the server:
uv run test_mapepire.py
A successful connection will display sample data from the SAMPLE.EMPLOYEE table.
Quickstart
Simple Client script
You can test the Db2i MCP server using a simple python script that creates a minimal MCP client:
This script requires the SAMPLE schema to be available in your Db2 for i database. make sure to set the SCHEMA environment variable in your .env file to SAMPLE.
SCHEMA=SAMPLE
Run the client script:
cd examples/mcp/db2i-mcp-server
uv run client.py
Expected output:
$ uv run client.py
===== AVAILABLE TOOLS =====
Tool: list-usable-tables
Description: List the usable tables in the schema. This tool should be called before running any other tool.
Input Schema: {
"type": "object",
"properties": {}
}
Tool: describe-table
Description: Describe a specific table including ites columns and sample rows. This tool should be called after list-usable-tables.
Input Schema: {
"type": "object",
"properties": {
"table_name": {
"type": "string",
"description": "The name of the table to describe"
}
},
"required": [
"table_name"
]
}
Tool: run-sql-query
Description: run a valid Db2 for i SQL query. This tool should be called after list-usable-tables and describe-table.
Input Schema: {
"type": "object",
"properties": {
"sql": {
"type": "string",
"description": "SELECT SQL query to execute"
}
},
"required": [
"sql"
]
}
Tool: add-note
Description: Add a new note
Input Schema: {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"type": "string"
}
},
"required": [
"name",
"content"
]
}
===== LIST OF TABLES =====
Available tables:
- ACT
- CL_SCHED
- DELETEME
- DEPARTMENT
- EMPLOYEE
- EMPPROJACT
- EMP_PHOTO
- EMP_RESUME
- IN_TRAY
- ORG
- PROJACT
- PROJECT
- SALES
- STAFF
===== TABLE DESCRIPTION: EMPLOYEE =====
Table Schema:
-- Generate SQL
-- Version: V7R4M0 190621
-- Generated on: 03/11/25 18:09:14
-- Relational Database: IHOST
-- Standards Option: Db2 for i
CREATE OR REPLACE TABLE SAMPLE.EMPLOYEE (
EMPNO CHAR(6) CCSID 37 NOT NULL ,
FIRSTNME VARCHAR(12) CCSID 37 NOT NULL ,
MIDINIT CHAR(1) CCSID 37 NOT NULL ,
LASTNAME VARCHAR(15) CCSID 37 NOT NULL ,
WORKDEPT CHAR(3) CCSID 37 DEFAULT NULL ,
PHONENO CHAR(4) CCSID 37 DEFAULT NULL ,
HIREDATE DATE DEFAULT NULL ,
JOB CHAR(8) CCSID 37 DEFAULT NULL ,
EDLEVEL SMALLINT NOT NULL ,
SEX CHAR(1) CCSID 37 DEFAULT NULL ,
BIRTHDATE DATE DEFAULT NULL ,
SALARY DECIMAL(9, 2) DEFAULT NULL ,
BONUS DECIMAL(9, 2) DEFAULT NULL ,
COMM DECIMAL(9, 2) DEFAULT NULL ,
CONSTRAINT SAMPLE.Q_SAMPLE_EMPLOYEE_EMPNO_00001 PRIMARY KEY( EMPNO ) )
RCDFMT EMPLOYEE ;
ALTER TABLE SAMPLE.EMPLOYEE
ADD CONSTRAINT SAMPLE.RED
FOREIGN KEY( WORKDEPT )
REFERENCES SAMPLE.DEPARTMENT ( DEPTNO )
ON DELETE SET NULL
ON UPDATE NO ACTION ;
ALTER TABLE SAMPLE.EMPLOYEE
ADD CONSTRAINT SAMPLE.NUMBER
CHECK( PHONENO >= '0000' AND PHONENO <= '9999' ) ;
Sample Data:
3 sample rows from EMPLOYEE:
EMPNO FIRSTNME MIDINIT LASTNAME WORKDEPT PHONENO HIREDATE JOB EDLEVEL SEX BIRTHDATE SALARY BONUS COMM
000010 CHRISTINE I HAAS A00 3978 01/01/65 PRES 18 F NULL 52750.0 1000.0 4220.0
000020 MICHAEL L THOMPSON B01 3476 10/10/73 MANAGER 18 M 02/02/48 41250.0 800.0 3300.0
000030 SALLY A KWAN C01 4738 04/05/75 MANAGER 20 F 05/11/41 38250.0 800.0 3060.0
Parameters
Here are the optional parameters you can pass to the server:
Db2i MCP Server
options:
-h, --help show this help message and exit
--use-env Use environment variables for configuration
--host HOST Host of the Db2i server (ignored if --use-env is set)
--user USER User for the Db2i server (ignored if --use-env is set)
--password PASSWORD Password for the Db2i server (ignored if --use-env is set)
--port PORT Port of the Db2i server (ignored if --use-env is set)
--schema SCHEMA Schema name (ignored if --use-env is set)
--ignore-unauthorized
Ignore unauthorized access (optional)
--ignore-tables IGNORE_TABLES [IGNORE_TABLES ...]
Tables to ignore (optional)
--include-tables INCLUDE_TABLES [INCLUDE_TABLES ...]
Tables to include (optional)
--custom-table-info CUSTOM_TABLE_INFO
Custom table info (optional)
--sample-rows-in-table-info SAMPLE_ROWS_IN_TABLE_INFO
Number of sample rows in table info (optional, default: 3)
--max-string-length MAX_STRING_LENGTH
Max string length for truncation (optional, default: 300)
Using with Claude Desktop
To use with Claude Desktop, add the server configuration to Claude Desktop's config file:
- On MacOS:
~/Library/Application\ Support/Claude/claude_desktop_config.json - On Windows:
%APPDATA%/Claude/claude_desktop_config.json
Development/Unpublished Servers Configuration
"mcpServers": {
"db2i-mcp-server": {
"command": "uv",
"args": [
"--directory",
"PATH_TO_THIS_REPO/db2i-agents/examples/mcp/db2i-mcp-server",
"run",
"db2i-mcp-server"
"--use-env"
]
}
}
Published Servers Configuration
"mcpServers": {
"db2i-mcp-server": {
"command": "uvx",
"args": [
"db2i-mcp-server"
]
}
}
After configuring, you can enable the server in Claude Desktop and interact with your Db2 for i database through Claude.
Here is an example chat using the MCP server with Claude Desktop: link
Development
Building and Publishing
To prepare the package for distribution:
- Sync dependencies and update lockfile:
uv sync
- Build package distributions:
uv build
This will create source and wheel distributions in the dist/ directory.
- Publish to PyPI:
uv publish
Note: You'll need to set PyPI credentials via environment variables or command flags:
- Token:
--tokenorUV_PUBLISH_TOKEN - Or username/password:
--username/UV_PUBLISH_USERNAMEand--password/UV_PUBLISH_PASSWORD
Debugging
Since MCP servers run over stdio, debugging can be challenging. For the best debugging experience, we strongly recommend using the MCP Inspector.
You can launch the MCP Inspector via npm with this command:
npx @modelcontextprotocol/inspector uv --directory /Users/adamshedivy/Documents/IBM/sandbox/oss/ai/db2i-ai/db2i-agents/examples/mcp/db2i-mcp-server run db2i-mcp-server
Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file db2i_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: db2i_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b72297ab2de8a4b24dae764d0ae2a9fa7469268d4352ee0820084e34ded4223
|
|
| MD5 |
03f8b43f7b2a0ad4fb0e13ae36a08083
|
|
| BLAKE2b-256 |
da20e555627034c01661978d20e6cd6066da024a0709e5e3422cedcadfde14f2
|
Provenance
The following attestation bundles were made for db2i_mcp_server-0.1.0.tar.gz:
Publisher:
publish-python.yml on ajshedivy/db2i-agents
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db2i_mcp_server-0.1.0.tar.gz -
Subject digest:
8b72297ab2de8a4b24dae764d0ae2a9fa7469268d4352ee0820084e34ded4223 - Sigstore transparency entry: 189152836
- Sigstore integration time:
-
Permalink:
ajshedivy/db2i-agents@fbb214b5f48dd35c5a91849abc7c2bf6bcea7e44 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ajshedivy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@fbb214b5f48dd35c5a91849abc7c2bf6bcea7e44 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file db2i_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: db2i_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
570a242fc87c79c7b7aaeb043bb0b0f21890d85ad72cf1ca637a537ed3a5bd12
|
|
| MD5 |
f18899ac6b10dafb9e712febf780b4c7
|
|
| BLAKE2b-256 |
a84b60b59a15373fa66fec5722531fc84dc5ade0f5b55fbd27c25935ea68f19e
|
Provenance
The following attestation bundles were made for db2i_mcp_server-0.1.0-py3-none-any.whl:
Publisher:
publish-python.yml on ajshedivy/db2i-agents
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db2i_mcp_server-0.1.0-py3-none-any.whl -
Subject digest:
570a242fc87c79c7b7aaeb043bb0b0f21890d85ad72cf1ca637a537ed3a5bd12 - Sigstore transparency entry: 189152837
- Sigstore integration time:
-
Permalink:
ajshedivy/db2i-agents@fbb214b5f48dd35c5a91849abc7c2bf6bcea7e44 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ajshedivy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@fbb214b5f48dd35c5a91849abc7c2bf6bcea7e44 -
Trigger Event:
workflow_dispatch
-
Statement type: