
MCP Database Server
io.github.Souhar-dya由 GitHub 账号 Souhar-dya 发布v1.3.1更新于 Oct 24, 2026
MCP server for SQLite, PostgreSQL, and MySQL with natural language to SQL and direct SQL tooling.
概览
一个本地 MCP 服务器,将 SQLite、PostgreSQL 和 MySQL 数据库开放给助手,把自然语言问题转换为 SQL 并返回结构化结果。
- 可以做什么
- 列出所连数据库中的表及列数,并详细描述某张表的结构。获取某张表的样本数据,快速查看内容。提交自然语言问题,获得生成的 SQL 查询结果(结构化 JSON)。检查服务健康状态。
- 适用场景
- 适合让助手用自然语言浏览和查询关系型数据库而无需手写 SQL,尤其是只读查询、了解表结构和快速取样数据。
- 运行要求
- 以本地 Docker 容器运行(或从源码用 Python 3.11+ 运行)。需要通过 DATABASE_URL 连接可访问的 SQLite、PostgreSQL 或 MySQL 数据库,并设置 MCP_API_KEY 保护数据库 HTTP 路由。需要能访问数据库主机的网络。
安装
在 SourceWeft 中
- 打开 控制台中的 MCP Database Server,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
mcp-db-server
[License] [Python] [mcpindex verdict]
An MCP (Model Context Protocol) server that exposes relational databases (PostgreSQL/MySQL) to AI agents with natural language query support. Transform natural language questions into SQL queries and get structured results.
Features
- Multi-Database Support: Works with PostgreSQL and MySQL
- Natural Language to SQL: Convert plain English queries to SQL using HuggingFace transformers
- RESTful API: Clean FastAPI-based endpoints for database operations
- Safety First: Read-only operations with query validation and result limits
- Docker Ready: Complete containerization with Docker Compose
- Production Ready: Health checks, logging, and error handling
- AI Agent Friendly: Designed specifically for AI agent integration
Version 1.4.0 Changes
- Added mandatory
X-API-Keyauthentication for all database HTTP endpoints;/healthremains public for health checks. - Removed unrestricted credentialed CORS and made allowed origins explicitly configurable.
- Changed the default HTTP bind address to
127.0.0.1. - Added table-name validation against existing database tables to block SQL injection through table routes.
- Added PostgreSQL
sslmode=requirecompatibility forasyncpgconnections. - Updated Docker Compose, environment examples, and documentation for secure API-key configuration.
- Published Docker images:
souhardyak/mcp-db-server:1.4.0souhardyak/mcp-db-server:latest
- Added GitHub Container Registry publishing for:
ghcr.io/souhar-dya/mcp-db-server:1.4.0ghcr.io/souhar-dya/mcp-db-server:latest
API Endpoints
Quick Start
Option 1: Docker Compose (Recommended)
-
Clone and start the services:
-
Test the endpoints:
Option 2: Local Development
-
Prerequisites:
- Python 3.11+
- PostgreSQL or MySQL database
-
Install dependencies:
-
Set environment variables:
-
Run the server:
Sample Database
The project includes a sample database with realistic e-commerce data:
- customers: Customer information (10 sample customers)
- orders: Order records (17 sample orders)
- order_items: Individual items within orders
- order_summary: View combining order and customer data
Natural Language Query Examples
The server can understand various types of natural language queries:
Configuration
Environment Variables
Database Connection Examples
Note:
- For MySQL cloud providers, the
ssl-modeparameter in the URL is ignored by the driver, but SSL is always enabled in the MCP server for cloud connections.- For PostgreSQL, use
sslmode=requirefor cloud DBs. For MySQL, just use the standard URL; SSL is handled automatically.- If you see errors about
ssl-modeorsslmode, check your URL and ensure you are using the correct driver prefix (mysql+aiomysqlorpostgresql+asyncpg).
Cloud Database Examples
Docker Usage with Cloud DB
GitHub Container Registry is also available:
Images are published automatically when a v*.*.* tag is pushed. The workflow also creates the matching GitHub Release. To publish an existing tag such as v1.4.0, open the workflow's Run workflow action and enter 1.4.0. Set the GHCR package visibility to Public in the repository's Packages settings if unauthenticated pulls should be allowed.
Troubleshooting
- If you get
connect() got an unexpected keyword argument 'ssl-mode', ignore it: SSL is still enabled. - For network errors, check firewall and DB credentials.
- For MySQL, always use
mysql+aiomysqlin the URL for async support.
The server normalizes sslmode=require to the ssl option expected by asyncpg. A temporary PostgreSQL verification was completed successfully against a compatible cloud database using CREATE, INSERT, SELECT, UPDATE, DELETE, and DROP; no test data was retained. Never commit or share a connection URL containing a real password.
API key authentication
MCP_API_KEY is a secret that you generate and provide to the server. It protects all database HTTP endpoints through the X-API-Key request header. The /health endpoint remains public for container health checks.
Generate a strong key on Linux or macOS:
Generate one in Windows PowerShell:
Start the Docker image with the key:
Call a protected endpoint with the same key:
Keep the key in a password manager or deployment secret store. Do not commit it to Git, put it in a public image, or include it in logs.
Security Features
- Mandatory HTTP Authentication: Database API routes require
X-API-Key;/healthremains public for health checks - Secure Network Default: HTTP mode binds to
127.0.0.1unless explicitly configured otherwise - Restricted CORS: Cross-origin access is disabled unless origins are explicitly configured
- Read-Only Operations: Only SELECT queries are allowed
- Query Validation: Automatic detection and blocking of dangerous SQL operations
- Result Limiting: Maximum 50 rows per query (configurable)
- Input Sanitization: Protection against SQL injection
- Safe Defaults: Secure configuration out of the box
Architecture
Model Context Protocol (MCP) Integration
This server is designed to work seamlessly with MCP-compatible AI agents:
- Standardized Endpoints: RESTful API following MCP conventions
- Structured Responses: JSON responses optimized for AI consumption
- Error Handling: Consistent error messages and status codes
- Documentation: OpenAPI/Swagger documentation available at
/docs
Publish To VS Code MCP Store (Registry)
VS Code MCP gallery uses MCP Registry metadata. This repository now includes
server.json for registry publication.
1) Build and publish Docker image
2) Validate server metadata
server.json is configured for an OCI package and stdio transport:
name:io.github.Souhar-dya/mcp-db-serverregistryType:ociidentifier:docker.io/souhardyak/mcp-db-server:1.3.1
The Dockerfile includes registry ownership annotation:
io.modelcontextprotocol.server.name=io.github.Souhar-dya/mcp-db-server
3) Publish to MCP Registry
Install publisher and publish metadata:
After publishing, users can discover/install it from MCP-compatible clients, including VS Code MCP experiences that read from the registry.
4) Local VS Code config example
Docker Smoke Test
Use the dedicated Docker smoke test in tests/docker:
This verifies Docker daemon access, image build, container startup, and health status.
Deployment
Docker Hub
Kubernetes
Testing
Run Tests Locally
Manual Testing
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
📝 Changelog
v1.3.0 (2025-12-24) - Docker Path Fix
- Fixed: Resolved import path issues in Docker container causing
from db import DatabaseManagerto fail - Fixed: Changed relative paths to absolute paths in Dockerfile and docker-compose.yml healthchecks
- Improved:
mcp_server.pynow uses robust path resolution that works both locally and in Docker containers - Updated: Docker image rebuilt and pushed with all path fixes
v1.2.0 (2025-11-03) - MySQL Column Access Fix
- Fixed: Resolved
Could not locate column in row for column 'column_name'error with MySQL databases - Fixed: Changed
describe_tablemethod to use index-based row access for better SQLAlchemy compatibility - Improved: Enhanced cross-database compatibility for schema introspection
- Resolved: GitHub Issue #1
v1.1.0 (2025-09-28) - Async Bug Fix
- Fixed: Resolved
str can't be used in 'await' expressionerror in MCP server - Improved: NLP query processing now works correctly with Claude Desktop integration
- Enhanced: Added comprehensive test database setup scripts
- Updated: Docker image rebuilt with bug fixes and updated dependencies
v1.0.0 (2025-09-25) - Initial Release
- Initial: Full MCP Database Server implementation
- Added: RESTful API with FastAPI
- Added: Natural language to SQL conversion
- Added: Docker containerization and deployment
- Added: Multi-database support (PostgreSQL, MySQL, SQLite)
Acknowledgments
- FastAPI for the excellent web framework
- HuggingFace Transformers for NL to SQL capabilities
- SQLAlchemy for database abstraction
- The Model Context Protocol (MCP) community
Support
⭐ If this project helped you, please consider giving it a star!
来源:README.md,提交 069028d
工具
0版本历史
1- v1.3.1最新Sep 16, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。