postgres-mcp-js
This MCP server provides safe, read-only access to PostgreSQL, MySQL, and MongoDB databases for schema inspection, query analysis, performance diagnostics, and health monitoring — designed for AI assistants like Claude, Cursor, and Windsurf.
Multi-database connectivity: Connect up to 3 databases simultaneously (PostgreSQL, MySQL, MongoDB) with automatic type detection from URL prefixes, referenced by aliases instead of direct credentials.
Schema inspection: List configured databases, schemas, tables/views/collections, sequences, and extensions; retrieve detailed object metadata including columns, constraints, indexes, and sample MongoDB documents.
Safe query execution: Run read-only SQL queries (SELECT, EXPLAIN, SHOW, WITH) with a 30-second timeout and read-only transactions enforced at the database level. MongoDB supports JSON-based queries with filtering.
Query analysis: Generate EXPLAIN plans (with optional ANALYZE), simulate hypothetical indexes via hypopg, and retrieve top/slow/resource-intensive queries via pg_stat_statements, MySQL performance_schema, or MongoDB system.profile.
Index analysis: Analyze query workloads to recommend missing indexes, detect sequential scan hotspots and FK columns without indexes, and analyze specific queries for index needs.
Health monitoring: Comprehensive checks covering index usage, connection status, replication lag, buffer hit ratios, vacuum/dead tuple status, sequence usage, and constraint validity.
Advanced diagnostics: Detect lock contention, blocking chains, idle-in-transaction sessions, and analyze table/index bloat with VACUUM recommendations.
Security: Credentials are never exposed to the AI (alias-only references), write operations are blocked in restricted mode, SQL statements are validated, and query timeouts are enforced. Zero configuration needed beyond environment variables in the MCP client config.
Provides safe, structured access to a PostgreSQL database, enabling health checks, index tuning, lock analysis, bloat detection, schema inspection, and SQL execution with read-only enforcement.
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., "@postgres-mcp-js Run a full health check on the primary 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.
anydb-mcp
One MCP server. Any database. PostgreSQL, MySQL, and MongoDB — all at once. Give Claude, Cursor, Windsurf, or any MCP-compatible AI safe, structured access to all your databases without ever exposing credentials.
What is this?
anydb-mcp is a Model Context Protocol (MCP) server that connects AI assistants to your databases. Connect up to 3 databases simultaneously — mix and match PostgreSQL, MySQL, and MongoDB. The AI can inspect schemas, diagnose performance problems, detect missing indexes, analyze locks, find slow queries across all databases in one call, and run safe read-only queries — all through a single, unified interface.
Works with: Claude Desktop, Claude Code, Cursor, Windsurf, Zed, and any MCP-compatible client.
Related MCP server: PostgreSQL MCP Server
Features
PostgreSQL + MySQL + MongoDB — connect any combination, up to 3 at once
Auto-detects DB type from the URL prefix (
postgresql://,mysql://,mongodb://)Up to 3 databases simultaneously — primary, secondary, tertiary — switchable per tool call
14 built-in tools — schema inspection, health checks, index analysis, lock detection, bloat, slow queries
list_slow_queriesfans out across all DBs — one call, combined report from every connected databaseCredential isolation — passwords never appear in tool calls or AI responses; AI only sees aliases like
"primary"Restricted mode — read-only transactions enforced at the database level (PostgreSQL/MySQL), 30s timeout
Index miss detection — sequential scan hotspots, FK columns without indexes, unused index stats
Lock analysis — blocking chains (PostgreSQL/MySQL), current operations (MongoDB)
Table bloat — dead-tuple analysis with VACUUM recommendations (PostgreSQL)
hypopg support — simulate hypothetical indexes before creating them (PostgreSQL)
Zero config — credentials go in the MCP client
envblock, no.envfile needed
Quick start
npx (no install needed)
npx anydb-mcpGlobal install
npm install -g anydb-mcp
anydb-mcpLocal clone
git clone https://github.com/shubham4038/anydb-mcp.git
cd anydb-mcp
npm install && npm run build
node dist/index.jsConnect to your AI
Credentials go in the env block — no .env file needed on the user's side.
Claude Desktop
File: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"anydb": {
"command": "npx",
"args": ["anydb-mcp"],
"env": {
"DB_PRIMARY_URL": "postgresql://user:pass@localhost:5432/mydb",
"ACCESS_MODE": "restricted"
}
}
}
}Claude Code
File: ~/.claude/settings.json
{
"mcpServers": {
"anydb": {
"command": "npx",
"args": ["anydb-mcp"],
"env": {
"DB_PRIMARY_URL": "postgresql://user:pass@localhost:5432/mydb",
"ACCESS_MODE": "restricted"
}
}
}
}Cursor
Settings → MCP → Add new MCP server:
{
"command": "npx",
"args": ["anydb-mcp"],
"env": {
"DB_PRIMARY_URL": "mysql://user:pass@localhost:3306/mydb",
"ACCESS_MODE": "restricted"
}
}Windsurf
File: ~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"anydb": {
"command": "npx",
"args": ["anydb-mcp"],
"env": {
"DB_PRIMARY_URL": "mongodb://user:pass@localhost:27017/mydb"
}
}
}
}Connecting multiple databases
Mix any combination of PostgreSQL, MySQL, and MongoDB. The AI uses the alias to target the right database — it never sees connection strings.
{
"env": {
"DB_PRIMARY_URL": "postgresql://user:pass@pg-host:5432/production",
"DB_PRIMARY_NAME": "production",
"DB_SECONDARY_URL": "mysql://user:pass@mysql-host:3306/legacy",
"DB_SECONDARY_NAME": "legacy",
"DB_TERTIARY_URL": "mongodb://user:pass@mongo-host:27017/analytics",
"DB_TERTIARY_NAME": "analytics",
"ACCESS_MODE": "restricted"
}
}DB type is auto-detected from the URL prefix:
URL prefix | Database |
| PostgreSQL |
| MySQL |
| MongoDB |
Example multi-DB AI prompts:
"List slow queries across all my databases"
"Compare index health between production and legacy"
"Show me what's currently locking on production"
"Is the analytics MongoDB missing any indexes?"
Tools
Every tool accepts an optional database parameter (defaults to the primary database). Call list_databases first to see what's configured.
Schema inspection
Tool | PostgreSQL | MySQL | MongoDB |
| schemas | schemas | databases |
| ✅ | ✅ | ✅ |
| tables/views | tables/views | collections |
| columns + indexes | columns + indexes | indexes + sample doc |
SQL & query execution
Tool | Description |
| PostgreSQL/MySQL: SQL string. MongoDB: JSON |
| EXPLAIN plan. PostgreSQL supports |
| PostgreSQL: |
| All databases at once — historical + currently running slow queries, combined report |
Index analysis
Tool | PostgreSQL | MySQL | MongoDB |
| ✅ full | ✅ via perf_schema | ✅ via $indexStats |
| ✅ EXPLAIN | ✅ EXPLAIN | ✅ explain() |
| ✅ seq scans + FK | ✅ perf_schema | ✅ $indexStats |
Health checks
Pass health_type: "all" or any specific check:
Check | PostgreSQL | MySQL | MongoDB |
| unused/invalid/duplicate | unused via perf_schema | unused via $indexStats |
| state breakdown | processlist | connections from serverStatus |
| dead tuples + wraparound | ❌ N/A | ❌ N/A |
| sequences > 75% used | ❌ N/A | ❌ N/A |
| replica lag + slots | ❌ N/A | ✅ replSetGetStatus |
| shared buffer hit ratio | InnoDB buffer pool | ❌ N/A |
| invalid constraints | ❌ N/A | ❌ N/A |
Advanced diagnostics
Tool | PostgreSQL | MySQL | MongoDB |
| blocking chains + idle-in-tx | InnoDB trx + data_lock_waits | currentOp |
| ✅ dead tuples + VACUUM | not applicable | not applicable |
Security model
Protection | How it works |
Credentials never reach the AI | DB URLs read from env at startup only — never in tool args or results |
Alias-only identity | AI sees |
DB-level read-only | PostgreSQL/MySQL: every query runs inside |
Statement validation | PostgreSQL/MySQL: first SQL keyword checked before query reaches the DB |
Query timeout | 30-second |
Completely isolated adapters | PostgreSQL, MySQL, MongoDB code never imports from each other — enforced by TypeScript |
Optional extensions
PostgreSQL
CREATE EXTENSION IF NOT EXISTS pg_stat_statements; -- enables get_top_queries
CREATE EXTENSION IF NOT EXISTS hypopg; -- enables hypothetical index simulationAdd to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements'MySQL
performance_schema should be enabled by default in MySQL 5.6+. Verify:
SHOW VARIABLES LIKE 'performance_schema';MongoDB
Enable the profiler for slow query tracking:
db.setProfilingLevel(1, { slowms: 100 })Docker
docker build -t anydb-mcp .
docker run --rm -i \
-e DB_PRIMARY_URL="postgresql://user:pass@host:5432/mydb" \
-e DB_SECONDARY_URL="mysql://user:pass@host:3306/mydb" \
-e ACCESS_MODE=restricted \
anydb-mcpLocal development
git clone https://github.com/shubham4038/anydb-mcp.git
cd anydb-mcp
npm install
npm run dev # runs with tsx, no build step needed
npm run typecheck # type check only
npm run build # production buildArchitecture
Each database adapter is 100% self-contained. PostgreSQL code never imports MySQL code, MySQL never imports MongoDB code. They only share a common TypeScript interface.
src/
adapters/
types.ts ← shared interface only (no logic)
postgres/ ← all PostgreSQL code, isolated
mysql/ ← all MySQL code, isolated
mongodb/ ← all MongoDB code, isolated
db/
registry.ts ← only place that knows all 3 adapters exist
server.ts ← MCP tools, calls adapter.method() without knowing which DBGitHub topics
Add these in Settings → Topics for discoverability:
mcp model-context-protocol postgresql mysql mongodb database multi-database ai claude cursor llm developer-tools typescript nodejs
License
MIT — free to use, modify, and distribute.
Available Tools
13 toolsanalyze_db_healthB
Run comprehensive database health checks across multiple dimensions.
Inputs: database, health_type.
analyze_locksB
Detect lock contention: blocking chains, long-running queries, idle-in-transaction sessions.
Inputs: database.
analyze_query_indexesA
Analyze specific SQL queries and identify missing indexes. Maximum 10 queries.
Inputs: queries (required), database, max_index_size_mb.
analyze_table_bloatB
Detect table and index bloat from dead tuples. Returns vacuum recommendations.
Inputs: database.
analyze_workload_indexesB
Analyze query workload from pg_stat_statements and recommend missing indexes.
Inputs: database, max_index_size_mb.
detect_index_missesB
Detect tables likely suffering from missing indexes: seq-scan dominance, FK columns without indexes, under-indexed hot tables.
Inputs: database.
execute_sqlA
Execute a read-only SQL query (SELECT, EXPLAIN, SHOW, WITH). Write operations are blocked. Max execution time: 30 seconds.
Inputs: sql (required), database.
explain_queryA
Get the query execution plan. Supports hypothetical index simulation (requires hypopg extension).
Inputs: sql (required), analyze, database, hypothetical_indexes.
get_object_detailsC
Get columns, constraints, and indexes for a table or view.
Inputs: object_name (required), schema_name (required), database, object_type.
get_top_queriesB
Report the slowest or most resource-intensive queries using pg_stat_statements.
Inputs: limit, sort_by, database.
list_databasesA
List configured database aliases. Use the returned names in the "database" parameter of other tools.
Inputs: no named parameters.
list_objectsB
List tables, views, sequences, or extensions in a schema.
Inputs: schema_name (required), database, object_type.
list_schemasA
List all schemas in the database.
Inputs: database.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Most tools have clear and distinct purposes, though the index analysis tools (analyze_query_indexes, analyze_workload_indexes, detect_index_misses) overlap somewhat in focus, potentially causing some confusion for an agent.
All tools use a consistent underscore-separated verb_noun pattern (e.g., analyze_locks, list_databases), making the tool set predictable and easy to navigate.
With 13 tools, the set is well-scoped for a database analysis server, covering essential operations without being overwhelming or insufficient.
The tool set comprehensively covers read-only database analysis: health, locks, bloat, indexes, query explanation, and object listing. There are no obvious gaps for its stated purpose.
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Xata MCP server lets AI agents interact with your Xata projects, and Postgres database branches.
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.1810,856 npm204AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides AI assistants with secure, read-only access to PostgreSQL databases while offering comprehensive tools for schema exploration, query validation, and performance optimization.MIT
- AlicenseBqualityDmaintenanceAn open source Model Context Protocol server for PostgreSQL that provides database health analysis, index tuning, query plan exploration, and safe SQL execution for AI agents throughout the development process.9MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for PostgreSQL, MySQL, and SQLite that gives AI assistants secure database access via the Model Context Protocol.56 npm5MIT