mcp-db-explorer
Allows exploring and querying PostgreSQL databases, including table structure inspection, statistical profiling, entity-relationship diagrams, and safe query execution.
Allows exploring and querying SQLite databases, including table structure inspection, statistical profiling, entity-relationship diagrams, and safe query execution.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-db-explorer List all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Model Context Protocol Database Explorer
A Model Context Protocol (MCP) server that exposes tools for exploring and querying SQLite and PostgreSQL databases. It allows Large Language Models (LLMs) to inspect table structures, perform statistical profiling, generate entity-relationship diagrams, and execute queries safely.
Overview
The Database Explorer MCP Server provides a bridge between LLMs and SQL databases. It features read-only constraints by default, AST-based query safety verification, automatic schema visualization, and execution plan inspection tools.
Related MCP server: PostgreSQL Advanced MCP Server
Architecture
The diagram below outlines the flow of a client request to the database via the MCP server:
graph TD
Client[MCP Client] -->|JSON-RPC| Server[MCP Database Explorer Server]
Server -->|Parse & Safety Check| Safety[Safety Validator]
Safety -->|AST Verification| Allowed{Safe?}
Allowed -->|Yes| Database[(Database: SQLite / PostgreSQL)]
Allowed -->|No| Block[Block Query & Return Error]
Database -->|Query Results| Server
Server -->|Response| ClientProject Structure
mcp-db-explorer/
├── .github/
│ └── workflows/
│ └── ci.yml # GitHub Actions CI workflow
├── mcp_db_explorer/
│ ├── __init__.py
│ ├── database.py # Database connection and querying logic
│ ├── prompts.py # Prompt templates (e.g. NL-to-SQL)
│ ├── safety.py # AST-based SQL safety validation
│ └── server.py # MCP Server definition and CLI entrypoint
├── tests/
│ ├── test_database.py # Tests for database connections and queries
│ ├── test_safety.py # Tests for AST query validation
│ └── test_server.py # Tests for MCP server tool schemas
├── pyproject.toml # Project dependency configuration
└── README.md # Project documentationSetup and Installation
Prerequisites
Ensure you have Python 3.10 or later installed on your system.
1. Clone the Repository
git clone https://github.com/arman1o1/mcp-db-explorer
cd mcp-db-explorer2. Setup and Install Dependencies
Option A: Using uv (Recommended)
This project is configured with uv. To install dependencies and set up the virtual environment, run:
uv syncOption B: Using pip and venv
You can set up a virtual environment and install dependencies manually:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e .Running the Application
Running with uv
To run the MCP server, use the uv run command:
uv run mcp-db-explorer --db-type sqlite --connection-string my_database.dbConfiguration Options
The server accepts several options via command-line arguments or environment variables:
Argument | Environment Variable | Description |
|
| Default database engine type ( |
|
| Database connection string (path for SQLite, URI for PostgreSQL) |
|
| Enable write operations (DML/DDL queries). Disabled by default. |
|
| Restricts SQLite database paths to be inside this directory. |
Client Integration
To use this server with an MCP client (such as Claude Desktop), add the server configuration to your client configuration file.
Claude Desktop Configuration
Open your claude_desktop_config.json:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Add the following configuration (use absolute paths):
{
"mcpServers": {
"mcp-db-explorer": {
"command": "uv",
"args": [
"--directory",
"C:\\absolute\\path\\to\\mcp-db-explorer",
"run",
"mcp-db-explorer",
"--db-type",
"sqlite",
"--connection-string",
"C:\\absolute\\path\\to\\my_database.db"
]
}
}
}Replace the paths with the correct ones for your local setup.
Testing
To run the test suite, run:
uv run pytestLicense
This project is licensed under the MIT License - see the LICENSE file for details.
Available Tools
7 toolsconnect_databaseA
Connect to a SQLite or PostgreSQL database. For SQLite, connection_string can be a file path (e.g. 'dev.db') or ':memory:'. For Postgres, connection_string must be a valid PostgreSQL connection URI. Resolves relative paths for SQLite databases against the current working directory.
Inputs: db_type (required), connection_string (required).
describe_tableA
Retrieve table columns, data types, primary key status, foreign keys, indexes, and a sample of 5 rows.
Inputs: table_name (required).
explain_query_planB
Run EXPLAIN on a SQL query to inspect the database execution path.
Inputs: sql (required).
generate_erdB
Generate a Mermaid.js Entity Relationship Diagram (ERD) based on tables and foreign keys.
Inputs: no named parameters.
get_table_statsA
Profile a table to compute row count, null rates, cardinality, and numeric ranges (min/max/average).
Inputs: table_name (required).
list_tablesA
List all table names and their descriptions in the connected database.
Inputs: no named parameters.
run_queryA
Execute a SQL query against the database. Checked for safety. Read-only SELECT by default.
Inputs: sql (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose: connection, schema description, query planning, ERD generation, statistics, table listing, and query execution. There is no overlap between them.
All tools follow a consistent verb_noun pattern in snake_case (e.g., connect_database, list_tables, run_query). No deviations or mixed conventions.
Seven tools is well-scoped for a database explorer. Each tool covers a necessary operation without being too few or too many.
The tool set covers the full lifecycle of database exploration: connection, listing tables, describing schemas, profiling stats, generating ERDs, explaining query plans, and executing queries. No obvious gaps.
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceA Model Context Protocol server that provides tools for interacting with databases, including PostgreSQL, DuckDB, and Google Cloud Storage Parquet files.2-
- AlicenseNot gradedqualityDmaintenanceAn enhanced Model Context Protocol server that enables LLMs to inspect database schemas with rich metadata and execute read-only SQL queries with safety checks.195 npm25MIT
- AlicenseNot gradedqualityDmaintenanceA flexible Model Context Protocol server that enables LLMs to interact with database systems, supporting dynamic schema discovery and query execution across PostgreSQL and SQLite backends.2MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to interact with PostgreSQL databases by executing SQL queries and inspecting database schemas. It provides tools for standardized database exploration and management through the Model Context Protocol.-