DB Connect MCP
Multi-database MCP server for PostgreSQL, MySQL, and ClickHouse
★ 1MITdatabases
Install
Config snippet generator goes here (5 client tabs)
README
# db-connect-mcp - Multi-Database MCP Server
<!-- mcp-name: io.github.yugui923/db-connect-mcp -->
[](https://github.com/yugui923/db-connect-mcp/actions/workflows/ci.yml)
[](https://github.com/yugui923/db-connect-mcp/actions/workflows/codeql.yml)
[](https://codecov.io/gh/yugui923/db-connect-mcp)
[](https://scorecard.dev/viewer/?uri=github.com/yugui923/db-connect-mcp)
[](https://opensource.org/licenses/MIT)
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.
## Demo

## Quick Start
1. **Install:**
```bash
pip install db-connect-mcp
```
2. **Add to Claude Desktop** `claude_desktop_config.json`:
```json
{
"mcpServers": {
"db-connect": {
"command": "python",
"args": ["-m", "db_connect_mcp"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
```
3. **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.
## 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
- Basic statistics (count, unique values, nulls)
- Numeric statistics (mean, median, std dev, quartiles)
- Value frequency distribution
- Cardinality analysis
- **Data sampling** - Preview table data with configurable limits
- **Custom queries** - Execute read-only SQL queries safely
- **Database profiling** - Get high-level database metrics and largest tables
### 🔒 Safety Features
- **Read-only enforcement** - All connections are read-only at multiple levels
- **Query validation** - Only SELECT and WITH queries are allowed
- **Automatic limits** - Queries are automatically limited to prevent large result sets
- **Connection string safety** - Automatically adds read-only parameters
- **Database-specific safety** - Each adapter implements appropriate safety measures
### 💡 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 ON TABLE users IS 'Registered user accounts with profile information';
COMMENT ON COLUMN users.email IS 'Primary email address, used for authentication';
COMMENT ON COLUMN 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
- **Automatic tunnel management** - Tunnel lifecycle handled transparently (start, health check, restart, cleanup)
- **Flexible authentication** - Password or private key based SSH authentication
- **Any database type** - Works with PostgreSQL, MySQL, and ClickHouse through the same tunnel
See the [SSH Tunnel Guide](docs/guides/SSH_TUNNEL.md) for configuration details.
## Installation
### Prerequisites
- **Python 3.10 or higher**
- **A database**: PostgreSQL (9.6+), MySQL/MariaDB (5.7+/10.2+), or ClickHouse
### Install via pip
```bash
pip install db-connect-mcp
```
That's it! The package is now ready to use.
> **For developers**: See [Development Guide](docs/guides/DEVELOPMENT.md) fo