multigres-mcp
Inspect and troubleshoot Postgres databases running behind a Multigres gateway, read-only by default, with optional cluster administration and write tools in unrestricted mode.
Explore the schema:
list_schemas,list_objects(tables, views, sequences, extensions),get_object_details(columns, constraints, indexes).Run read-only SQL:
execute_sqltakes oneSELECT/EXPLAIN/SHOW, checked by the Multigres parser and run in a rolled-back read-only transaction.See query plans:
explain_querywith optionalANALYZEor hypothetical indexes (hypopg).Get index advice:
analyze_workload_indexesfor the wholepg_stat_statementsworkload,analyze_query_indexesfor up to 10 queries you supply; nothing is created.Find slow queries:
get_top_queriesranks by time or resources frompg_stat_statementsand per-gateway statistics, optionally on one node.Check health:
diagnoseruns bloat, vacuum, locks, activity, waits, slow queries, missing indexes, cache, log, index health, sequences, replication and constraint checks.Cluster operations (need
--admin-url):cluster_status,list_backups,verify_backups,get_backup_job_status,read_node_log.Write/admin tools (unrestricted mode only):
execute_write_sql,switch_primary,create_backup,expire_backups,set_postgres_restarts.
Provides PostgreSQL diagnostics and cluster management for Multigres clusters, including schema and object inspection, read-only SQL execution, query plans with hypothetical indexes, top-query analysis, index advice, health checks, cluster status, backup operations, and node log reading.
multigres-mcp
An MCP server for Multigres clusters. It gives an MCP client two groups of tools:
Postgres diagnostics through the Multigres gateway: schemas and objects, read-only SQL, query plans with hypothetical indexes, top queries, index advice and a health check. These follow the tools of postgres-mcp.
Cluster tools through multiadmin: cluster status, backups, node logs, and in the unrestricted mode switching the primary and starting or expiring backups.
The server is read-only by default. Write tools are registered only in the unrestricted mode.
It has been tested against a local Multigres Docker cluster built from commit 5fa0f2955ede (2026-11-10, PostgreSQL 17.7, two cells) on Linux with Docker Engine. Other setups have not been tested.
Install
Each release has a multigres-mcp-<version>.mcpb file. It is an MCP Bundle: clients that install bundles ask for the settings under "Configuration" and run the server. It is also a zip file whose server/ directory holds binaries for Linux and macOS on amd64 and arm64 and for Windows on amd64, which any other client can run directly.
Related MCP server: postgres-mcp-server
Build
Requires Go 1.26 or later.
git clone https://github.com/JoongHyuk-Shin/multigres-mcp
cd multigres-mcp
go build -o multigres-mcp ./cmd/multigres-mcpThe server talks MCP over standard input and output. ./multigres-mcp --help prints the options.
packaging/build-mcpb.sh builds the release bundle into dist/. It also needs jq, Node.js and openssl.
Configuration
Every option can be given as a flag or as an environment variable. A flag wins over the variable.
Flag | Variable | Default | Meaning |
|
| none, required | Connection string of the Multigres gateway. |
|
| none | multiadmin HTTP address. The cluster tools are registered only when it is set. |
|
| none | Bearer token for multiadmin started with |
|
| none |
|
|
|
|
|
|
|
| Statement timeout for the SQL every tool sends. See "Things to know". |
Direct node connections reuse the user, password and database of --database-url and take the host and port from multiadmin.
In the local Docker cluster both nodes report the host localhost, while their Postgres ports are reachable only at the container's address. Find that address in the Multigres checkout with:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$(docker compose ps -q multigres)"and pass it as --node-host-map localhost=<address>.
Adding it to an MCP client
With Claude Code, for the local Docker cluster (replace 172.18.0.2 with the address found above):
claude mcp add multigres -e DATABASE_URI=postgres://postgres:postgres@localhost:15432/postgres -- /path/to/multigres-mcp --admin-url http://localhost:15000 --node-host-map localhost=172.18.0.2Other clients take the same command, arguments and environment in their server configuration, for example:
{
"mcpServers": {
"multigres": {
"type": "stdio",
"command": "/path/to/multigres-mcp",
"args": ["--admin-url", "http://localhost:15000", "--node-host-map", "localhost=172.18.0.2"],
"env": {
"DATABASE_URI": "postgres://postgres:postgres@localhost:15432/postgres"
}
}
}
}Tools
Tool | Mode | What it does |
| both | List the schemas. The |
| both | List the tables, views or sequences of a schema, or every extension in the database. |
| both | Columns, constraints and indexes of a table or view, or details of a sequence or extension. |
| both | Run one read-only statement ( |
| both | The plan of a query, optionally with |
| both | The slowest or most expensive queries, from |
| both | Index advice for the workload in |
| both | The same for up to 10 given queries. |
| both | Health checks: bloat, vacuum, locks, activity, waits, slow queries, missing indexes, cache, log, index health, sequences, replication and constraints. It starts with the statistics period of the node that answered. |
| both, needs | Cells, databases, the primary and replicas of each shard with LSN and lag, gateways, orchestrators, recent primary changes, and whether the connected user is a superuser. |
| both, needs | Backups of a shard. |
| both, needs | Run pgBackRest |
| both, needs | Status of a backup job. |
| both, needs | The end of a node's Postgres log, read over a direct connection to that node. |
| unrestricted | Run one statement that may change data or schema, committed if it succeeds. |
| unrestricted, needs | Ask Multigres to switch a shard's primary, then report the old and new primary and terms. Multigres may elect the same node again; the tool says so and does not retry. |
| unrestricted, needs | Start a backup and return its job id. |
| unrestricted, needs | Expire backups with the retention rules configured in the cluster. |
| unrestricted, needs | Turn automatic Postgres restarts on a node on or off. |
That is 14 tools in the restricted mode and 19 in the unrestricted mode, or 9 and 10 without --admin-url. diagnose and get_top_queries take an optional node to read one node directly instead of through the gateway, for example the old primary after a failover.
Safety
The restricted mode does not register any tool that can write. Writing SQL is a tool of its own, execute_write_sql, so a client permission given to execute_sql never covers a write, even after the server is restarted in the unrestricted mode.
Every statement that execute_sql, explain_query and analyze_query_indexes receive passes these checks. They do not rely on each other: checks 1, 3 and 4 each stop a write on their own.
It is parsed with the Multigres parser. It must be exactly one statement, the top statement must be
SELECT,EXPLAINof aSELECT, orSHOW, and the tree must not contain data-changing statements,SELECT INTOor locking clauses. Functions must be on an allow list (the postgres-mcp list with functions that have side effects removed), and a schema-qualified function must be inpg_catalog. The Multigres gateway can send the statement rewritten from its parse tree instead of the text it received, so the rewritten statement must pass this check as well.It is sent with the extended query protocol, which carries one statement only.
The read-only connection is opened with
default_transaction_read_only=on.It runs in
BEGIN TRANSACTION READ ONLY, which is always rolled back.search_pathis pinned, and a statement is not sent if it or its rewritten form calls a function that PostgreSQL resolves throughsearch_pathand whose name also exists outsidepg_catalog. The rewritten form calls some built-ins without the prefix, such asbtrimforTRIM(...)and even for a writtenpg_catalog.btrim(...). PostgreSQL also resolves the plain call formsoverlay(a, b, c)andsubstring(a, b, c)throughsearch_path, though the Multigres parser reads them aspg_catalogcalls.A statement timeout is set.
This covers the statements the model sends and the functions they call directly. The bodies of objects already in the database (views, functions, operators, policies) are trusted and not checked. Against a production database, connect as a read-only role as well. cluster_status shows whether the connected user is a superuser.
Multigres hands pooled Postgres connections from one client to the next. Within the same transaction, the server removes the hypothetical indexes and session advisory locks a tool call may have left on its connection. If that cleanup fails, it ends its own Postgres session rather than hand the state on. execute_write_sql rejects transaction control, session-level SET and RESET, multigres.* settings, hypopg functions, and statements that leave session state behind (temporary objects, PREPARE, LISTEN, DECLARE ... WITH HOLD, LOAD, DISCARD, DO). Session settings (set_config(..., false)) and the random seed (setseed) changed inside the body of a function or trigger are not removed and can reach the next client of that connection; like the other object bodies, they are trusted.
Direct node connections run fixed queries only, never SQL from the model.
The multiadmin address (in full and as host:port), the admin token and the database password are removed from tool results and error messages. The removal replaces text, so a password that is a common word is masked wherever that word appears. A password equal to the user or database name is not masked, because results show those names; the server prints a warning when it starts.
Things to know
--sql-timeoutdefaults to 25s because the multipooler ends a transaction's connection when one statement runs past--connpool-user-reserved-inactivity-timeout(default 30s). To use a longer timeout, raise that pooler setting too.The results of
execute_sqlandexecute_write_sqlend with a line naming the settings the server set for that call only (statement_timeout,lock_timeout, and for readssearch_path), and thestatement_timeoutits own session had before. The gateway enforcesstatement_timeoutitself without setting it on the node, so the node'spg_settingsshows 0 for it whileSHOWthrough the gateway answers with the gateway's value.Cumulative statistics are kept per node. After a failover the new primary's statistics do not include what happened on the old primary. The tools that use statistics start with the period they cover; the
nodeoption ofdiagnoseandget_top_queriesreads another node.Index sizes in the advice are hypopg estimates and ignore btree deduplication. On a column with many repeated values the estimate can be several times the real size (on 200,000 rows with 1,000 distinct values: 4,644,864 bytes estimated, 1,384,448 bytes real).
The gateway truncates the query text it keeps to
--query-metrics-sql-max-bytes(default 4096) without a marker. Plans and index advice use the fullpg_stat_statementstext or the full statement you give.get_top_queriesshows the first 2,000 characters of eachpg_stat_statementstext anddiagnosethe first 500, with the full length and thequeryid, so one very long statement cannot fill the 50,000-character result. The result says how to read a longer text withexecute_sqlin pieces of 20,000 characters. The lock check shows the first 500 characters of the waiting and blocking statements. In gateway query statistics,get_top_queriesanddiagnoseshow the first 500 characters of the text each gateway kept, with the gateway's fingerprint to tell apart queries that start alike. The index advisors analyze the full text but list each skipped or costed query by its first 200 characters and full length, plus thequeryidfor workload queries, and show the first 500 characters of a skip reason.VACUUMandCREATE INDEX CONCURRENTLYcannot run in a transaction, soexecute_write_sqlcannot run them.Calls to multiadmin time out after 30 seconds,
verify_backupsafter 10 minutes.If
execute_write_sqlgets no reply to itsCOMMIT, it says it does not know whether the statement was committed. Check the data before sending it again.
Tests
go test ./...runs the unit tests. The integration and end-to-end tests have the build tag cluster and need a local Multigres Docker cluster with pg_stat_statements preloaded and hypopg installed. They switch the primary, drop and recreate the two extensions, and end sessions, so do not point them at a cluster you care about. They fail rather than skip when the cluster cannot be reached.
Start the cluster from a Multigres checkout:
git clone https://github.com/multigres/multigres
cd multigres
git checkout 5fa0f2955ede
MULTIGRES_PG_EXTRA_CONF="shared_preload_libraries = 'pg_stat_statements'" docker compose up -d --buildWait until docker compose ps shows the container as healthy, then install hypopg and create both extensions:
docker compose exec -u root multigres sh -c 'apt-get update -q && apt-get install -y -q --no-install-recommends postgresql-17-hypopg'
docker compose exec -e PGPASSWORD=postgres multigres psql -h localhost -p 15432 -U postgres -d postgres -c 'CREATE EXTENSION pg_stat_statements' -c 'CREATE EXTENSION hypopg'Then, in this repository, with MULTIGRES_MCP_TEST_NODE_HOST set to the container address from the docker inspect command above:
MULTIGRES_MCP_TEST_NODE_HOST=<address> go test -tags cluster -p 1 -count=1 -timeout 25m ./...-p 1 runs one package at a time, because the packages share the cluster's primary, extensions and connection pools. The tests use the gateway at localhost:15432, multiadmin at localhost:15000 and the node ports 25432 and 25433 of the Docker cluster; MULTIGRES_MCP_TEST_GATEWAY_URL and MULTIGRES_MCP_TEST_ADMIN_URL change the first two. test/facts-map.md maps the Multigres behaviour the design relies on to the test that checks it.
License
Apache License 2.0, see LICENSE. Parts adapted from postgres-mcp are under the MIT License, see THIRD_PARTY_NOTICES.md.
Available Tools
9 toolsanalyze_query_indexesARead-onlyIdempotent
Recommend indexes for up to 10 SELECT queries you give, each with weight 1, by the same hypothetical-index search as analyze_workload_indexes, with its 10% rule, max_index_size_mb and 30 second limit. Returns the same parts: CREATE INDEX statements with estimated sizes and costs, skipped queries with reasons, and each query's cost before and after. A query may hold values or $1-style placeholders; one with placeholders is costed with a generic plan. Statements that are not a SELECT are skipped with the reason. Nothing is created. Needs hypopg.
Inputs: queries (required), max_index_size_mb.
analyze_workload_indexesARead-onlyIdempotent
Recommend indexes for this database's workload: the pg_stat_statements queries with at least 50 calls and 5 ms mean time, up to 100 by total time. Candidates are indexes on 1 to 3 columns that the queries filter, join, sort or group on, each tried as a hypothetical index (hypopg) and compared by planner cost. A greedy search adds one at a time while an addition lowers the workload cost by at least 10%, is worth its size and keeps the total within max_index_size_mb; it ends 30 seconds after the analysis starts, keeping what it has chosen by then. Nothing is created. Returns CREATE INDEX statements with estimated sizes and costs, skipped queries with reasons, and each query's cost before and after. Needs pg_stat_statements and hypopg. For queries you choose, use analyze_query_indexes.
Inputs: max_index_size_mb.
diagnoseARead-onlyIdempotent
Run health checks (bloat, vacuum, locks, activity, waits, slow queries, missing indexes, cache, log, index health, sequences, replication, constraints), after the statistics period of the node that answered.
Inputs: node, checks.
execute_sqlARead-onlyIdempotent
Run one read-only SQL statement (SELECT, EXPLAIN of a SELECT, or SHOW) through the Multigres gateway. The statement is checked before it is sent and runs in a read-only transaction that is always rolled back. Functions must be on the allow list.
Inputs: sql (required).
explain_queryARead-onlyIdempotent
Show the execution plan of a SQL query with cost estimates. A query with $1-style placeholders (as in query statistics) is explained with a generic plan. Hypothetical indexes need the hypopg extension.
Inputs: sql (required), analyze, hypothetical_indexes.
get_object_detailsARead-onlyIdempotent
Show the columns (data type, nullability, default), constraints and indexes of a table or view, the data type, start and increment of a sequence, or an extension's version, relocatable flag and schema from pg_extension.extnamespace (schema_name is not used for extension). Read from the system catalogs, so the role's privileges do not hide anything. Use list_objects to find names.
Inputs: object_name (required), schema_name (required), object_type.
get_top_queriesARead-onlyIdempotent
Report the slowest or most resource-intensive queries from pg_stat_statements and from the query statistics each Multigres gateway keeps. The two sources cover different periods and are shown separately.
Inputs: node, limit, source, sort_by.
list_objectsARead-onlyIdempotent
List the tables, views or sequences in one schema, or every extension in the database (schema_name is not used for extension). Rows give the schema, name and type of each table or view, the schema, name and data type of each sequence, or each extension's name, version, relocatable flag and schema from pg_extension.extnamespace. Read from the system catalogs, so the role's privileges do not hide objects. Use list_schemas for schema names and get_object_details for one object.
Inputs: schema_name (required), object_type.
list_schemasARead-onlyIdempotent
List all schemas in the database. The multigres schema is internal to Multigres.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool has a distinct purpose, and the two index-advisor tools are explicitly differentiated (user-supplied SELECTs vs pg_stat_statements workload), with each description pointing to the other. Minor overlaps remain: diagnose reports slow queries/missing indexes that get_top_queries and the analyzers also cover, and execute_sql can run EXPLAIN of a SELECT overlapping explain_query.
Nearly all tools follow a clean verb_noun or verb_resource pattern (list_objects, list_schemas, get_object_details, get_top_queries, analyze_query_indexes, analyze_workload_indexes, execute_sql, explain_query). The lone exception is the bare verb 'diagnose', a minor deviation in an otherwise predictable scheme.
Nine tools is well within the ideal range and each earns its place: discovery (list_schemas, list_objects), inspection (get_object_details, explain_query), querying (execute_sql, get_top_queries), tuning (two analyzers), and health (diagnose). No tool looks redundant or filler.
The read-only inspection/tuning surface is well covered: schema and object discovery, plan explanation, workload and single-query index advice, and health diagnostics form a coherent lifecycle. Gaps are modest—no tool for server/config settings, database-level listing, or table/index statistics—but these are peripheral to the analytical purpose.
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Managed Postgres MCP: projects, SQL, docs search, and storage buckets via OAuth.
Manage Dragonfly Cloud datastores, backups, networks, connections and metrics.
Related MCP Servers
- AlicenseAqualityDmaintenancePostgres Pro is an open source Model Context Protocol (MCP) server built to support you and your AI agents throughout the entire development process—from initial coding, through testing and deployment, and to production tuning and maintenance.93,490MIT
- AlicenseAqualityDmaintenanceProvides PostgreSQL database management and analysis via MCP, enabling schema exploration, query execution, performance monitoring, and database health checks.3640 npmMIT
- FlicenseNot gradedqualityDmaintenanceProvides tools for managing PostgreSQL databases through the Managed DB API, including project creation, table management, migrations, backups, and more.-
- AlicenseAqualityBmaintenanceGoverned PostgreSQL DBA operations — slow-query, bloat, and blocking-lock RCA, index management, vacuum/analyze, and replication lag, with unbypassable audit logging (MCP + CLI), budget/runaway guards, dry-run, and undo/rollback.35MIT