database-explorer-mcp
Generates Mermaid ER diagrams from database schemas.
Allows AI assistants to explore schemas, run queries, and manage MongoDB databases.
Allows AI assistants to explore schemas, run queries, and manage MySQL databases.
Allows AI assistants to explore schemas, run queries, and manage PostgreSQL databases.
Allows AI assistants to explore schemas, run queries, and manage SQLite databases.
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., "@database-explorer-mcp 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.
ποΈ Database Explorer MCP Server
Let AI assistants talk to your databases.
Connect Claude, Cursor, VS Code Copilot, Windsurf β or any MCP-compatible AI β to PostgreSQL, MySQL, SQLite, and MongoDB using natural language.
Features Β· Quick Start Β· Setup Guides Β· Tools Reference Β· Prompts Β· Configuration Β· Contributing
π€ What is this?
This is a Model Context Protocol (MCP) server β a bridge that lets AI assistants interact with your databases directly.
Think of it like this: Instead of you manually writing SQL queries and copy-pasting results to ChatGPT, this server lets the AI connect to your database, explore the schema, run queries, and analyze data β all through natural conversation.
How it works
ββββββββββββββββββββ βββββββββββββββββββββββββββ ββββββββββββββββ
β AI Assistant β MCP β Database Explorer β SQL β Database β
β ββββββββββΊβ MCP Server ββββββββββΊβ β
β Claude Desktop β JSON β β β PostgreSQL β
β Cursor β over β β’ Explores schemas β β MySQL β
β VS Code Copilot β stdio β β’ Runs queries β β SQLite β
β Windsurf β β β’ Generates ERDs β β MongoDB β
β Any MCP client β β β’ Suggests indexes β β β
ββββββββββββββββββββ βββββββββββββββββββββββββββ ββββββββββββββββWho is this for?
Developers who want to query databases using natural language through their AI coding assistant
Data analysts who want AI help exploring and understanding databases
Teams who want to let AI tools safely access their databases (with read-only mode)
Anyone using an MCP-compatible AI tool who works with databases
β οΈ Important: This is NOT a standalone tool
This server requires an MCP-compatible AI client to use. It does NOT have its own UI.
The AI client sends commands to this server, and the server talks to your database. See Setup Guides below.
Related MCP server: GraphJin
β¨ Features
Feature | Description |
π 4 Database Engines | PostgreSQL, MySQL, SQLite, MongoDB |
π Schema Explorer | List tables, describe columns, view indexes, full schema dump |
β‘ Query Execution | Run SQL or MongoDB queries with auto-LIMIT safety |
π SQL Safety | Destructive queries (DROP, INSERT, etc.) blocked by default |
π Table Statistics | Row counts, sizes, index info |
π Query Plans | EXPLAIN queries to debug performance |
π‘ Index Suggestions | Smart recommendations for missing indexes |
π€ Data Export | Export results as CSV or JSON |
πΊοΈ ERD Generator | Generate Mermaid ER diagrams from your schema |
π Data Search | Full-text search across all tables and columns |
π§ 4 AI Prompts | Pre-built templates for common database tasks |
π Multi-Connection | Connect to multiple databases simultaneously |
π Quick Start
1. Clone and build
git clone https://github.com/nandanosql/database-explorer-mcp.git
cd database-explorer-mcp
npm install
npm run build2. Add to your AI tool
Choose your AI tool below and add the configuration:
3. Start using it!
Just talk to your AI naturally:
"Connect to my SQLite database at ~/data/app.db"
"What tables are in this database?"
"Show me the first 10 users ordered by signup date"
"Generate an ER diagram of the schema"
"Any missing indexes I should add?"
π§ Setup with Your AI Tool
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %AppData%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"database-explorer": {
"command": "node",
"args": ["/FULL/PATH/TO/database-explorer-mcp/build/index.js"],
"env": {
"DB_EXPLORER_READONLY": "true"
}
}
}
}Restart Claude Desktop. You'll see the π¨ tools icon showing 13 available tools.
Create .cursor/mcp.json in your project root:
{
"mcpServers": {
"database-explorer": {
"command": "node",
"args": ["/FULL/PATH/TO/database-explorer-mcp/build/index.js"]
}
}
}Restart Cursor. The tools will be available in Composer and Chat.
Create .vscode/mcp.json in your project:
{
"servers": {
"database-explorer": {
"command": "node",
"args": ["/FULL/PATH/TO/database-explorer-mcp/build/index.js"]
}
}
}Enable MCP in VS Code settings, then use Copilot Chat with @mcp to access tools.
Add to your Windsurf MCP configuration:
{
"mcpServers": {
"database-explorer": {
"command": "node",
"args": ["/FULL/PATH/TO/database-explorer-mcp/build/index.js"]
}
}
}This server communicates over stdio using the standard MCP protocol. Any client that supports MCP over stdio can connect:
# The server reads from stdin and writes to stdout
node /path/to/database-explorer-mcp/build/index.jsOr use the MCP Inspector for testing:
npx @modelcontextprotocol/inspector node build/index.jsπ οΈ Tools (13 total)
Connection Management
Tool | Description |
| Connect to PostgreSQL, MySQL, SQLite, or MongoDB |
| Disconnect from a database |
| List all active connections |
Schema Exploration
Tool | Description |
| List all tables/views/collections with row counts |
| Get columns, types, constraints, indexes for a table |
| Full database schema as structured JSON |
| π Generate Mermaid ER diagram from schema |
Querying & Analysis
Tool | Description |
| Execute SQL or MongoDB queries (read-only by default) |
| Get query execution plan |
| π Full-text search across all tables and text columns |
Optimization & Export
Tool | Description |
| Row counts, sizes, index statistics |
| Smart index optimization recommendations |
| Export query results as CSV or JSON |
π§ Built-in Prompts
These prompts appear as suggested starting points in compatible AI clients:
Prompt | What it does |
| Automatically explores and explains the entire database structure |
| Analyzes tables for performance issues and suggests fixes |
| Helps you write a query for a specific task |
| Creates a comprehensive data report on a topic |
π Usage Examples
Connect to a Database
You: Connect to my PostgreSQL database at localhost, database 'myapp', user 'admin', password 'secret'
AI: β
Connected to postgresql database "myapp" with alias "default"Explore Schema
You: What tables are in this database?
AI: Database: myapp (postgresql)
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β’ users [table] β 12,450 rows β 4.2 MB
β’ orders [table] β 89,120 rows β 28.7 MB
β’ products [table] β 2,340 rows β 1.1 MB
...Query Data
You: Show me the top 5 customers by total order value
AI: [runs the query automatically]
customer_name β total_orders β total_value
βββββββββββββββΌβββββββββββββββΌββββββββββββ
Alice Johnson β 47 β $12,450.00
Bob Smith β 38 β $9,870.50
...Generate ERD
You: Generate an ER diagram of the database
AI: [returns Mermaid diagram]erDiagram
users {
int id PK
varchar username "NOT NULL"
varchar email "NOT NULL"
}
orders {
int id PK
int user_id FK
decimal total_amount "NOT NULL"
}
users ||--o{ orders : "user_id"Search Data
You: Find any mentions of "alice" across all tables
AI: π Search results for "alice":
ββββββββββββββββββββββββββββββββββββββββββββββββββ
π users.username β 1 match(es)
β id: 1 | username: alice | email: alice@example.com
π users.email β 1 match(es)
β id: 1 | username: alice | email: alice@example.comSQLite (File-based, no server needed)
You: Connect to the SQLite database at /path/to/mydb.sqliteMongoDB
You: Connect to MongoDB at localhost, database 'myapp'
You: Find all users older than 25βοΈ Configuration
Configure via environment variables in your MCP client config:
Variable | Default | Description |
|
| Block destructive queries by default |
|
| Default row limit for queries |
|
| Maximum allowed row limit |
|
| Query timeout in milliseconds |
Example with Claude Desktop:
{
"mcpServers": {
"database-explorer": {
"command": "node",
"args": ["/path/to/build/index.js"],
"env": {
"DB_EXPLORER_READONLY": "true",
"DB_EXPLORER_MAX_ROWS": "200"
}
}
}
}π Security
Read-only by default β DROP, TRUNCATE, ALTER, INSERT, UPDATE, DELETE are blocked unless
readonly: falseis explicitly passedAuto-LIMIT β SELECT queries automatically get a LIMIT clause (default 100, max 1000)
Query timeout β 30-second timeout prevents runaway queries
No credentials stored β Connection details are in-memory only, never written to disk
Local only β Uses stdio transport, no network exposure
ποΈ Project Structure
src/
βββ index.ts # Entry point (stdio transport + env config)
βββ server.ts # MCP server setup, tool/prompt/resource registration
βββ types.ts # Shared TypeScript interfaces + SQL safety patterns
βββ connection-manager.ts # Connection lifecycle management
βββ connectors/
β βββ base.ts # Abstract connector interface
β βββ postgresql.ts # PostgreSQL (pg driver)
β βββ mysql.ts # MySQL (mysql2 driver)
β βββ sqlite.ts # SQLite (better-sqlite3)
β βββ mongodb.ts # MongoDB (mongodb driver)
βββ tools/
βββ connect.ts # connect/disconnect/list
βββ schema.ts # list_tables/describe_table/get_schema
βββ query.ts # run_query/explain_query + SQL safety
βββ stats.ts # get_table_stats
βββ optimize.ts # suggest_indexes
βββ export.ts # export_data
βββ erd.ts # generate_erd (Mermaid)
βββ search.ts # search_dataπ§ͺ Testing
Integration tests use SQLite (no external database needed):
npm testβ connects to SQLite database
β lists all tables
β describes table with columns and types
β describes table with foreign keys
β gets indexes for a table
β gets full database schema
β runs SELECT query
β runs JOIN query
β runs aggregate query
β runs INSERT query (write mode)
β explains query plan
β gets table stats for all tables
β gets table stats for specific table
β blocks DROP statements
β blocks TRUNCATE statements
β blocks ALTER statements
β blocks INSERT statements
β allows SELECT statements
β allows EXPLAIN statements
β connects via connection manager
β lists connections
β throws on missing connection
β stores server config
23 pass / 0 failπ€ Contributing
Contributions are welcome! Here's how:
Fork this repository
Create a feature branch:
git checkout -b feature/amazing-featureCommit your changes:
git commit -m 'Add amazing feature'Push to the branch:
git push origin feature/amazing-featureOpen a Pull Request
Ideas for contributions
Add support for more databases (Redis, DynamoDB, ClickHouse)
Add query history tracking
Add schema diff between connections
Improve MongoDB aggregation pipeline support
Add data visualization tools
π License
MIT β see LICENSE for details.
Built with β€οΈ for the AI-assisted development community
If this project helps you, give it a β on GitHub!
Available Tools
13 toolsconnect_databaseB
Connect to a database (PostgreSQL, MySQL, SQLite, or MongoDB). Returns the connection alias for use in subsequent queries.
Inputs: type (required), host, port, user, +5 more.
describe_tableC
Get detailed schema info for a specific table/collection, including columns, types, constraints, and indexes.
Inputs: table (required), connection.
disconnect_databaseC
Disconnect from a database by its alias.
Inputs: alias.
explain_queryA
Get the execution plan for a query without running it. Useful for optimizing slow queries.
Inputs: query (required), connection.
export_dataC
Export query results as CSV or JSON format. Useful for getting data out of the database in a portable format.
Inputs: query (required), limit, format, connection.
generate_erdB
Generate an Entity Relationship Diagram (ERD) in Mermaid format from the database schema. The output can be rendered in any Mermaid-compatible viewer. Optionally filter to specific tables.
Inputs: tables, connection.
get_schemaB
Get the complete database schema β all tables, columns, indexes, and relationships as structured JSON.
Inputs: connection.
get_table_statsB
Get statistics for database tables β row counts, sizes, index counts, and last analysis time.
Inputs: table, connection.
list_connectionsB
List all active database connections.
Inputs: no named parameters.
list_tablesB
List all tables, views, or collections in the connected database.
Inputs: connection.
run_queryA
Execute a SQL query (PostgreSQL/MySQL/SQLite) or MongoDB query (JSON format). For SQL databases: provide standard SQL. For MongoDB: provide JSON like {"collection":"users","operation":"find","query":{"age":{"$gt":25}},"options":{"limit":10}}. MongoDB operations: find, aggregate, count, distinct. Results are limited to 100 rows by default (max 1000). By default, destructive queries (DROP, TRUNCATE, INSERT, UPDATE, DELETE) are blocked. Set readonly=false to allow writes.
Inputs: query (required), limit, readonly, connection.
search_dataB
Search for a value across all (or specific) tables and text columns. Useful for finding where specific data lives in the database.
Inputs: searchTerm (required), tables, connection, caseSensitive, +1 more.
suggest_indexesB
Analyze a table's columns and existing indexes, then suggest potentially missing indexes based on column patterns (foreign keys, common query patterns).
Inputs: table (required), connection.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
TDQS
Scored across 13 tools
The set is mostly distinct: connection management, schema listing/description, querying, explaining, searching, stats, index suggestions, ERD, and export each have separate roles. Minor overlap exists between get_schema and list_tables/describe_table as aggregate vs granular schema tools, and export_data's relationship to run_query results is slightly unclear.
All 13 tools use snake_case and follow a predictable verb_noun or verb_resource pattern (e.g., list_tables, describe_table, run_query). No casing or style inconsistencies are present.
13 tools is well-scoped for a database exploration server, covering connections, schema, queries, and analysis without excessive surface area. Each tool appears to earn its place.
The surface covers connection lifecycle, schema discovery, query execution, explain plans, search, stats, index advice, ERD generation, and export. Minor gaps may exist (e.g., no explicit list_databases or transaction control), but agents can work around them via run_query and existing tools.
Maintenance
Related MCP Connectors
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with and manage multiple database types (PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, Redis) through natural language, supporting query analysis, schema management, data analysis, backup/restore, and security analysis.8 npm2MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to query databases using natural language, with automatic schema discovery and SQL compilation.453 npm3,236Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.6 npm1ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with PostgreSQL or MySQL databases using natural language. Supports SQL queries, schema discovery, and pre-built aggregations without writing SQL.35 npmMIT