Multi Database MCP Server
A unified server for structured, multi-database access via the Model Context Protocol.
Key Features
Use Cases
README
Multi Database MCP Server
Overview
The DB MCP Server provides a standardized way for AI models to interact with multiple databases simultaneously. Built on the FreePeak/cortex framework, it enables AI assistants to execute SQL queries, manage transactions, explore schemas, and analyze performance across different database systems through a unified interface.
Core Concepts
Multi-Database Support
Unlike traditional database connectors, DB MCP Server can connect to and interact with multiple databases concurrently:
{
"connections": [
{
"id": "mysql1",
"type": "mysql",
"host": "localhost",
"port": 3306,
"name": "db1",
"user": "user1",
"password": "password1"
},
{
"id": "postgres1",
"type": "postgres",
"host": "localhost",
"port": 5432,
"name": "db2",
"user": "user2",
"password": "password2"
}
]
}
Dynamic Tool Generation
For each connected database, the server automatically generates specialized tools:
// For a database with ID "mysql1", these tools are generated:
query_mysql1 // Execute SQL queries
execute_mysql1 // Run data modification statements
transaction_mysql1 // Manage transactions
schema_mysql1 // Explore database schema
performance_mysql1 // Analyze query performance
Clean Architecture
The server follows Clean Architecture principles with these layers:
- Domain Layer: Core business entities and interfaces
- Repository Layer: Data access implementations
- Use Case Layer: Application business logic
- Delivery Layer: External interfaces (MCP tools)
Features
- Simultaneous Multi-Database Support: Connect to multiple MySQL and PostgreSQL databases concurrently
- Database-Specific Tool Generation: Auto-creates specialized tools for each connected database
- Clean Architecture: Modular design with clear separation of concerns
- OpenAI Agents SDK Compatibility: Full compatibility for seamless AI assistant integration
- Dynamic Database Tools: Execute queries, run statements, manage transactions, explore schemas, analyze performance
- Unified Interface: Consistent interaction patterns across different database types
- Connection Management: Simple configuration for multiple database connections
Supported Databases
| Database | Status | Features |
|---|---|---|
| MySQL | ✅ Full Support | Queries, Transactions, Schema Analysis, Performance Insights |
| PostgreSQL | ✅ Full Support (v9.6-17) | Queries, Transactions, Schema Analysis, Performance Insights |
| TimescaleDB | ✅ Full Support | Hypertables, Time-Series Queries, Continuous Aggregates, Compression, Retention Policies |
Deployment Options
The DB MCP Server can be deployed in multiple ways to suit different environments and integration needs:
Docker Deployment
# Pull the latest image
docker pull freepeak/db-mcp-server:latest
# Run with mounted config file
docker run -p 9092:9092 \
-v $(pwd)/config.json:/app/my-config.json \
-e TRANSPORT_MODE=sse \
-e CONFIG_PATH=/app/my-config.json \
freepeak/db-mcp-server
Note: Mount to
/app/my-config.jsonas the container has a default file at/app/config.json.
STDIO Mode (IDE Integration)
# Run the server in STDIO mode
./bin/server -t stdio -c config.json
For Cursor IDE integration, add to .cursor/mcp.json:
{
"mcpServers": {
"stdio-db-mcp-server": {
"command": "/path/to/db-mcp-server/server",
"args": ["-t", "stdio", "-c", "/path/to/config.json"]
}
}
}
SSE Mode (Server-Sent Events)
# Default configuration (localhost:9092)
./bin/server -t sse -c config.json
# Custom host and port
./bin/server -t sse -host 0.0.0.0 -port 8080 -c config.json
Client connection endpoint: http://localhost:9092/sse
Source Code Installation
# Clone the repository
git clone https://github.com/FreePeak/db-mcp-server.git
cd db-mcp-server
# Build the server
make build
# Run the server
./bin/server -t sse -c config.json
Configuration
Database Configuration File
Create a config.json file with your database connections:
{
"connections": [
{
"id": "mysql1",
"type": "mysql",
"host": "mysql1",
"port": 3306,
"name": "db1",
"user": "user1",
"password": "password1",
"query_timeout": 60,
"max_open_conns": 20,
"max_idle_conns": 5,
"conn_max_lifetime_seconds": 300,
"conn_max_idle_time_seconds": 60
},
{
"id": "postgres1",
"type": "postgres",
"host": "postgres1",
"port": 5432,
"name": "db1",
"user": "user1",
"password": "password1"
}
]
}
Command-Line Options
# Basic syntax
./bin/server -t <transport> -c <config-file>
# SSE transport options
./bin/server -t sse -host <hostname> -port <port> -c <config-file>
# Inline database configuration
./bin/server -t stdio -db-config '{"connections":[...]}'
# Environment variable configuration
export DB_CONFIG='{"connections":[...]}'
./bin/server -t stdio
Available Tools
For each connected database, DB MCP Server automatically generates these specialized tools:
Query Tools
| Tool Name | Description |
|---|---|
query_<db_id> |
Execute SELECT queries and get results as a tabular dataset |
execute_<db_id> |
Run data manipulation statements (INSERT, UPDATE, DELETE) |
transaction_<db_id> |
Begin, commit, and rollback transactions |
Schema Tools
| Tool Name | Description |
|---|---|
schema_<db_id> |
Get information about tables, columns, indexes, and foreign keys |
generate_schema_<db_id> |
Generate SQL or code from database schema |
Performance Tools
| Tool Name | Description |
|---|---|
performance_<db_id> |
Analyze query performance and get optimization suggestions |
TimescaleDB Tools
For PostgreSQL databases with TimescaleDB extension, these additional specialized tools are available:
| Tool Name | Description |
|---|---|
timescaledb_<db_id> |
Perform general TimescaleDB operations |
create_hypertable_<db_id> |
Convert a standard table to a TimescaleDB hypertable |
list_hypertables_<db_id> |
List all hypertables in the database |
time_series_query_<db_id> |
Execute optimized time-series queries with bucketing |
time_series_analyze_<db_id> |
Analyze time-series data patterns |
continuous_aggregate_<db_id> |
Create materialized views that automatically update |
refresh_continuous_aggregate_<db_id> |
Manually refresh continuous aggregates |
For detailed documentation on TimescaleDB tools, see TIMESCALEDB_TOOLS.md.
Examples
Querying Multiple Databases
-- Query the first database
query_mysql1("SELECT * FROM users LIMIT 10")
-- Query the second database in the same context
query_postgres1("SELECT * FROM products WHERE price > 100")
Managing Transactions
-- Start a transaction
transaction_mysql1("BEGIN")
-- Execute statements within the transaction
execute_mysql1("INSERT INTO orders (customer_id, product_id) VALUES (1, 2)")
execute_mysql1("UPDATE inventory SET stock = stock - 1 WHERE product_id = 2")
-- Commit or rollback
transaction_mysql1("COMMIT")
-- OR
transaction_mysql1("ROLLBACK")
Exploring Database Schema
-- Get all tables in the database
schema_mysql1("tables")
-- Get columns for a specific table
schema_mysql1("columns", "users")
-- Get constraints
schema_mysql1("constraints", "orders")
Troubleshooting
Common Issues
- Connection Failures: Verify network connectivity and database credentials
- Permission Errors: Ensure the database user has appropriate permissions
- Timeout Issues: Check the
query_timeoutsetting in your configuration
Logs
Enable verbose logging for troubleshooting:
./bin/server -t sse -c config.json -v
Contributing
We welcome contributions to the DB MCP Server project! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please see our CONTRIBUTING.md file for detailed guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Star History
Repository Owner
Organization
Repository Details
Programming Languages
Tags
Topics
Join Our Newsletter
Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.
Related MCPs
Discover similar Model Context Protocol servers
Multi-Database MCP Server (by Legion AI)
Unified multi-database access and AI interaction server with MCP integration.
Multi-Database MCP Server enables seamless access and querying of diverse databases via a unified API, with native support for the Model Context Protocol (MCP). It supports popular databases such as PostgreSQL, MySQL, SQL Server, and more, and is built for integration with AI assistants and agents. Leveraging the MCP Python SDK, it exposes databases as resources, tools, and prompts for intelligent, context-aware interactions, while delivering zero-configuration schema discovery and secure credential management.
- ⭐ 76
- MCP
- TheRaLabs/legion-mcp
MCP Toolbox for Databases
Open source MCP server for secure and efficient Gen AI database integrations.
MCP Toolbox for Databases is an open source server that implements the Model Context Protocol (MCP) for database interactions in Gen AI workflows. It manages core complexities such as connection pooling, authentication, and tool integration, enabling developers to create and deploy database tools with ease and enhanced security. The toolbox supports streamlined connections between development environments and databases, offering observability, context-aware code generation, and automation features. Its design emphasizes rapid integration, reusable tools, and compatibility with AI assistants.
- ⭐ 11,412
- MCP
- googleapis/genai-toolbox
MCP 数据库工具 (MCP Database Utilities)
A secure bridge enabling AI systems safe, read-only access to multiple databases via unified configuration.
MCP Database Utilities provides a secure, standardized service for AI systems to access and analyze databases like SQLite, MySQL, and PostgreSQL using a unified YAML-based configuration. It enforces strict read-only operations, local processing, and credential protection to ensure data privacy and integrity. The tool is suitable for entities focused on data privacy and minimizes risks by isolating database connections and masking sensitive data. Designed for easy integration, it supports multiple installation options and advanced capabilities such as schema analysis and table browsing.
- ⭐ 85
- MCP
- donghao1393/mcp-dbutils
PGMCP
Natural language PostgreSQL interface via the Model Context Protocol.
PGMCP enables seamless interaction with any PostgreSQL database through natural language queries, translating user intent into structured SQL results. It acts as a Model Context Protocol (MCP) server, connecting AI assistants and MCP-compatible clients to databases with features like streaming, robust error handling, and optional AI-powered SQL generation. The tool ensures secure, read-only access to existing databases using HTTP/MCP protocol. Compatibility includes tools such as Cursor, Claude Desktop, and VS Code extensions.
- ⭐ 499
- MCP
- subnetmarco/pgmcp
SkySQL MCP Server
Serverless MariaDB database management with AI-powered agents via Model Context Protocol.
SkySQL MCP Server implements the Model Context Protocol to provide a robust interface for launching and managing serverless MariaDB and MySQL database instances. It offers capabilities to interact with AI-powered agents for intelligent database operations, execute SQL queries, and manage credentials and security settings. Integration with tools like MCP CLI, Smithery.ai, and Cursor.sh is supported for interactive usage. Designed for efficiency and scalability, it enables streamlined database workflows with advanced AI assistance.
- ⭐ 2
- MCP
- skysqlinc/skysql-mcp
XiYan MCP Server
A server enabling natural language queries to SQL databases via the Model Context Protocol.
XiYan MCP Server is a Model Context Protocol (MCP) compliant server that allows users to query SQL databases such as MySQL and PostgreSQL using natural language. It leverages the XiYanSQL model, providing state-of-the-art text-to-SQL translation and supports both general LLMs and local deployment for enhanced security. The server lists available database tables as resources and can read table contents, making it simple to integrate with different applications.
- ⭐ 218
- MCP
- XGenerationLab/xiyan_mcp_server
Didn't find tool you were looking for?