MCP ExplorerExplorer

Db Query Mcp

@NewToolAIon 9 months ago
4 Apache-2.0
FreeCommunity
AI Systems
db-query-mcp is an MCP tool that enables data querying and export operations across diverse databases.

Overview

What is Db Query Mcp

db-query-mcp is an MCP tool designed for data querying and export operations across various databases, ensuring compatibility with mainstream relational databases such as MySQL, PostgreSQL, Oracle, and SQLite.

Use cases

Use cases for db-query-mcp include generating reports from multiple databases, exporting data for analysis, integrating with web applications for dynamic data retrieval, and facilitating data migration tasks.

How to use

To use db-query-mcp, install it via pip with ‘pip install db-query-mcp’. For specific databases, additional dependencies may be required, such as ‘pymysql’ for MySQL or ‘psycopg2-binary’ for PostgreSQL. You can connect to your database using the appropriate connection string.

Key features

Key features of db-query-mcp include multi-database support, secure access with a default read-only mode, smart query capabilities for efficient SQL generation and execution, and data export functionality. Future updates will expand support to additional databases like Elasticsearch and MongoDB.

Where to use

db-query-mcp can be utilized in various fields such as data analysis, business intelligence, application development, and any scenario requiring efficient data querying across different database systems.

Content

image

Python Version
License
PyPI
GitHub pull request

[ English | 中文 ]

db-query-mcp

Introduction

db-query-mcp is a mcp tool supporting diverse database querying and exporting, featuring:

  • Multi-DB Support: Full compatibility with mainstream databases (ElasticSearch, MySQL, PostgreSQL, Oracle, SQLite, etc.)
  • Secure Access: Default read-only mode for data protection
  • Smart Query: Natural language to SQL conversion with query optimization
  • Data Export: CSV / Json export capabilities
  • Roadmap: Expanding support for MongoDB and GraphDatabase to become full-stack DB query MCP

Demo

https://github.com/user-attachments/assets/60771cda-8b52-41bd-90e3-523c836f6366

Changelog

  • 2025-06-02: Added support for ElasticSearch database queries

Installation

pip install db-query-mcp

ElasticSearch:

pip install "db-query-mcp[elasticsearch]"

Install from GitHub:

pip install git+https://github.com/NewToolAI/db-query-mcp

MySQL requires additional dependencies:

pip install pymysql

PostgreSQL requires additional dependencies:

pip install psycopg2-binary

For other databases, install their respective connection packages:

Database Connection Package Example Connection String
SQLite Built-in Python sqlite:///example.db
MySQL pymysql or mysql-connector-python mysql+pymysql://user:password@localhost/dbname
PostgreSQL psycopg2 or psycopg2-binary postgresql://user:password@localhost:5432/dbname
Oracle cx_Oracle oracle+cx_oracle://user:password@hostname:1521/sidname
SQL Server pyodbc or pymssql mssql+pyodbc://user:password@hostname/dbname

Configuration

Note: ​For certain clients, such as Cursor, only one db-query-mcp server can run at a time.​​

Run using uvx

{
  "mcpServers": {
    "sqlite_db_mcp": {
      "command": "uvx",
      "args": [
        "db-query-mcp",
        "--db",
        "sqlite",
        "--uri",
        "sqlite:///sqlite_company.db"
      ]
    }
  }
}
{
  "mcpServers": {
    "es_db_mcp": {
      "command": "uvx",
      "args": [
        "db-query-mcp",
        "--db",
        "elasticsearch",
        "--uri",
        "https://user:password@localhost:9200?index=test_data_index&ca_certs=/home/user/http_ca.crt"
      ]
    }
  }
}

Run Using command

{
  "mcpServers": {
    "sqlite_db_mcp": {
      "command": "db-query-mcp",
      "args": [
        "--db",
        "sqlite",
        "--uri",
        "sqlite:///sqlite_company.db"
      ]
    }
  }
}
{
  "mcpServers": {
    "es_db_mcp": {
      "command": "db-query-mcp",
      "args": [
        "--db",
        "elasticsearch",
        "--uri",
        "https://user:password@localhost:9200?index=test_data_index&ca_certs=/home/user/http_ca.crt"
      ]
    }
  }
}

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers