Skip to content

Added MCP server - #546

Closed
mjavadalavi wants to merge 1 commit into
ankane:masterfrom
mjavadalavi:mcp-server
Closed

mjavadalavi wants to merge 1 commit into
ankane:masterfrom
mjavadalavi:mcp-server

Conversation

@mjavadalavi

@mjavadalavi mjavadalavi commented Sep 20, 2026 •

Copy link
Copy Markdown

This PR adds a built-in MCP server, so AI assistants like Claude can inspect database performance — running queries, query stats, explain plans, indexes, space usage, maintenance, connections, replication, sequences, settings, and more.

Design

  • communicates over stdio (JSON-RPC) — no HTTP server or extra port needed
  • read-only — tools never modify the database; mutating operations (kill queries, reset stats, capture stats, analyze tables, autoindex) are intentionally not exposed, and explain never uses ANALYZE
  • no additional dependencies — implemented with the JSON stdlib, keeping the gemspec unchanged apart from the new executable
  • uses the same configuration as the rest of the gem: PGHERO_DATABASE_URL or config/pghero.yml (PGHERO_CONFIG_PATH), works with or without Rails
  • new pghero-mcp executable; guides/MCP.md documents setup for Claude Code, Claude Desktop, and Cursor

Tools (31)

All tools accept an optional database argument and default to the first configured database.

  • queries — overview, running_queries, long_running_queries, blocked_queries, explain
  • query stats — query_stats, query_stats_status, query_details
  • indexes — indexes, invalid_indexes, duplicate_indexes, unused_indexes, index_usage, index_bloat, missing_indexes, suggested_indexes, best_index
  • space & tables — space, space_growth, relation_space_stats, table_stats, unused_tables, caching
  • infrastructure — maintenance, settings, connections, replication, sequences, invalid_constraints, system_stats, databases

Feature availability matches the gem: query stats tools require the pg_stat_statements extension, suggested indexes require the pg_query gem, and system stats require AWS/GCP config — tools return a clear error message when a prerequisite is missing.

Testing

15 new tests covering the protocol (initialize/version negotiation, ping, notifications, error codes) and tool calls against a real database. Full suite: 203 runs, 0 failures.

- read-only MCP server over stdio for AI assistants
- 31 tools: queries, query stats, explain, indexes, space,
  maintenance, connections, replication, sequences, settings,
  and more
- no additional dependencies
- pghero-mcp executable
@ankane

ankane commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Hi @mjavadalavi, thanks for the PR, but it's not something I'd like to maintain.

@ankane ankane closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants