DEV Community

xuks124
xuks124

Posted on

MCP DB Query: 让你的AI助手直接查询MySQL、PostgreSQL、SQLite数据库

什么是MCP DB Query?

MCP DB Query 是一个 Model Context Protocol (MCP) 服务器,让Claude、Cursor等AI助手可以直接查询MySQL、PostgreSQL和SQLite数据库。不需要中间API层,不需要写后端代码。

GitHub: github.com/xuks124/mcp-db-query

核心特性

  • 多数据库支持:MySQL、PostgreSQL、SQLite 一键切换
  • 零配置:SQLite模式只需要一个文件路径
  • 只读安全设计:默认只读,支持参数化查询防注入
  • MCP协议原生兼容:可用在任何MCP客户端中

安装

npm install -g mcp-db-query
Enter fullscreen mode Exit fullscreen mode

或者克隆仓库运行:

git clone https://github.com/xuks124/mcp-db-query.git
cd mcp-db-query
npm install
Enter fullscreen mode Exit fullscreen mode

配置Claude Desktop

claude_desktop_config.json 中添加:

{
  "mcpServers": {
    "db-query": {
      "command": "node",
      "args": ["/path/to/mcp-db-query/index.js"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

使用示例

SQLite(查询本地数据库)

{
  "type": "sqlite",
  "file": "/data/app.db",
  "query": "SELECT * FROM users LIMIT 5"
}
Enter fullscreen mode Exit fullscreen mode

MySQL

{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "database": "mydb",
  "user": "root",
  "password": "pass",
  "query": "SHOW TABLES"
}
Enter fullscreen mode Exit fullscreen mode

PostgreSQL

{
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "database": "mydb",
  "user": "root",
  "password": "pass",
  "query": "SELECT * FROM users LIMIT 10"
}
Enter fullscreen mode Exit fullscreen mode

谁适合用?

  • 用Claude Desktop的开发人员
  • 用Cursor编程的开发者
  • 需要让AI直接访问数据库做数据分析的场景
  • 不想建后端API又想用AI操作数据库的人

为什么不做成REST API?

MCP的优势在于:AI客户端原生支持、不需要配置API路由、不需要处理认证和鉴权、工具调用比REST更自然。

许可证

MIT


如果你觉得这个工具对你有用,点个Star支持一下 👉 github.com/xuks124/mcp-db-query

Top comments (0)