Postgres Scout Mcp

io.github.bluwork由 GitHub 账号 bluwork 发布v1.0.3更新于 Oct 24, 2026

Scout your PostgreSQL databases with AI - safety features, monitoring, and data quality

概览

AI 生成的概览

让助手通过 38 个工具检查、诊断并可选地修改 PostgreSQL 数据库,涵盖健康度、性能与数据质量。

可以做什么
Postgres Scout 将助手连接到 PostgreSQL 数据库,提供 38 个工具,分为探索、查询、诊断、优化、监控、数据质量、关系、时间序列、导出和写入等类别。它可以列出数据库、模式和表,描述表结构,执行并解释查询,给出整体健康评分,检测异常和表膨胀,建议索引和分区,检查锁和实时活动,查找重复行、缺失值和孤立记录,并将表导出为 CSV、JSON、JSONL 或 SQL。safeUpdate、safeDelete、safeInsert 等写入工具带有试运行预览和行数限制。
适用场景
适合助手需要回答 PostgreSQL 数据库运维问题的场景,例如哪些表存在膨胀、哪些查询较慢、数据是否有重复或孤立行。适合希望默认只读探索、并在需要时另开实例进行受控写入的开发者和 DBA。
运行要求
通过 stdio 在本地运行,通常使用 npx postgres-scout-mcp 并附带 PostgreSQL 连接字符串作为参数。需要 Node.js 以及访问数据库的网络。可选环境变量用于配置查询超时、结果行数上限、速率限制、连接池大小和日志。部分诊断功能(如 getSlowQueries)需要 pg_stat_statements 扩展。
安装前请注意
服务器默认只读,但读写实例可以对所连数据库执行 UPDATE、DELETE 和 INSERT;应指向开发数据库而非生产库。写入工具提供试运行和行数限制,但仍会修改数据。连接字符串作为命令行参数传入,可能出现在进程列表中。启用文件日志会把工具调用及参数写入磁盘,不过连接字符串会被脱敏。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Postgres Scout Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

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.

[npm] [License]

What You Get

You ask:

"How healthy is my production database? Any urgent issues?"

Postgres Scout returns:


Overall Health Score: 78/100

Component Breakdown

ComponentScoreStatus
Cache Performance94/100Healthy
Index Efficiency82/100Good
Table Bloat61/100Needs Attention
Connection Usage75/100Fair

Issues Found

  • HIGH — Table orders has 34% bloat (2.1 GB wasted). VACUUM FULL recommended.
  • MEDIUM — 3 unused indexes on sessions consuming 890 MB.
  • LOW — Cache hit ratio for analytics_events is 71% (target: >90%).

Recommendations

  • Run VACUUM FULL orders during maintenance window
  • Drop unused indexes: idx_sessions_legacy, idx_sessions_old_token, idx_sessions_temp
  • Consider adding analytics_events to 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

bash
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):

json
{  "mcpServers": {    "postgres-scout": {      "command": "npx",      "args": ["-y", "postgres-scout-mcp", "postgresql://localhost:5432/mydb"],      "type": "stdio"    }  }}
Cursor / VS Code

Add to your MCP settings:

json
{  "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:

json
{  "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 to
  • getDatabaseStats — size, cache hit ratio, connection info
  • listSchemas — all schemas in the current database
  • listTables — tables with size and row statistics
  • describeTable — columns, constraints, indexes, and more

Query — run and analyze

  • executeQuery — run SELECT queries (or writes in read-write mode)
  • explainQuery — EXPLAIN plans for performance analysis
  • optimizeQuery — optimization recommendations for a specific query

Diagnose — find problems before they find you

  • getHealthScore — overall health score with component breakdown
  • detectAnomalies — anomalies in performance, connections, and data
  • analyzeTableBloat — bloat analysis for VACUUM planning
  • getSlowQueries — 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 patterns
  • suggestPartitioning — partitioning strategies for large tables
  • getIndexUsage — identify unused or underused indexes

Monitor — watch it live

  • getCurrentActivity — active queries and connections
  • analyzeLocks — lock contention and blocking queries
  • getLiveMetrics — real-time metrics over a time window
  • getHottestTables — tables with highest activity
  • getTableMetrics — comprehensive per-table I/O and scan stats

Data Quality — trust your data

  • findDuplicates — duplicate rows by column combination
  • findMissingValues — NULL analysis across columns
  • findOrphans — orphaned records with invalid foreign keys
  • checkConstraintViolations — test constraints before adding them
  • analyzeTypeConsistency — type inconsistencies in text columns

Relationships — follow the connections

  • exploreRelationships — multi-hop foreign key traversal
  • analyzeForeignKeys — foreign key health and performance

Time Series — temporal analysis

  • findRecent — rows within a time window
  • analyzeTimeSeries — window functions and anomaly detection
  • detectSeasonality — seasonal pattern detection

Export — get data out

  • exportTable — CSV, JSON, JSONL, or SQL
  • generateInsertStatements — INSERT statements for migration

Write (read-write only) — safe modifications

  • previewUpdate / previewDelete — see what would change before committing
  • safeUpdate — UPDATE with dry-run, row limits, empty WHERE protection
  • safeDelete — DELETE with dry-run, row limits, empty WHERE protection
  • safeInsert — 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

VariableDefaultDescription
QUERY_TIMEOUT30000Query timeout in milliseconds
MAX_RESULT_ROWS10000Maximum rows returned per query
ENABLE_RATE_LIMITtrueEnable rate limiting
RATE_LIMIT_MAX_REQUESTS100Requests per window
RATE_LIMIT_WINDOW_MS60000Rate limit window (ms)
PGMAXPOOLSIZE10Connection pool max size
PGMINPOOLSIZE2Connection pool min size
PGIDLETIMEOUT10000Idle connection timeout (ms)
ENABLE_LOGGINGfalseEnable file logging
LOG_DIR./logsLog file directory
LOG_LEVELinfoLog 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

bash
git clone https://github.com/bluwork/postgres-scout-mcp.gitcd postgres-scout-mcppnpm installpnpm buildpnpm test

License

Apache-2.0

来源:README.md,提交 3cb6fa3

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.3最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分