npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xuejike/coding-db-mcp

v1.0.4

Published

MCP (Model Context Protocol) service for querying multiple types of databases (MySQL, PostgreSQL, MSSQL, Oracle) via stdio transport

Readme

MCP 数据库查询工具

这是一个用于Coding Agent MCP 服务的数据库查询工具,可以通过提示词,从当前项目配置文件中读取数据库连接信息并连接多种类型的数据库(MySQL、PostgreSQL、MSSQL、Oracle)并执行 SQL 查询。该工具运行在只读模式下,确保不会意外修改数据库中的数据

功能特点

  • 支持连接多种数据库(MySQL、PostgreSQL、MSSQL、Oracle)
  • 执行自定义 SQL 查询(只读模式)
  • 自动阻止修改数据的操作(INSERT、UPDATE、DELETE等)
  • 返回结构化查询结果
  • 包含错误处理机制
  • 实现为 MCP stdio 服务

安全特性

该工具具有以下安全保护措施:

  1. 只读模式:自动检测并阻止任何修改数据的SQL操作
  2. SQL语句检查:只允许SELECT、SHOW、DESCRIBE等只读查询
  3. 错误处理:对非法操作返回明确的错误信息

安装说明

方式一:从 npm 仓库进行全局安装

您可以从 npm 仓库进行全局安装:

npm install -g @xuejike/coding-db-mcp

安装后,您可以通过以下命令启动服务:

db-query-mcp

方式二:使用 npx 运行(无需安装)

您也可以直接使用 npx 运行此工具,无需预先安装:

npx @xuejike/coding-db-mcp

这种方式会在每次运行时临时下载并执行最新版本的工具。

配置到 Agent 的 MCP 中

要将此服务配置到 Agent 的 MCP 中,请按照以下步骤操作:

1. 配置 Agent 的 MCP 设置

在 Agent 的 MCP 配置中添加此服务。通常需要在 Agent 的配置文件中添加类似以下的配置:

{
  "mcpServers": {
    "database-query": {
      "command": "coding-db-mcp",
      "args": [
        
      ]
    }
  }
}

如果使用 npx 方式,配置应为:

{
  "mcpServers": {
    "database-query": {
      "command": "npx",
      "args": [
        "@xuejike/coding-db-mcp"
      ]
    }
  }
}

2. 配置数据库连接信息(可选)

数据库连接信息文件不是必需的,Agent 可以通过提示词从当前项目配置文件中自动读取数据库连接信息。

例如,在 Spring Boot 项目中,Agent 可以直接读取 application-dev.yaml 文件中的数据库连接配置。

如果需要手动配置数据库连接信息,可以创建 .env 文件:

cp .env.example .env

.env 文件中设置以下变量:

  • DB_HOST: 数据库主机地址
  • DB_PORT: 数据库端口
  • DB_USER: 数据库用户名
  • DB_PASSWORD: 数据库密码
  • DB_NAME: 数据库名称

3. 启动 Agent

启动 Agent 并确保 MCP 服务正确加载。Agent 现在应该能够使用以下四个数据库查询工具:

  • query_mysql: MySQL 数据库查询工具
  • query_postgresql: PostgreSQL 数据库查询工具
  • query_mssql: MSSQL 数据库查询工具
  • query_oracle: Oracle 数据库查询工具

当 Agent 需要查询数据库时,它会自动调用相应的工具并传入必要的参数(主机、端口、用户名、密码、数据库名和SQL查询语句)。

MCP工具说明

当作为MCP服务运行时,该服务提供以下工具:

query_mysql

执行MySQL数据库查询(只读模式)

参数:

  • host (string): 数据库主机地址
  • port (integer): 数据库端口
  • user (string): 数据库用户名
  • pwd (string): 数据库密码
  • db (string): 数据库名称
  • querySql (string): 要执行的SQL查询语句(仅支持SELECT等只读操作)

query_postgresql

执行PostgreSQL数据库查询(只读模式)

参数:

  • host (string): 数据库主机地址
  • port (integer): 数据库端口
  • user (string): 数据库用户名
  • pwd (string): 数据库密码
  • db (string): 数据库名称
  • querySql (string): 要执行的SQL查询语句(仅支持SELECT等只读操作)

query_mssql

执行MSSQL数据库查询(只读模式)

参数:

  • host (string): 数据库主机地址
  • port (integer): 数据库端口
  • user (string): 数据库用户名
  • pwd (string): 数据库密码
  • db (string): 数据库名称
  • querySql (string): 要执行的SQL查询语句(仅支持SELECT等只读操作)

query_oracle

执行Oracle数据库查询(只读模式)

参数:

  • host (string): 数据库主机地址
  • port (integer): 数据库端口
  • user (string): 数据库用户名
  • pwd (string): 数据库密码
  • db (string): 数据库名称
  • querySql (string): 要执行的SQL查询语句(仅支持SELECT等只读操作)

安全说明

  1. 该工具运行在只读模式下,自动阻止任何修改数据的SQL操作
  2. 建议限制数据库用户权限,避免使用具有管理员权限的账户
  3. 不要在代码中硬编码数据库凭证
  4. 生产环境中应启用SSL连接

错误处理

工具会返回结构化的错误信息,包括:

  • success: 布尔值,表示查询是否成功
  • error: 错误消息
  • code: 错误代码

返回格式

成功的查询将返回以下结构:

  • success: true
  • data: 查询结果数组
  • columns: 列信息数组
  • rowCount: 返回行数