Skip to main content

A read-only MCP server for interacting with a DB2 database.

Project description

db2-mcp-server

PyPI version License: MIT Coverage

Overview

The db2-mcp-server is a Python-based server utilizing the MCP framework to interact with IBM DB2 databases. It provides tools for listing tables and retrieving table metadata.

Features

  • List Tables: Retrieve a list of tables from the connected DB2 database.
  • Get Table Metadata: Fetch metadata for a specific table, including column details and data types.
  • Dynamic Prompt Loading: Load custom prompts from JSON configuration files for flexible query assistance.
  • Built-in Prompts: Pre-configured prompts for DB2 query help and schema analysis.

Requirements

  • Python 3.12
  • FastMCP (latest stable version)
  • IBM DB2 Python driver (ibm_db)
  • Pydantic

Setup Instructions

  1. Clone the Repository

    git clone <repository-url>
    cd db2-mcp-server
    
  2. Set Up Virtual Environment

    uv v0.6.x
    source uv/bin/activate
    
  3. Install Dependencies

    pip install -r requirements.txt
    
  4. Run the Server

    python src/db2_mcp_server/core.py
    

Dynamic Prompts

The server supports dynamic prompt loading from JSON configuration files. Set the PROMPTS_FILE environment variable to specify a custom prompts configuration file.

Example Usage

export PROMPTS_FILE=/path/to/your/prompts_config.json
python src/db2_mcp_server/core.py

Configuration Format

See examples/prompts_config.json for a complete example and docs/DYNAMIC_PROMPTS.md for detailed documentation.

Testing

  • Use pytest (version ≥ 7.0.0) for running tests.
  • Current test coverage: 92.98% (exceeding the 80% requirement).
  • Comprehensive test suite includes:
    • Core functionality tests (test_core.py)
    • Database tools tests (test_list_tables.py, test_metadata_retrieval.py)
    • Caching mechanism tests (test_cache.py)
    • Logging configuration tests (test_logger.py)
    • Dynamic prompt loading tests (test_dynamic_loader.py, test_integration_dynamic_prompts.py)
  • Run tests with:
    pytest --cov=src/db2_mcp_server --cov-report=html tests/
    
  • For verbose output:
    pytest --cov=src/db2_mcp_server --cov-report=term-missing -v
    

Security and API Restrictions

  • The server is read-only, prohibiting SQL INSERT, UPDATE, or DELETE operations.
  • Uses a database user with only SELECT privileges.

Logging

  • Errors are logged with structured logs in JSON format, excluding sensitive data.

Contribution

  • Contributions are welcome. Please follow the project's coding standards and testing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db2_mcp_server-0.2.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db2_mcp_server-0.2.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file db2_mcp_server-0.2.0.tar.gz.

File metadata

  • Download URL: db2_mcp_server-0.2.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for db2_mcp_server-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7bd4cd80994de8e57156fa1f860fc2f969e06289c1f48176ed32494a25dad2d6
MD5 43d2070de2a0ae1b0ff7b74edc233f3a
BLAKE2b-256 76e2d303c9e2f1b22a283990c42307db13b774d40f61de8c4b0c9f6e753b4e5f

See more details on using hashes here.

File details

Details for the file db2_mcp_server-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: db2_mcp_server-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for db2_mcp_server-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23d6435795325e7096c4d857f9b081c3637471823b78d750b3166e53d6807834
MD5 220f8a98aef1fdd52113bc646a8dc0a6
BLAKE2b-256 5be070b9a88f989502199260bdc835aec28815f2f395451fccd4d4d663cef910

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page