MCP DB Server
Provides read-only SQL query capabilities, schema discovery, and table listing for SQLite databases.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP DB Servershow me the schema of the employees table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP DB Server
让 AI Agent 通过自然语言查询数据库的 MCP 服务器
基于 Model Context Protocol (MCP) 构建,提供只读数据库查询能力。支持自动 Schema 发现、SQL 查询执行、安全校验。
项目结构
mcp-db-server/
├── src/
│ ├── server.py # MCP 服务入口 + 4 个工具
│ ├── db.py # 数据库连接 + Schema 发现
│ └── safety.py # SQL 安全校验(只读模式)
├── sample.db # 示例 SQLite 数据库
├── .env # 数据库连接配置
├── .env.example # 配置模板
├── requirements.txt # 依赖
├── setup_sample_db.py# 创建示例数据库
└── test_server.py # 测试脚本Related MCP server: TextQL MCP Server
快速开始
⚡ 选择你的终端
根据你用的终端,Python 命令写法不同:
终端 | 命令 |
Git Bash(Claude Code 默认) |
|
PowerShell |
|
cmd |
|
以下所有命令以 Git Bash 为例,换成你的终端对应写法即可。
1. 安装依赖
pip install mcp python-dotenv2. 配置数据库
编辑 .env 文件:
DATABASE_URL=sqlite:///sample.db当前支持 SQLite。示例数据库包含 departments 和 employees 两张表。
3. 启动服务
# Git Bash:
/d/anaconda/python -m src.server
# PowerShell/cmd:
D:\anaconda\python.exe -m src.server4. 用 MCP Inspector 调试(推荐)
# Git Bash:
/d/anaconda/Scripts/mcp dev src/server.py
# PowerShell/cmd:
D:\anaconda\Scripts\mcp.exe dev src/server.py这会启动一个 Web 调试界面(http://localhost:5173),在浏览器中测试所有工具。
5. 集成到 Claude Desktop
在 Claude Desktop 的配置 claude_desktop_config.json 中添加:
{
"mcpServers": {
"mcp-db-server": {
"command": "D:\\anaconda\\python.exe",
"args": ["-m", "src.server"],
"cwd": "C:\\Users\\86150\\source\\repos\\mcp-db-server"
}
}
}可用工具
工具 | 参数 | 说明 |
| 无 | 列出所有表名 |
|
| 查看指定表的结构 |
| 无 | 查看完整数据库结构概览 |
|
| 执行 SELECT 查询 |
安全特性
只读模式:仅允许 SELECT 语句,拦截 INSERT/UPDATE/DELETE/DROP 等
CTE 支持:允许
WITH ... SELECT复杂查询错误提示:被拦截时会给出明确原因
测试验证
# Git Bash:
/d/anaconda/python test_server.py
# PowerShell/cmd:
D:\anaconda\python.exe test_server.py简历项目描述
Database MCP Server — 基于 Model Context Protocol 构建的数据库查询代理服务器
设计并实现了 MCP 协议服务端,提供 4 个标准化工具接口供 AI Agent 调用
实现自动 Schema 发现,支持动态获取表结构和字段信息
构建只读 SQL 安全校验层,防止 DDL/DML 操作,确保数据安全
支持 SQLite,架构可扩展至 MySQL/PostgreSQL
集成 Claude Desktop,实现自然语言驱动的数据库查询
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with SQLite databases by executing read and write queries, listing tables, and inspecting schemas. It provides a secure, local interface for database management and data retrieval through the Model Context Protocol.2MIT
- AlicenseNot gradedqualityDmaintenanceTranslates natural language to SQL/GraphQL queries and executes them, enabling AI agents to interact with databases through the Model Context Protocol.1Apache 2.0
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to connect to and query an SQLite database through the Model Context Protocol, allowing natural language interaction with database tables and data.-
- FlicenseNot gradedqualityDmaintenanceEnables natural-language querying of structured data via Model Context Protocol, allowing AI agents to answer questions without SQL or API knowledge.-