explainLABSCO SUMMARY
Create the read-only role first; the SQL in the README is the setup step, not an appendix.
The metadata tools need nothing more than SELECT on a handful of pg_stat_* views and a few size functions, and the README spells out exactly which grants that is. Doing it that way removes the risk from the whole integration, which matters because the EXPLAIN ANALYZE tools — the ones that make the diagnosis genuinely useful — do let an LLM run arbitrary queries, transaction-wrapped or not.
What it is
An MCP interface over the rails-pg-extras gem, mounted into your own Rails application as a route. It exposes PostgreSQL's diagnostic metadata — the queries that tell you about bloat, index usage, slow statements, locks and connections — so an LLM can explore them and explain what it finds, instead of you running each query by hand and interpreting the output yourself.
What you get
- PostgreSQL metadata and performance metrics as MCP tools: table bloat, slow queries, unused indexes and the rest of the pg-extras set
- Bottleneck queries surfaced through the gem's
callsandoutliersreports - Optional EXPLAIN and EXPLAIN ANALYZE on those bottlenecks —
explainandexplain_analyze, each behind its own environment flag - The connected database user readable through the
connectionstool, so you can confirm which role the LLM is actually using - An HTTP SSE interface mounted at a path you choose in
config/routes.rb, with an optional auth token - An execution context wrapped in a transaction and rolled back, so in theory data modification is not possible through the explain path
Requirements
A Rails application with PostgreSQL. Add the gem with bundle add rails-pg-extras-mcp and mount RailsPgExtrasMcp::App.build in config/routes.rb; RailsPgExtrasMcp::App.build(opts) passes options straight through to fast-mcp, and a production mount typically needs allowed_origins, allowed_ips, auth_token and localhost_only: false. Clients reach it through mcp-remote — npm install -g mcp-remote — pointed at the SSE path with an Authorization header. The EXPLAIN tools are off unless PG_EXTRAS_MCP_EXPLAIN_ENABLED and PG_EXTRAS_MCP_EXPLAIN_ANALYZE_ENABLED are set to true; enabling them means an LLM can run arbitrary queries against your database, so the README asks you to use a read-only role and offers RAILS_PG_EXTRAS_MCP_DATABASE_URL to override the default ActiveRecord connection. The project describes itself as early beta.
Setup effort
Follow the published steps — bundle add rails-pg-extras-mcp
USE CASES
Finding out what is actually slow
Read the calls and outliers reports and let the LLM rank the bottlenecks instead of eyeballing pg_stat_statements output.
Explaining a slow query without a psql session
Enable the explain tools against a read-only role and have the plan analysed and explained in the same conversation.
Cleaning up indexes and bloat
Ask for unused indexes and table bloat, and get the answer as a prioritised list rather than raw query output.
Confirming the LLM is where you think it is
Ask which database user it is connected as before letting it run anything, using the connections tool.
5 tools
Listed in project docs. Your client may show a different list.
explain_analyzeconnectionscallsoutliersBEFORE YOU INSTALL
What to know first
Tools you get
5 tools named in the project's documentation.
Where it runs
The documented client runs the server on your machine.
INSTALLATION
Connect your client
Server setup
bundle add rails-pg-extras-mcpIn config/routes.rb: mount RailsPgExtrasMcp::App.build, at: "pg_extras_mcp" (optionally with opts = { auth_token: "secret" })
npm install -g mcp-remoteAdd the pg-extras mcpServers entry that shells out to npx mcp-remote against your app's /pg_extras_mcp/sse endpoint
MCP Clients
Any MCP client
{
"mcpServers": {
"pg-extras": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:3000/pg_extras_mcp/sse",
"--header",
"Authorization: secret"
]
}
}
}