Provides read-only database connectivity for MySQL databases, enabling schema inspection, table exploration, parameterized query execution, and connection pooling.
Provides read-only database connectivity for PostgreSQL databases, enabling schema inspection, table exploration, parameterized query execution, and connection pooling.
Provides database connectivity for SQLite databases, enabling schema inspection, table exploration, parameterized query execution, and sample data retrieval.
Common Database MCP Server
A Model Context Protocol (MCP) server that provides database connectivity to Claude Code, Claude Desktop, and Windsurf IDE. Supports PostgreSQL, MySQL, SQLite, and DB2 iSeries databases through native Python drivers.
Features
✅ Multiple Database Support: PostgreSQL, MySQL, SQLite, DB2 iSeries
✅ Read-Only by Default: Safe database exploration without risk of data modification
✅ Connection Pooling: Efficient connection management for network databases
✅ SQL Injection Prevention: Parameterized queries and query validation
✅ Cross-Platform: Works on macOS, Linux, and Windows
✅ MCP Tools: Execute queries, inspect schemas, explore tables
✅ MCP Resources: Database schemas as resources
✅ MCP Prompts: Guided workflows for database exploration
Installation
Prerequisites
Python 3.9 or higher
pip
Install from Source
Install Optional Dependencies
For development and testing:
Database Driver Installation
The server automatically installs drivers for:
PostgreSQL (
psycopg2-binary)MySQL (
mysql-connector-python)SQLite (
sqlite3- built into Python)
For DB2 iSeries on macOS:
Note: ibm_db works on macOS (both Intel and Apple Silicon M1/M2/M3).
Configuration
Claude Code Configuration
Add the server to your ~/.claude/mcp.json or Claude Desktop configuration:
Environment Variables
Configure databases using environment variables with the format:
Or use connection strings:
Multiple Database Example
Configure multiple databases:
Usage
Available MCP Tools
list_databases()
List all configured database connections.
test_connection(database)
Test database connectivity.
list_schemas(database)
List all schemas/databases (PostgreSQL/MySQL only).
list_tables(database, schema=None)
List all tables in a database.
describe_table(database, table, schema=None)
Get detailed table schema.
execute_query(database, query, parameters=None, limit=100)
Execute a SELECT query with parameterized inputs.
get_sample_data(database, table, schema=None, limit=10)
Get sample rows from a table.
Available MCP Resources
db://{database}/schema
Get complete database schema as markdown.
db://{database}/tables/{table}/schema
Get specific table schema as markdown.
Available MCP Prompts
explore_database
Guided workflow for database exploration.
query_with_safety
Instructions for generating safe parameterized queries.
analyze_table_structure
Analyze table structure and identify relationships.
Security Best Practices
1. Use Read-Only Mode
Always use read-only mode (default) when exploring production databases:
2. Create Dedicated Database Users
Create database users with SELECT-only permissions:
PostgreSQL:
MySQL:
3. Use Environment Variables
Store credentials in environment variables, never in code:
4. Network Security
Use SSL/TLS for database connections
Restrict database access by IP address
Use SSH tunnels for remote databases
Troubleshooting
Connection Refused
PostgreSQL/MySQL:
Solutions:
Verify the database server is running
Check hostname and port are correct
Ensure firewall allows connections
Test with
psqlormysqlcommand-line tools
Authentication Failed
Solutions:
Verify credentials are correct
Check user has necessary permissions
For PostgreSQL, check
pg_hba.confallows connections
SQLite Database Locked
Solutions:
Close other applications using the database
Wait a moment and try again
Check file permissions
ibm_db Installation Issues (macOS)
If ibm_db fails to install:
Development
Running Tests
Running with Debug Logging
Project Structure
MVP Status
Currently Supported (v0.1.0)
✅ PostgreSQL
✅ MySQL
✅ SQLite
✅ DB2 iSeries
✅ Read-only queries
✅ Connection pooling
✅ Schema inspection
✅ Parameterized queries
✅ MCP tools, resources, and prompts
Coming Soon
🔜 Write operations (opt-in)
🔜 Transaction support
🔜 Query caching
🔜 Stored procedure execution
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Add tests for new functionality
Ensure all tests pass
Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues, questions, or contributions:
GitHub Issues: Create an issue
Documentation: This README
Acknowledgments
Built with FastMCP
Implements the Model Context Protocol
Database drivers: psycopg2, mysql-connector-python, ibm_db