多种数据库查询MCP

@NewToolAI/db-query-mcp
1 Stars 1.6k 次浏览 NewToolAI 更新于 2026-08-23

db-query-mcp 是一个支持多种数据库查询和导出的 MCP 工具。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

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

服务介绍

Python Version
License
PyPI
GitHub pull request

[ 中文 | English ]

db-query-mcp

简介

db-query-mcp 是一个支持多种数据库查询和导出的 MCP 工具,具有以下核心特性:

  • ​多数据库支持​:全面兼容主流关系型数据库(ElasticSearch、MySQL、PostgreSQL、Oracle、SQLite等);
  • 安全访问​:默认以只读模式连接数据库,保障数据安全;
  • 智能查询​:提供高效的查询语句生成与执行能力;
  • ​数据导出​:支持查询结果导出功能;
  • 未来版本规划将扩展对 MongoDB 以及 GraphDatabase 的支持,致力于成为全栈式数据库查询 MCP。

演示

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

更新日志

  • 2025-06-02: 支持ElasticSearch数据库查询

安装

关系数据库:

pip install db-query-mcp

ElasticSearch:

pip install db-query-mcp[elasticsearch]

源码安装:

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

mysql需要额外安装依赖:

pip install pymysql

postgredb需要额外安装依赖:

pip install psycopg2-binary

对于其他数据库,需要额外安装相应的数据库连接包。

Database Connection Package Example Connection String
SQLite (Python 内置) sqlite:///example.db
MySQL pymysqlmysql-connector-python mysql+pymysql://user:password@localhost/dbname
PostgreSQL psycopg2、psycopg2-binary postgresql://user:password@localhost:5432/dbname
Oracle cx_Oracle oracle+cx_oracle://user:password@hostname:1521/sidname
SQL Server pyodbcpymssql mssql+pyodbc://user:password@hostname/dbname

配置

{
  "mcpServers": {
    "sqlite_db_mcp": {
      "command": "db-query-mcp",
      "args": [
        "--db",
        "sqlite",
        "--uri",
        "sqlite:///sqlite_company.db"
      ]
    },
    "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"
      ]
    }
  }
}

相关 MCP 服务