database-explorer-mcp

database-explorer-mcp

Enables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.

Category
Visit Server

README

<div align="center">

πŸ—„οΈ 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.

License: MIT MCP TypeScript Node.js

Features Β· Quick Start Β· Setup Guides Β· Tools Reference Β· Prompts Β· Configuration Β· Contributing

</div>


πŸ€” 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.


✨ 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 build

2. 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

<details> <summary><b>🟣 Claude Desktop</b></summary>

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.

</details>

<details> <summary><b>🟒 Cursor</b></summary>

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.

</details>

<details> <summary><b>πŸ”΅ VS Code (GitHub Copilot)</b></summary>

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.

</details>

<details> <summary><b>🌊 Windsurf</b></summary>

Add to your Windsurf MCP configuration:

{
  "mcpServers": {
    "database-explorer": {
      "command": "node",
      "args": ["/FULL/PATH/TO/database-explorer-mcp/build/index.js"]
    }
  }
}

</details>

<details> <summary><b>πŸ› οΈ Any MCP Client (Generic)</b></summary>

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.js

Or use the MCP Inspector for testing:

npx @modelcontextprotocol/inspector node build/index.js

</details>


πŸ› οΈ Tools (13 total)

Connection Management

Tool Description
connect_database Connect to PostgreSQL, MySQL, SQLite, or MongoDB
disconnect_database Disconnect from a database
list_connections List all active connections

Schema Exploration

Tool Description
list_tables List all tables/views/collections with row counts
describe_table Get columns, types, constraints, indexes for a table
get_schema Full database schema as structured JSON
generate_erd πŸ†• Generate Mermaid ER diagram from schema

Querying & Analysis

Tool Description
run_query Execute SQL or MongoDB queries (read-only by default)
explain_query Get query execution plan
search_data πŸ†• Full-text search across all tables and text columns

Optimization & Export

Tool Description
get_table_stats Row counts, sizes, index statistics
suggest_indexes Smart index optimization recommendations
export_data 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
explore_database Automatically explores and explains the entire database structure
optimize_performance Analyzes tables for performance issues and suggests fixes
write_query Helps you write a query for a specific task
generate_report 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.com

SQLite (File-based, no server needed)

You: Connect to the SQLite database at /path/to/mydb.sqlite

MongoDB

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
DB_EXPLORER_READONLY true Block destructive queries by default
DB_EXPLORER_MAX_ROWS 100 Default row limit for queries
DB_EXPLORER_MAX_ROW_LIMIT 1000 Maximum allowed row limit
DB_EXPLORER_TIMEOUT_MS 30000 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: false is explicitly passed
  • Auto-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:

  1. Fork this repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open 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.


<div align="center">

Built with ❀️ for the AI-assisted development community

If this project helps you, give it a ⭐ on GitHub!

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured