SQLTools MCP
Allows connecting to MariaDB databases to execute SQL queries, list tables, and inspect table schemas through the MCP tools.
Allows connecting to MySQL databases to execute SQL queries, list tables, and inspect table schemas through the MCP tools.
Allows connecting to PostgreSQL databases to execute SQL queries, list tables, and inspect table schemas through the MCP tools.
Allows connecting to SQLite database files to execute SQL queries, list tables, and inspect table schemas through the MCP tools.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
SQLTools MCP
[English] | [中文]
SQLTools MCP 是一个全能型数据库访问服务,基于 Model Context Protocol (MCP) 开发。
它的核心痛点解决能力是:无需为每种数据库安装独立的 MCP Server,只需这一个服务,即可让 AI 助手同时支持 MySQL、Postgres、SQL Server、达梦 (DM8) 以及 SQLite。
✨ 核心能力
🔌 全能数据库适配:
MySQL / MariaDB
PostgreSQL
SQL Server (MSSQL)
达梦 (DM8) (国内主流国产数据库)
SQLite (本地文件数据库)
🔄 一键切换:同一个 AI 会话中可以随时通过
connect_database切换到不同的数据库环境。🛡️ 生产安全:具备 SQL 注入防护和针对破坏性操作(DROP/TRUNCATE 等)的预警提示。
📊 优化体验:支持大数据量分页加载,失败时提供智能修复建议。
Related MCP server: MCP Database Manager
📦 快速安装
# 克隆并进入目录
git clone https://github.com/huangzt/sqltools_mcp
cd sqltools-mcp
# 建议在虚拟环境中安装
pip install -e .
# 安装您需要的驱动
pip install pymysql # MySQL
pip install psycopg2-binary # PostgreSQL
pip install pymssql # SQL Server
pip install jaydebeapi # DM8 (需要 Java 环境)⚙️ 配置指南
环境变量
你可以在启动 MCP 服务时设置以下环境变量来实现自动连接:
变量名 | 说明 | 默认值 |
| 数据库类型 (mysql, postgres, mssql, dm8, sqlite) |
|
| 数据库主机地址 |
|
| 端口号 (0 则使用各协议默认端口) |
|
| 数据库用户名 | - |
| 数据库密码 | - |
| 数据库名 (SQLite 为文件绝对路径) | - |
🚀 AI 客户端配置
1. Google Antigravity
编辑 ~/.gemini/antigravity/mcp_config.json:
{
"mcpServers": {
"sqltools": {
"command": "python",
"args": ["-m", "sqltools_mcp.server"],
"env": {
"DB_TYPE": "sqlite",
"DB_NAME": "/path/to/your/db.sqlite"
}
}
}
}2. Claude Desktop
编辑配置文件:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"sqltools": {
"command": "python",
"args": ["-m", "sqltools_mcp.server"],
"env": {
"DB_TYPE": "mysql",
"DB_HOST": "localhost",
"DB_USER": "root",
"DB_PASSWORD": "password",
"DB_NAME": "test"
}
}
}
}3. Cursor / Windsurf
在 Settings -> Features -> MCP (Cursor) 或 Settings -> MCP (Windsurf) 中添加:
Name:
sqltoolsType:
commandCommand:
python -m sqltools_mcp.server
4. Roo Code (原 Roo Cline)
在 VS Code 中打开 Roo Code 设置,在 MCP Config 中添加:
"sqltools": {
"command": "python",
"args": ["-m", "sqltools_mcp.server"]
}5. Zed
编辑 ~/.zed/settings.json:
{
"context_protocols": [
{
"mcp": {
"servers": {
"sqltools": {
"command": "python",
"args": ["-m", "sqltools_mcp.server"]
}
}
}
}
]
}6. Continue (VS Code / JetBrains)
编辑 ~/.continue/config.json:
{
"mcpServers": [
{
"name": "sqltools",
"command": "python",
"args": ["-m", "sqltools_mcp.server"]
}
]
}🛠️ 工具详情 (Tools)
AI 模型可以通过以下英文接口与数据库交互:
1. connect_database
连接或切换到目标数据库。
参数:
dbtype(必填),host,port,username,password,dbname.特性: 自动断开旧连接,验证新连接可用性。
2. execute_sql
执行 SQL 查询。
参数:
query(必填),timeout.特性: 支持 SELECT 和 DML 语句;自动处理数据类型转换。
3. list_tables
列出数据库中的所有表。
参数:
schema,limit(默认 100),offset(默认 0).特性: 支持分页,返回表类型和行数估计。
4. describe_table
查看特定表的结构。
参数:
table_name(必填),schema.特性: 返回详尽的列信息:名称、类型、是否可空、主键标志、默认值等。
5. get_connection_status
检查当前连接状态。
特性: 返回当前连接的协议类型和基本配置(不含密码)。
🛡️ 安全性
本项目在 SECURITY.md 中详细列出了安全措施,包括表名转义和破坏性操作提醒,确保 AI 在操作数据库时的基本安全性。
📄 开源协议
基于 MIT License 开源。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
Query, explore, and manage your databases through natural conversation.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to securely interact with MariaDB and MySQL databases using granular per-connection read/write permissions and transaction support. It allows users to manage multiple database connections, explore schemas, and execute controlled SQL queries through a standardized interface.625 npm5MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with and manage multiple database types (PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, Redis) through natural language, supporting query analysis, schema management, data analysis, backup/restore, and security analysis.8 npm2MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.13MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to directly query MySQL databases, list tables, and view table structures through natural language.20 npmMIT