db
MCP server from zerogon1203/db-mcp-server
claude mcp add --transport stdio zerogon1203-db-mcp-server /path/to/venv/bin/python /path/to/db-mcp-server/main.py \ --env DB_HOST="localhost" \ --env DB_NAME="your_db_name" \ --env DB_TYPE="postgresql"
How to use
This MCP Database Server provides a security-enhanced analytics and visualization layer for MySQL/MariaDB and PostgreSQL databases, with basic support for SQLite planned. It enforces read-only operation, prevents SQL injection, validates identifiers, and requires parameter binding for safe query execution. Tools are organized into schema utilities, analysis utilities, and visualization utilities, enabling you to inspect schemas, stats, sample data, and query plans, as well as generate visual diagrams and reports. Use the Cursor IDE integration or the MCP transport mechanisms to connect your client or editor to the server and run the available commands to explore and analyze your databases.
Key capabilities include: get_schema, get_table_stats, get_sample_data, get_column_stats for schema and data insights; execute_query, explain_query, optimize_query, get_db_status, get_table_size, get_index_usage, analyze_performance, suggest_indexes, and optimize_tables for in-depth analysis and optimization suggestions; and generate_schema_mermaid, generate_tables_summary, and generate_performance_report for visualization and reporting. These tools help you understand database structure, assess performance bottlenecks, and produce documentation-like outputs (ERDs, markdown tables, ASCII charts) that you can share with your team.
How to install
Prerequisites:
- Python 3.8+ installed on your system
- Git installed
- Access to a PostgreSQL/MySQL/MariaDB server for testing
Installation steps:
-
Clone the repository git clone <this-repo-url> cd db-mcp-server
-
Create and activate a virtual environment python -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install dependencies pip install -r requirements.txt
-
Configure environment variables
- Create a .env file or use an env var setup to provide DB connection details as described in README (DB_TYPE, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, etc.).
-
Run the server (example) python main.py
-
Connect via MCP client using the provided mcp_config example (adjust paths and env values to your setup).
Additional notes
Tips and considerations:
- Ensure the read-only and security-related settings are applied in production to prevent unauthorized data modification.
- Use a dedicated read-only database user for the MCP server (as shown in the README examples).
- If using Cursor IDE, configure the MCP server entry with transport=stdio and provide the path to your Python executable and main.py. Ensure the environment variables (DB_TYPE, DB_NAME, DB_HOST, etc.) are correctly set for your target database.
- Keep your dependencies up to date and monitor for SQL injection prevention updates in the tooling.
- For SQLite, expect basic support and consider migrating to MySQL/PostgreSQL for full feature sets.
Related MCP Servers
mcp-vegalite
MCP server from isaacwasserman/mcp-vegalite-server
github-chat
A Model Context Protocol (MCP) for analyzing and querying GitHub repositories using the GitHub Chat API.
nautex
MCP server for guiding Coding Agents via end-to-end requirements to implementation plan pipeline
pagerduty
PagerDuty's official local MCP (Model Context Protocol) server which provides tools to interact with your PagerDuty account directly from your MCP-enabled client.
futu-stock
mcp server for futuniuniu stock
mcp -boilerplate
Boilerplate using one of the 'better' ways to build MCP Servers. Written using FastMCP