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 "Install 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-jsRun 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.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/shubham4038/postgres-mcp-js'
If you have feedback or need assistance with the MCP directory API, please join our Discord server