Multi-Database MCP Server
Enables simultaneous querying and schema exploration across multiple database types, including PostgreSQL, MySQL, SQL Server, and SQLite. It supports parallel query execution and detailed inspection of tables and schemas across different database instances.
README
Multi-Database MCP Server
An MCP (Model Context Protocol) server that provides tools to access multiple databases simultaneously. The server runs in Docker and supports querying multiple databases of different types in parallel. This server was inspired by needs to compare databases or support migrations.
Features
- Multiple Database Types: Support for PostgreSQL, MySQL/MariaDB, SQL Server, and SQLite
- Multiple Database Support: Connect to and query multiple databases simultaneously (even different types)
- Parallel Queries: Execute the same query across multiple databases at once
- Schema Exploration: List databases, schemas, tables, and describe table structures
- Dockerized: Runs in a Docker container for easy deployment
- Connection Pooling: Efficient connection management for all database types
- Flexible Configuration: Organize databases by type
Available Tools
- list_databases - List all configured database connections
- query_database - Execute a SQL query on a specific database
- list_tables - List all tables in a database schema
- describe_table - Get detailed schema information for a table
- list_schemas - List all schemas in a database
- query_multiple_databases - Execute the same query on multiple databases simultaneously
Setup
1. Create Database Configuration
Copy the example configuration file and edit it with your database credentials:
cp databases.json.example databases.json
Edit databases.json with your database connection details. Organize databases by type at the root level:
{
"postgresql": {
"postgres_db": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "your_password",
"database": "database1"
},
"another_postgres": {
"host": "remote.example.com",
"port": 5432,
"user": "admin",
"password": "secret",
"database": "production"
}
},
"mysql": {
"mysql_db": {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "your_password",
"database": "mydatabase"
}
},
"sqlserver": {
"sqlserver_db": {
"host": "localhost",
"port": 1433,
"user": "sa",
"password": "your_password",
"database": "MyDatabase"
}
},
"sqlite": {
"sqlite_db": {
"database": "/path/to/database.db"
}
}
}
Supported Database Types
- PostgreSQL (
"postgresql","postgres", or"pg") - MySQL/MariaDB (
"mysql"or"mariadb") - SQL Server (
"sqlserver","mssql", or"sql server") - SQLite (
"sqlite"or"sqlite3")
2. Build and Run with Docker Compose
docker-compose up --build
3. Build and Run with Docker
# Build the image
docker build -t multidb-mcp-server .
# Run the container
docker run -it \
-v $(pwd)/databases.json:/app/databases.json:ro \
multidb-mcp-server
4. Docker Connection Tips
When configuring database connections from within Docker, keep these tips in mind:
Network Connections (PostgreSQL, MySQL, SQL Server)
- Accessing host machine databases: Use
host.docker.internalas the hostname (Windows/Mac) or172.17.0.1(Linux) - Accessing other containers: Use the container name or service name from
docker-compose.yml - Accessing remote databases: Use the actual hostname or IP address
Example for accessing PostgreSQL on host machine:
{
"postgresql": {
"local_db": {
"host": "host.docker.internal",
"port": 5432,
"user": "postgres",
"password": "password",
"database": "mydb"
}
}
}
Example for accessing database in another Docker container:
{
"postgresql": {
"container_db": {
"host": "postgres-container",
"port": 5432,
"user": "postgres",
"password": "password",
"database": "mydb"
}
}
}
Example for accessing SQL Server on host machine:
{
"sqlserver": {
"sqlserver_db": {
"host": "host.docker.internal",
"port": 1433,
"user": "sa",
"password": "password",
"database": "MyDatabase"
}
}
}
Note for SQL Server: Ensure that SQL Server is configured to accept TCP/IP connections and that the SQL Server Browser service is running if using named instances. The default port is 1433.
File Paths (SQLite)
- SQLite databases on host: Mount the directory containing the database file as a volume and use the container path
- SQLite databases in container: Use absolute paths within the container
Example Docker run command with SQLite volume:
docker run -it \
-v $(pwd)/databases.json:/app/databases.json:ro \
-v $(pwd)/data:/app/data:ro \
multidb-mcp-server
Example SQLite configuration:
{
"sqlite": {
"local_db": {
"database": "/app/data/mydatabase.db"
}
}
}
Note: The path /app/data/mydatabase.db is the path inside the container, which maps to ./data/mydatabase.db on your host machine via the volume mount.
Usage
The server communicates via stdio using the MCP protocol. Connect your MCP client to the Docker container's stdio streams.
Example MCP Client Configuration
If using with an MCP client, configure it to connect to the Docker container:
{
"mcpServers": {
"multidb": {
"command": "docker",
"args": [
"run",
"-i",
"-v",
"[YOUR/PATH]/databases.json:/app/databases.json:ro",
"multidb-mcp-server"
]
}
}
}
Tool Examples
List All Databases
{
"tool": "list_databases",
"arguments": {}
}
Query a Single Database
{
"tool": "query_database",
"arguments": {
"database_name": "db1",
"query": "SELECT * FROM users LIMIT 10"
}
}
List Tables
{
"tool": "list_tables",
"arguments": {
"database_name": "db1",
"schema": "public"
}
}
Describe a Table
{
"tool": "describe_table",
"arguments": {
"database_name": "db1",
"table_name": "users",
"schema": "public"
}
}
Query Multiple Databases Simultaneously
You can query multiple databases of different types simultaneously:
{
"tool": "query_multiple_databases",
"arguments": {
"database_names": ["db1", "db2", "sqlserver_db"],
"query": "SELECT COUNT(*) as total FROM users"
}
}
Note: When querying multiple databases of different types, ensure the SQL syntax is compatible across all database types, or use database-specific queries for each database separately.
Development
Local Development (without Docker)
- Install dependencies:
pip install -r requirements.txt
- Set environment variable:
export DB_CONFIG_PATH=./databases.json
- Run the server:
python server.py
Database-Specific Notes
PostgreSQL
- Default port: 5432
- Default schema:
public - Uses
asyncpgfor async operations
MySQL/MariaDB
- Default port: 3306
- Schema parameter is optional (uses current database)
- Uses
aiomysqlfor async operations
SQL Server
- Default port: 1433
- Default schema:
dbo - Requires ODBC Driver 17 for SQL Server (installed in Docker image)
- Uses
pyodbcwith asyncio wrapper - Important: SQL Server must be configured to accept TCP/IP connections
- For named instances, ensure SQL Server Browser service is running
- Use
host.docker.internalto connect to SQL Server on the host machine from Docker
SQLite
- No network connection required
- Use
databasefield to specify file path (or:memory:for in-memory) - Default schema:
main - Uses
aiosqlitefor async operations
Security Notes
- Never commit
databases.json- It contains sensitive credentials - Use environment variables or secrets management in production
- Consider using SSL/TLS connections for remote databases
- Limit network access to the Docker container
- For SQLite, ensure file paths are secure and accessible
Troubleshooting
Connection Issues
- Verify database credentials in
databases.json - Ensure databases are accessible from the Docker container
- Check network connectivity (use
docker networkfor container-to-container communication)
Permission Issues
- Ensure the
databases.jsonfile has proper read permissions - Check that the Docker volume mount is correct
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。