What is DB MCP Server?
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"
}
]
}
For each connected database, the server automatically generates a set of 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 and interact with 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
- Dynamic Database Tools:
- Execute SQL queries with parameters
- Run data modification statements with proper error handling
- Manage database transactions across sessions
- Explore database schemas and relationships
- Analyze query performance and receive optimization suggestions
- Unified Interface: Consistent interaction patterns across different database types
- Connection Management: Simple configuration for multiple database connections
Currently Supported Databases
| Database |
Status |
Features |
| MySQL |
✅ Full Support |
Queries, Transactions, Schema Analysis, Performance Insights |
| PostgreSQL |
✅ Full Support |
Queries, Transactions, Schema Analysis, Performance Insights |
Quick Start
Using Docker
The quickest way to get started is with Docker:
# Pull the latest image
docker pull freepeak/db-mcp-server:latest
# Run with your config mounted
docker run -p 9092:9092 -v $(pwd)/config.json:/app/config.json freepeak/db-mcp-server -t sse -c /app/config.json
From Source
# 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 in SSE mode
./server -t sse -c config.json
Running the Server
The server supports multiple transport modes to fit different use cases:
STDIO Mode (for IDE integration)
Ideal for integration with AI coding assistants:
# Run the server in STDIO mode
./server -t stdio -c config.json
Output will be sent as JSON-RPC messages to stdout, while logs go to stderr.
For Cursor integration, add this to your .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)
For web-based applications and services:
# Run with default host (localhost) and port (9092)
./server -t sse -c config.json
# Specify a custom host and port
./server -t sse -host 0.0.0.0 -port 8080 -c config.json
Connect your client to http://localhost:9092/sse for the event stream.
Docker Compose
For development environments with database containers:
# docker-compose.yml
version: '3'
services:
db-mcp-server:
image: freepeak/db-mcp-server:latest
ports:
- "9092:9092"
volumes:
- ./config.json:/app/config.json
command: ["-t", "sse", "-c", "/app/config.json"]
depends_on:
- mysql
- postgres
mysql:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: testdb
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- "3306:3306"
postgres:
image: postgres:14
environment:
POSTGRES_DB: testdb
POSTGRES_USER: user
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
Configuration
Database Configuration
Create a config.json file with your database connections:
{
"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"
}
]
}
Command-Line Options
The server supports various command-line options:
# Basic options
./server -t <transport> -c <config-file>
# Available transports: stdio, sse
# For SSE transport, additional options:
./server -t sse -host <hostname> -port <port> -c <config-file>
# Direct database configuration:
./server -t stdio -db-config '{"connections":[...]}'
# Environment variable configuration:
export DB_CONFIG='{"connections":[...]}'
./server -t stdio
For each connected database (e.g., "mysql1", "mysql2"), the server creates:
The server automatically generates tools with names following this format:
<tool_type>_<database_id>
Where:
<tool_type>: One of: query, execute, transaction, schema, performance
<database_id>: The ID of the database as defined in your configuration
Example tool names for a database with ID "mysql1":
query_mysql1
execute_mysql1
transaction_mysql1
schema_mysql1
performance_mysql1
-
query_<dbid>: Execute SQL queries on the specified database
{
"query": "SELECT * FROM users WHERE age > ?",
"params": [30]
}
-
execute_<dbid>: Execute SQL statements (INSERT, UPDATE, DELETE)
{
"statement": "INSERT INTO users (name, email) VALUES (?, ?)",
"params": ["John Doe", "john@example.com"]
}
-
transaction_<dbid>: Manage database transactions
// Begin transaction
{
"action": "begin",
"readOnly": false
}
// Execute within transaction
{
"action": "execute",
"transactionId": "<from begin response>",
"statement": "UPDATE users SET active = ? WHERE id = ?",
"params": [true, 42]
}
// Commit transaction
{
"action": "commit",
"transactionId": "<from begin response>"
}
-
schema_<dbid>: Get database schema information
{
"random_string": "dummy"
}
-
performance_<dbid>: Analyze query performance
{
"action": "analyzeQuery",
"query": "SELECT * FROM users WHERE name LIKE ?"
}
list_databases: List all configured database connections
{}
Examples
Querying Multiple Databases
// Query the first database
{
"name": "query_mysql1",
"parameters": {
"query": "SELECT * FROM users LIMIT 5"
}
}
// Query the second database
{
"name": "query_mysql2",
"parameters": {
"query": "SELECT * FROM products LIMIT 5"
}
}
Executing Transactions
// Begin transaction
{
"name": "transaction_mysql1",
"parameters": {
"action": "begin"
}
}
// Response contains transactionId
// Execute within transaction
{
"name": "transaction_mysql1",
"parameters": {
"action": "execute",
"transactionId": "tx_12345",
"statement": "INSERT INTO orders (user_id, product_id) VALUES (?, ?)",
"params": [1, 2]
}
}
// Commit transaction
{
"name": "transaction_mysql1",
"parameters": {
"action": "commit",
"transactionId": "tx_12345"
}
}
Roadmap
We're committed to expanding DB MCP Server to support a wide range of database systems:
Q3 2025
- MongoDB - Support for document-oriented database operations
- SQLite - Lightweight embedded database integration
- MariaDB - Complete feature parity with MySQL implementation
Q4 2025
- Microsoft SQL Server - Enterprise database support with T-SQL capabilities
- Oracle Database - Enterprise-grade integration
- Redis - Key-value store operations
2026
- Cassandra - Distributed NoSQL database support
- Elasticsearch - Specialized search and analytics capabilities
- CockroachDB - Distributed SQL database for global-scale applications
- DynamoDB - AWS-native NoSQL database integration
- Neo4j - Graph database support
- ClickHouse - Analytics database support
Troubleshooting
Common Issues
- Connection Errors: Verify your database connection settings in
config.json
- Tool Not Found: Ensure the server is running and check tool name prefixes
- Failed Queries: Check your SQL syntax and database permissions
Logs
The server writes logs to:
- STDIO mode: stderr
- SSE mode: stdout and
./logs/db-mcp-server.log
Enable debug logging with the -debug flag:
./server -t sse -debug -c config.json
Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b new-feature
- Commit your changes:
git commit -am 'Add new feature'
- Push to the branch:
git push origin new-feature
- Submit a pull request
Please ensure your code follows our coding standards and includes appropriate tests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Cursor Integration
The MCP server registers tools with names that match the format Cursor expects. The tool names follow this format:
mcp_<servername>_<tooltype>_<dbID>
For example: mcp_mysql1_db_mcp_server_stdio_schema_mysql1_db
The server uses the name mysql1_db_mcp_server_stdio by default, which should match your Cursor configuration in the mcp.json file.
Cursor Configuration
In your Cursor configuration (~/.cursor/mcp.json), you should have a configuration like:
{
"mcpServers": {
"multidb": {
"command": "/path/to/db-mcp-server/server",
"args": [
"-t",
"stdio",
"-c",
"/path/to/database_config.json"
]
}
}
}
The server will automatically register tools with simple names that match the database identifiers in your configuration.
Once your DB MCP Server is running and properly configured in Cursor, you can use the MCP tools in your AI assistant conversations. The tools follow this naming pattern:
mcp_<server_name>_<tool_type>_<database_id>
Where:
<server_name> is the name defined in your .cursor/mcp.json (e.g., "multidb")
<tool_type> is one of: query, execute, transaction, schema, performance, list_databases
<database_id> is the database ID from your configuration (not needed for list_databases)
Examples:
For a server named "multidb" with a database ID "mysql1":
- Listing all databases:
mcp_multidb_list_databases
- Querying the database:
mcp_multidb_query_mysql1
Query: SELECT * FROM users LIMIT 10
- Viewing database schema:
mcp_multidb_schema_mysql1
- Executing statements:
mcp_multidb_execute_mysql1
Statement: INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com')
- Managing transactions:
mcp_multidb_transaction_mysql1
Action: begin
If the AI assistant can't call the MCP tools:
- Make sure the server is running (check with
ps aux | grep server)
- Verify your .cursor/mcp.json configuration is correct
- Ensure the server_name in .env matches what's in your MCP tool calls
- Restart Cursor after making configuration changes
- Check the logs in the logs/ directory for any errors