The DB MCP Server is a powerful tool that allows AI assistants to interact with multiple databases simultaneously through a standardized Model Context Protocol (MCP). It provides a unified interface for executing SQL queries, managing transactions, exploring schemas, and analyzing performance across different database systems.
# 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
# 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"]
}
}
}
# 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
# 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
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"
}
]
}
# 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
For each database connection, the server generates specialized tools automatically:
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 |
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 |
Tool Name | Description |
---|---|
performance_<db_id> |
Analyze query performance and get optimization suggestions |
Additional tools are available for PostgreSQL databases with TimescaleDB extension:
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 |
-- 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")
-- 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")
-- 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")
query_timeout
setting in your configurationEnable verbose logging for troubleshooting:
./bin/server -t sse -c config.json -v
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.