Rails PG Extras MCP
About
An MCP interface for the rails-pg-extras gem, providing PostgreSQL metadata and performance analysis through LLM prompts.
Details
- Author
- pawurb
- Categories
- Database, Other, Infrastructure
Jump to
Setup
Install Rails PG Extras MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/pawurb/rails-pg-extras-mcp
Follow the installation instructions in the repository README, then restart your MCP client.
MCP (Model Context Protocol) interface forrails-pg-extrasgem. Easily explore PostgreSQL metadata and debug performance issues. Check for table bloat, slow queries, unused indexes, and more. RunEXPLAIN ANALYZEon bottlenecks and get clear, LLM-powered insights to optimize your database.
Use a minimally privileged,read-only userto eliminate the risk of data modification or exposure.
Check outthis postfor more in-depth info on the project.
The library supports MCP protocol via HTTP SSE interface.
mount RailsPgExtrasMcp::App.build, at: "pg_extras_mcp"
opts = { auth_token: "secret" } mount RailsPgExtrasMcp::App.build(opts), at: "pg_extras_mcp"
opts = { allowed_origins: [ /../ ], allowed_ips: [ "" ], auth_token: "secret", localhost_only: false } mount RailsPgExtrasMcp::App.build(opts) at: "pg_extras_mcp"
{ "mcpServers": { "pg-extras": { "command": "npx", "args": [ "mcp-remote", "http://localhost:3000/pg_extras_mcp/sse", "--header", "Authorization: secret" ] } } }
You can now ask LLM questions about the metadata and performance metrics of your database.
callsandoutliersmethods return a list of bottleneck queries. LLM can get better insights into these queries by performingEXPLAINandEXPLAIN ANALYZEanalysis. MCP server exposes two optional methods for this purpose:explainandexplain_analyze.
You can enable them by setting the followingENVvariables:
ENV['PG_EXTRAS_MCP_EXPLAIN_ENABLED'] = 'true'ENV['PG_EXTRAS_MCP_EXPLAIN_ANALYZE_ENABLED'] = 'true'
Enabling these features means that an LLM, can run arbitrary queries in your database. The execution context is wrapped in a transaction and rolled back, so, in theory, any data modification should not be possible. But it's advised to configure a read-only permission if you want to use these features. By specifyingENV['RAILS_PG_EXTRAS_MCP_DATABASE_URL']you can overwrite the default Rails ActiveRecord database connection to restrict an access scope:
If you're not planing to useEXPLAIN ANALYZEfeatures, you should configure a user with read access only to the metadata tables:
CREATE ROLE extras_viewer NOLOGIN; CREATE USER extras_user WITH PASSWORD 'your_password'; GRANT extras_viewer TO extras_user; GRANT CONNECT ON DATABASE your_db_name TO extras_user; GRANT USAGE ON SCHEMA public TO extras_user; GRANT SELECT ON pg_stat_statements TO extras_user; GRANT SELECT ON pg_stat_activity, pg_locks TO extras_user; GRANT SELECT ON pg_stat_user_indexes, pg_index TO extras_user; GRANT SELECT ON pg_stat_all_tables, pg_stat_database, pg_settings, pg_namespace TO extras_user; GRANT EXECUTE ON FUNCTION pg_relation_size(regclass) TO extras_user; GRANT EXECUTE ON FUNCTION pg_indexes_size(regclass) TO extras_user; GRANT EXECUTE ON FUNCTION pg_table_size(regclass) TO extras_user; GRANT EXECUTE ON FUNCTION pg_total_relation_size(regclass) TO extras_user;
You can ask an LLM to check which db user it's connected with usingconnectionstool.
The project is in an early beta, so proceed with caution.
An MCP server for PostgreSQL providing index tuning, explain plans, health checks, and safe SQL execution.
MCP-PostgreSQL-Ops is a professional MCP server for PostgreSQL database operations, monitoring, and management. Supports PostgreSQL 12-17 with comprehensive database analysis, performance monitoring, and intelligent maintenance recommendations through natural language queries.
Multi-database agent access (PostgreSQL, SQLite, MySQL, Oracle, SQL Server) with batch queries, pre-configured connections, and SQLGlot-enforced read-only safety
A read-only MCP server for querying AWS PostgreSQL databases.
A read-only MCP server for AlloyDB, enabling LLMs to query live data directly from AlloyDB databases.
A read-only MCP server by CData that enables LLMs to query live data from EnterpriseDB databases.
A server for direct interaction with CockroachDB databases.
Database MCP server for MySQL, MariaDB, PostgreSQL & SQLite
A single-binary MCP server for MySQL, MariaDB, PostgreSQL, and SQLite
A Model Context Protocol (MCP) server that provides multi-database query execution capabilities with support for SQLite, PostgreSQL, and MySQL databases. Includes a built-in Web UI for managing database connections.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





