io.github.bluwork/postgres-scout-mcp
Scout your PostgreSQL databases with AI - safety features, monitoring, and data quality
Ask AI about io.github.bluwork/postgres-scout-mcp
Powered by Claude Β· Grounded in docs
I know everything about io.github.bluwork/postgres-scout-mcp. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Postgres Scout MCP
Scout your PostgreSQL databases with AI - A production-ready Model Context Protocol server with built-in safety features, monitoring, and data quality tools.
What You Get
You ask:
"How healthy is my production database? Any urgent issues?"
Postgres Scout returns:
Overall Health Score: 78/100
Component Breakdown
| Component | Score | Status |
|---|---|---|
| Cache Performance | 94/100 | Healthy |
| Index Efficiency | 82/100 | Good |
| Table Bloat | 61/100 | Needs Attention |
| Connection Usage | 75/100 | Fair |
Issues Found
- HIGH β Table
ordershas 34% bloat (2.1 GB wasted). VACUUM FULL recommended. - MEDIUM β 3 unused indexes on
sessionsconsuming 890 MB. - LOW β Cache hit ratio for
analytics_eventsis 71% (target: >90%).
Recommendations
- Run
VACUUM FULL ordersduring maintenance window - Drop unused indexes:
idx_sessions_legacy,idx_sessions_old_token,idx_sessions_temp - Consider adding
analytics_eventsto shared_buffers or partitioning by date
That's getHealthScore β one of 38 tools covering exploration, diagnostics, optimization, monitoring, data quality, and safe writes.
Quick Start
Claude Code
claude mcp add postgres-scout -- npx -y postgres-scout-mcp postgresql://localhost:5432/mydb
Then ask: "Show me the largest tables and whether they have any bloat issues."
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"postgres-scout": {
"command": "npx",
"args": ["-y", "postgres-scout-mcp", "postgresql://localhost:5432/mydb"],
"type": "stdio"
}
}
}
Cursor / VS Code
Add to your MCP settings:
{
"postgres-scout": {
"command": "npx",
"args": ["-y", "postgres-scout-mcp", "postgresql://localhost:5432/mydb"]
}
}
Read-Only vs Read-Write
The server runs in read-only mode by default. For write operations, run a separate instance:
{
"mcpServers": {
"postgres-scout-readonly": {
"command": "npx",
"args": ["-y", "postgres-scout-mcp", "--read-only", "postgresql://localhost:5432/production"],
"type": "stdio"
},
"postgres-scout-readwrite": {
"command": "npx",
"args": ["-y", "postgres-scout-mcp", "--read-write", "postgresql://localhost:5432/development"],
"type": "stdio"
}
}
}
- postgres-scout-readonly: Safe exploration, no risk of data modification
- postgres-scout-readwrite: Write operations when explicitly needed
Tools
Explore β understand your database
listDatabasesβ databases the user has access togetDatabaseStatsβ size, cache hit ratio, connection infolistSchemasβ all schemas in the current databaselistTablesβ tables with size and row statisticsdescribeTableβ columns, constraints, indexes, and more
Query β run and analyze
executeQueryβ run SELECT queries (or writes in read-write mode)explainQueryβ EXPLAIN plans for performance analysisoptimizeQueryβ optimization recommendations for a specific query
Diagnose β find problems before they find you
getHealthScoreβ overall health score with component breakdowndetectAnomaliesβ anomalies in performance, connections, and dataanalyzeTableBloatβ bloat analysis for VACUUM planninggetSlowQueriesβ slow query analysis (requires pg_stat_statements)suggestVacuumβ VACUUM recommendations based on dead tuples and bloat
Optimize β make it faster
suggestIndexesβ missing index recommendations from query patternssuggestPartitioningβ partitioning strategies for large tablesgetIndexUsageβ identify unused or underused indexes
Monitor β watch it live
getCurrentActivityβ active queries and connectionsanalyzeLocksβ lock contention and blocking queriesgetLiveMetricsβ real-time metrics over a time windowgetHottestTablesβ tables with highest activitygetTableMetricsβ comprehensive per-table I/O and scan stats
Data Quality β trust your data
findDuplicatesβ duplicate rows by column combinationfindMissingValuesβ NULL analysis across columnsfindOrphansβ orphaned records with invalid foreign keyscheckConstraintViolationsβ test constraints before adding themanalyzeTypeConsistencyβ type inconsistencies in text columns
Relationships β follow the connections
exploreRelationshipsβ multi-hop foreign key traversalanalyzeForeignKeysβ foreign key health and performance
Time Series β temporal analysis
findRecentβ rows within a time windowanalyzeTimeSeriesβ window functions and anomaly detectiondetectSeasonalityβ seasonal pattern detection
Export β get data out
exportTableβ CSV, JSON, JSONL, or SQLgenerateInsertStatementsβ INSERT statements for migration
Write (read-write only) β safe modifications
previewUpdate/previewDeleteβ see what would change before committingsafeUpdateβ UPDATE with dry-run, row limits, empty WHERE protectionsafeDeleteβ DELETE with dry-run, row limits, empty WHERE protectionsafeInsertβ INSERT with validation, batching, ON CONFLICT support
Security
- Read-only by default β write operations must be explicitly enabled
- All queries use parameterized values
- SQL injection prevention with input validation and pattern detection
- Identifier sanitization for table/column names
- Rate limiting on all operations
- Query timeouts to prevent long-running queries
- Response size limits to prevent memory exhaustion
Examples
"What are the largest tables and do they have bloat?"
listTables({ schema: "public" })
analyzeTableBloat({ schema: "public", minSizeMb: 100 })
"Find duplicate emails in the users table."
findDuplicates({ table: "users", columns: ["email"] })
"Which queries are slowest and how can I speed them up?"
getSlowQueries({ minDurationMs: 100, limit: 10 })
suggestIndexes({ schema: "public" })
"Show me what's happening on the database right now."
getCurrentActivity()
getLiveMetrics({ metrics: ["queries", "connections", "cache"], duration: 30000, interval: 1000 })
getHottestTables({ limit: 5, orderBy: "seq_scan" })
"Find orphaned orders that reference deleted customers."
findOrphans({ table: "orders", foreignKey: "customer_id", referenceTable: "customers", referenceColumn: "id" })
Configuration
| Variable | Default | Description |
|---|---|---|
QUERY_TIMEOUT | 30000 | Query timeout in milliseconds |
MAX_RESULT_ROWS | 10000 | Maximum rows returned per query |
ENABLE_RATE_LIMIT | true | Enable rate limiting |
RATE_LIMIT_MAX_REQUESTS | 100 | Requests per window |
RATE_LIMIT_WINDOW_MS | 60000 | Rate limit window (ms) |
PGMAXPOOLSIZE | 10 | Connection pool max size |
PGMINPOOLSIZE | 2 | Connection pool min size |
PGIDLETIMEOUT | 10000 | Idle connection timeout (ms) |
ENABLE_LOGGING | false | Enable file logging |
LOG_DIR | ./logs | Log file directory |
LOG_LEVEL | info | Log verbosity: debug, info, warn, error |
CLI flags: --read-only (default), --read-write, --mode <mode>
Logging
File logging is disabled by default. Set ENABLE_LOGGING=true to enable. Two log files are created in LOG_DIR:
- tool-usage.log β every tool call with timestamp, name, and arguments
- error.log β errors with stack traces
Connection strings are automatically redacted in all output.
Development
git clone https://github.com/bluwork/postgres-scout-mcp.git
cd postgres-scout-mcp
pnpm install
pnpm build
pnpm test
License
Apache-2.0
