Multi-database MCP server for PostgreSQL, MySQL, and ClickHouse
The io.github.yugui923/db-connect-mcp MCP server is a multi-database database connectivity service for PostgreSQL, MySQL, and ClickHouse. It provides access for MCP-based clients to work with these database engines via the serverβs defined tools.
π οΈ Key Features
Multi-database support for PostgreSQL, MySQL, and ClickHouse
GitHub project with CI, CodeQL, and code coverage badges
π Use Cases
Connecting an MCP client to one of the supported database systems
Integrating PostgreSQL, MySQL, or ClickHouse workflows into MCP-based applications
β‘ Developer Benefits
Centralizes connectivity for multiple database backends under a single MCP server
Repository includes quality tooling indicators (CI, CodeQL, code coverage)
β οΈ Limitations
Supported databases are limited to PostgreSQL, MySQL, and ClickHouse (as stated)
A read-only MCP (Model Context Protocol) server for exploratory data analysis across multiple database systems. This server provides safe, read-only access to PostgreSQL, MySQL, and ClickHouse databases with comprehensive analysis capabilities.
Restart Claude Desktop and start querying your database!
Note: Using python -m db_connect_mcp ensures the command works even if Python's Scripts directory isn't in your PATH. Existing mcpServers configurations remain valid: stdio is still the default. The optional remote Streamable HTTP mode serves both older initialize-based clients and 2026-07-28 session-free MCP clients at /mcp without changing the database or SSH configuration. Existing HTTP deployments must review forwarded Host/Origin values: the upgrade enables transport validation and may require MCP_ALLOWED_HOSTS / MCP_ALLOWED_ORIGINS.
Features
ποΈ Multi-Database Support
PostgreSQL - Full support with advanced metadata and statistics
MySQL - Complete support for MySQL and MariaDB databases
ClickHouse - Support for analytical workloads and columnar storage
π Database Exploration
List schemas - View all schemas in the database
List tables - See all tables with metadata (size, row counts, comments)
Describe tables - Get detailed column information, indexes, and constraints
View relationships - Understand foreign key relationships between tables
π Data Analysis
Column profiling - Statistical analysis of column data
Database-specific safety - Each adapter implements appropriate safety measures
π Observability
db-connect-mcp inherits the MCP SDK's built-in OpenTelemetry server
instrumentation. The API is a no-op until the launching process configures an
SDK and exporter. Review exporter sampling and redaction before production use,
because database identifiers and error details may be sensitive.
π‘ Best Practices
Tip: db-connect-mcp works best with databases that have proper comments on tables and columns. When your database includes descriptive comments, the MCP server can provide richer context to AI assistants, leading to better understanding of your data model and more accurate query suggestions.
Adding comments in PostgreSQL:
sql
COMMENT ONTABLE users IS'Registered user accounts with profile information';
COMMENT ONCOLUMN users.email IS'Primary email address, used for authentication';
COMMENT ONCOLUMN users.is_verified IS'Whether email has been verified via confirmation link';
Adding comments in MySQL:
sql
ALTER TABLE users COMMENT ='Registered user accounts with profile information';
ALTER TABLE users MODIFY COLUMN email VARCHAR(255) COMMENT 'Primary email address, used for authentication';
The server automatically retrieves and displays these comments when describing tables, helping AI assistants understand the purpose and semantics of your data.
π SSH Tunnel Support
Secure remote access - Connect to databases behind firewalls via SSH tunnels
Performance tuning: prepared_statement_cache_size, max_cached_statement_lifetime, etc.
MySQL/MariaDB:
code
# Simple URL (driver automatically added)
DATABASE_URL=mysql://root:password@localhost:3306/mydb
# MariaDB URLs (normalized to mysql+aiomysql)
DATABASE_URL=mariadb://user:pass@host:3306/db # MariaDB style
DATABASE_URL=maria://user:pass@host:3306/db # Short form
# JDBC URLs (automatically converted)
DATABASE_URL=jdbc:mysql://user:pass@host:3306/db # From Java apps
DATABASE_URL=jdbc:mariadb://user:pass@host:3306/db # JDBC MariaDB
# With explicit async driver
DATABASE_URL=mysql+aiomysql://user:pass@host:3306/db
# With charset (critical for proper Unicode support)
DATABASE_URL=mariadb://user:pass@remote.host:3306/db?charset=utf8mb4
Supported MySQL Parameters:
charset - Character encoding (e.g., utf8mb4) - critical for data integrity
use_unicode - Enable Unicode support
connect_timeout, read_timeout, write_timeout - Various timeouts
autocommit - Transaction autocommit mode
init_command - Initial SQL command to run
sql_mode - SQL mode settings
time_zone - Time zone setting
ClickHouse:
code
# Simple URL (driver automatically added)
DATABASE_URL=clickhouse://default:@localhost:9000/default
# Short forms (normalized to clickhouse+asynch)
DATABASE_URL=ch://user:pass@host:9000/db # Short form
DATABASE_URL=click://user:pass@host:9000/db # Alternative
# JDBC URLs (automatically converted)
DATABASE_URL=jdbc:clickhouse://user:pass@host:9000/db # From Java apps
DATABASE_URL=jdbc:ch://user:pass@host:9000/db # JDBC with short form
# With explicit async driver
DATABASE_URL=clickhouse+asynch://user:pass@host:9000/db
# With performance settings
DATABASE_URL=ch://user:pass@host:9000/db?timeout=60&max_threads=4
Supported ClickHouse Parameters:
database - Default database selection
timeout, connect_timeout, send_receive_timeout - Various timeouts
compress, compression - Enable compression
max_block_size, max_threads - Performance tuning
Note:
SSL parameters (ssl, sslmode) are automatically converted to the correct format for asyncpg
Certificate file parameters (sslcert, sslkey, sslrootcert) are filtered out as they can cause compatibility issues
Only parameters known to work with async drivers are preserved
Usage
Running the Server
bash
# Run the server (works everywhere, no PATH configuration needed)
python -m db_connect_mcp
# With environment variable
DATABASE_URL="postgresql://user:pass@host:5432/db" python -m db_connect_mcp
Note: Using python -m db_connect_mcp works regardless of whether Python's Scripts directory is in your PATH.
After creating .mcp.json, restart Claude Code and verify with /mcp. You should see db-connect-mcp listed with all available tools.
Tip: Instead of SSH_PRIVATE_KEY_PATH, you can use SSH_PRIVATE_KEY to pass the private key content directly as a string (raw PEM or base64-encoded PEM). This is useful in CI/CD or cloud environments where mounting key files is impractical.
See the SSH Tunnel Guide for full tunnel configuration reference.
Using with Claude Desktop
Add the server to your Claude Desktop configuration (claude_desktop_config.json):
The same database URL formats and SSH tunnel environment variables shown in the Claude Code examples above work identically with Claude Desktop.
For development: See Development Guide for running from source with uv.
Database Feature Support
Feature
PostgreSQL
MySQL
ClickHouse
Schemas
β Full
β Full
β Full
Tables
β Full
β Full
β Full
Views
β Full
β Full
β Full
Indexes
β Full
β Full
β οΈ Limited
Foreign Keys
β Full
β Full
β No
Constraints
β Full
β Full
β οΈ Limited
Table Size
β Exact
β Exact
β Exact
Row Count
β Exact
β Exact
β Exact
Column Stats
β Full
β Full
β Full
Sampling
β Full
β Full
β Full
MCP Resources
Modern MCP clients can discover database context as private, cache-aware JSON
resources in addition to calling tools:
db-connect://database β database identity, dialect, and capabilities
db-connect://schema/{schema} β schema counts and metadata
db-connect://table/{schema}/{table} β columns, indexes, constraints, and comments
The schema and table forms are also advertised as resource templates for direct
access when the identifier is already known.
Resource catalogs are URI-sorted and cursor-paginated in pages of 100. Cursors
are tied to a catalog snapshot; if schemas or tables change between pages, the
server asks the client to restart pagination instead of returning an
inconsistent traversal.
Available Tools
All tools publish JSON Schema input and output contracts, read-only behavior
annotations, and machine-readable structured results. The same result remains
available as JSON text for clients that do not yet consume MCP structured
content. Structured list results use an items envelope while their legacy
text form remains a JSON array.
get_database_info
Get database metadata, including the dialect, version, connection details,
read-only status, and capabilities.
list_schemas
List all schemas in the database.
list_tables
List all tables in a schema with metadata.
Parameters:
schema (optional): Schema name (default: "public")
describe_table
Get detailed information about a table.
Parameters:
table: Name of the table
schema (optional): Schema name (default: "public")
analyze_column
Analyze a column with statistics and distribution.
Parameters:
table: Name of the table
column: Name of the column
schema (optional): Schema name (default: "public")
sample_data
Get a sample of data from a table.
Parameters:
table: Name of the table
schema (optional): Schema name (default: "public")
limit (optional): Number of rows (default: 100, max: 1000)
execute_query
Execute a read-only SQL query.
Parameters:
query: SQL query (must be SELECT or WITH)
limit (optional): Maximum rows (default: 1000, max: 10000)
get_table_relationships
Get foreign key relationships for a table.
Parameters:
table: Name of the table
schema (optional): Schema name (default: "public")
explain_query
Get a database-specific query execution plan.
Parameters:
query: SQL query to explain
analyze (optional): Execute the query and include actual runtime statistics (default: false)
search_objects
Search schemas, tables, views, columns, and indexes with progressive detail.
Parameters:
pattern: SQL LIKE pattern, such as %user%
object_types (optional): Object types to include
detail_level (optional): names, summary, or full (default: summary)
schema (optional): Restrict the search to a schema
table (optional): Restrict column and index searches to a table
limit (optional): Maximum matches (default: 100, max: 1000)
Example Usage
Once configured, you can use the server with any compatible MCP client:
code
"Can you analyze my database and tell me about the table structure?"
"Show me the relationships between tables in the public schema"
"What's the distribution of values in the users.created_at column?"
"Give me a sample of data from the orders table"
"Run this query: SELECT COUNT(*) FROM users WHERE created_at > '2024-01-01'"
Database-Specific Examples
Working with PostgreSQL:
code
"List all schemas except system ones"
"Show me the foreign key relationships in the sales schema"
"Analyze the performance of indexes on the products table"
Working with MySQL:
code
"What storage engines are being used in my database?"
"Show me all tables in the information_schema"
"Analyze the customer_orders table structure"
Working with ClickHouse:
code
"Show me the partitions for the events table"
"What's the compression ratio for the analytics.clicks table?"
"Sample 1000 rows from the metrics table"
Safety and Security
Read-only by design: The server enforces read-only access at multiple levels:
Connection string parameters
Session-level settings
Query validation
No data modification: INSERT, UPDATE, DELETE, CREATE, DROP, and other modification statements are blocked
Query limits: All queries are automatically limited to prevent excessive resource usage
No sensitive operations: No access to system catalogs or administrative functions
Development
For detailed development setup, testing, and contribution guidelines, see the Development Guide.
The server uses an adapter pattern to support multiple database systems:
Adapters: Each database type has its own adapter that implements database-specific functionality
Core: Shared functionality for connection management, query execution, and metadata inspection
Models: Pydantic models for type safety and validation
Server: MCP server implementation that routes requests to appropriate components
Running Tests
bash
# Start local test database (PostgreSQL 17 with sample data)cd tests/docker && docker-compose up -d && cd ../..
# Run all tests in parallel (preferred - 6 workers)
uv run pytest -n 6
# Run specific test modules
uv run pytest tests/module/test_inspector.py -v -n 6
uv run pytest tests/integration/ -v -n 6
# Stop test databasecd tests/docker && docker-compose down && cd ../..
# Reset database (clean slate with fresh data)cd tests/docker && docker-compose down -v && docker-compose up -d && cd ../..
Local Test Database:
PostgreSQL 17 with 50K+ rows of sample data across 7 tables