Multi Database MCP Server

by freepeak

120 stars
722 downloads
Not rated
GitHub

About

Enables direct interaction with MySQL and PostgreSQL databases through a Go-based connectivity layer that supports both local stdio and production SSE transport modes for querying, analyzing, and manipulating structured data.

Details

Author
freepeak
Repository
FreePeak/db-mcp-server
GitHub stars
120
Downloads
722
License
MIT License
Categories
Database, Other, Productivity, Developer Tools, Design, AI, Search, Infrastructure, Frontend
Tags
#sql, #postgres, #mysql, #sqlite, #integration

- Simultaneous Multi-Database Support: Connect to multiple MySQL, PostgreSQL, SQLite, and Oracle databases concurrently
- Lazy Loading Mode: Defer connection establishment until first use - perfect for setups with 10+ databases (enable with --lazy-loading flag)
- 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
- Health Check: Automatic validation of database connectivity on startup
- Production Guardrails: Per-database read_only enforcement (blocks writes through both query_ and execute_ tools), max_rows result truncation with explicit notices, and per-query timeouts

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Multi Database MCP Server
    Command (node, npx, python, etc.) /path/to/db-mcp-server/server
    Arguments
    • Argument 1 -t
    • Argument 2 stdio
    • Argument 3 -c
    • Argument 4 /path/to/config.json

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

The DB MCP Server can be deployed in multiple ways to suit different environments and integration needs:


docker run -p 9092:9092 \
  -v $(pwd)/config.json:/app/my-config.json \
  -e TRANSPORT_MODE=sse \
  -e CONFIG_PATH=/app/my-config.json \
  -e DB_MCP_API_KEY=replace-me-with-a-long-random-string \
  freepeak/db-mcp-server

> Note: Mount to /app/my-config.json as the container has a default file at /app/config.json.

The SSE and streamable-HTTP transports accept an Authorization: Bearer <key>
header. Set DB_MCP_API_KEY (or pass -api-key) when launching the Docker
container; clients must then send the matching bearer token on every request:

curl -H "Authorization: Bearer replace-me-with-a-long-random-string" \
     http://localhost:9092/sse

When no API key is configured the transport remains open (single-user /
development use). The middleware lives in internal/delivery/mcp.APIKeyAuth
and is exported so you can compose it with your own reverse proxy if you
front the container with nginx, Caddy, or Traefik.

./bin/server -t sse -c config.json


Create a config.json file with your database connections:

json
{
"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,
"read_only": false,
"max_rows": 1000
},
{
"id": "postgres1",
"type": "postgres",
"host": "postgres1",
"port": 5432,
"name": "db1",
"user": "user1",
"password": "password1"
},
{
"id": "sqlite_app",
"type": "sqlite",
"database_path": "./data/app.db",
"journal_mode": "WAL",
"cache_size": 2000,
"read_only": false,
"use_modernc_driver": true,
"query_timeout": 30,
"max_open_conns": 1,
"max_idle_conns": 1
},
{
"id": "sqlite_encrypted",
"type": "sqlite",
"database_path": "./data/secure.db",
"encryption_key": "your-secret-key-here",
"journal_mode": "WAL",
"use_modernc_driver": false
},
{
"id": "sqlite_memory",
"type": "sqlite",
"database_path": ":memory:",
"cache_size": 1000,
"use_modernc_driver": true
}
]
}

./bin/server -t stdio -c <config-file> -log-dir /tmp/db-mcp-logs

./bin/server -t stdio -db-config '{"connections":[...]}'

export DB_CONFIG='{"connections":[...]}'
./bin/server -t stdio

Available Flags:
- -t, -transport: Transport mode (stdio or sse)
- -c, -config: Path to database configuration file
- -p, -port: Server port for SSE mode (default: 9092)
- -h, -host: Server host for SSE mode (default: localhost)
- -log-level: Log level (debug, info, warn, error)
- -log-dir: Directory for log files (default: ./logs in current directory)
- -db-config: Inline JSON database configuration

When using SQLite databases, you can leverage these additional configuration options:

When using Oracle databases, you can leverage these additional configuration options:

The project includes comprehensive unit and integration tests for all supported databases.

./oracle-test.sh start

./oracle-test.sh stop

./timescaledb-test.sh start

./timescaledb-test.sh stop
```

docker-compose -f docker-compose.test.yml up -d
./oracle-test.sh start

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_<db_id>

Get information about tables, columns, indexes, and foreign keys.

generate_schema_<db_id>

Generate SQL or code from database schema.

performance_<db_id>

Analyze query performance and get optimization suggestions.

explain_<db_id>

Show the execution plan for a SQL statement without running it.

describe_<db_id>

Inspect one table's columns, indexes, and row estimate via engine catalog queries.

health_<db_id>

Report connectivity, ping latency, connection-pool state, and engine stats.

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 each connected database, DB MCP Server automatically generates these specialized tools:

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "multi database mcp server": {
            "env": {},
            "args": [
                "-t",
                "stdio",
                "-c",
                "/path/to/config.json"
            ],
            "shell": false,
            "command": "/path/to/db-mcp-server/server"
        }
    }
}

Linux

{
    "env": [],
    "args": [
        "-t",
        "stdio",
        "-c",
        "/path/to/config.json"
    ],
    "shell": false,
    "command": "/path/to/db-mcp-server/server"
}

Macos

{
    "env": [],
    "args": [
        "-t",
        "stdio",
        "-c",
        "/path/to/config.json"
    ],
    "shell": false,
    "command": "/path/to/db-mcp-server/server"
}

Windows

{
    "env": [],
    "args": [
        "/c",
        "/path/to/db-mcp-server/server",
        "-t",
        "stdio",
        "-c",
        "/path/to/config.json"
    ],
    "shell": true,
    "command": "cmd"
}

Multi Database MCP Server

License: MIT
Go Report Card
Go Reference
Contributors

<h3>A powerful multi-database server implementing the Model Context Protocol (MCP) to provide AI assistants with structured access to databases.</h3>

<div class="toc">
<a href="#overview">Overview</a> •
<a href="#core-concepts">Core Concepts</a> •
<a href="#features">Features</a> •
<a href="#supported-databases">Supported Databases</a> •
<a href="#deployment-options">Deployment Options</a> •
<a href="#configuration">Configuration</a> •
<a href="#available-tools">Available Tools</a> •
<a href="#examples">Examples</a> •
<a href="#troubleshooting">Troubleshooting</a> •
<a href="#contributing">Contributing</a>
</div>

</div>

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"
    },
    {
      "id": "oracle1",
      "type": "oracle",
      "host": "localhost",
      "port": 1521,
      "service_name": "XEPDB1",
      "user": "user3",
      "password": "password3"
    }
  ]
}

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:

1. Domain Layer: Core business entities and interfaces
2. Repository Layer: Data access implementations
3. Use Case Layer: Application business logic
4. Delivery Layer: External interfaces (MCP tools)

Features

- Simultaneous Multi-Database Support: Connect to multiple MySQL, PostgreSQL, SQLite, and Oracle databases concurrently
- Lazy Loading Mode: Defer connection establishment until first use - perfect for setups with 10+ databases (enable with --lazy-loading flag)
- 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
- Health Check: Automatic validation of database connectivity on startup
- Production Guardrails: Per-database read_only enforcement (blocks writes through both query_ and execute_ tools), max_rows result truncation with explicit notices, and per-query timeouts

Production Guardrails

Protect agent sessions against runaway queries and accidental writes:

| Setting | Scope | Effect |
|---------|-------|--------|
| "read_only": true | per database | Blocks write statements (INSERT, UPDATE, DELETE, DDL, data-modifying CTEs, stacked writes) through both query and execute tools, and enforces rejection at the database engine itself on PostgreSQL/TimescaleDB (default_transaction_read_only=on) and MySQL (transaction_read_only=1); SQLite opens mode=ro. Classification strips comments and string literals and defaults to deny for unrecognized statements. |
| "max_rows": 1000 | per database | Truncates result sets at N rows and appends an explicit [Truncated] notice so the model knows to refine its query instead of losing context. 0 (default) means unlimited. |
| "query_timeout": 30 | per database | Cancels queries that exceed the timeout in seconds. |

> Defense in depth: read-only is enforced in three layers — application classifier, engine session defaults, and (recommended) least-privilege database users. Oracle currently relies on the classifier plus user privileges.

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 |
| SQLite | ✅ Full Support | File-based & In-memory databases, SQLCipher encryption support |
| Oracle | ✅ Full Support (10g-23c) | Queries, Transactions, Schema Analysis, RAC, Cloud Wallet, TNS |
| 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

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.