Postgres MCP Pro tools: what restricted mode really stops, and how to make your agent ask

All 9 tools of Postgres MCP Pro (postgres-mcp 0.3.0), checked by running it against a real database in both access modes: what restricted mode refuses, why explain_query and analyze_query_indexes deleted rows in unrestricted mode, and the Claude Code settings that make the rest ask.

Checked on by running postgres-mcp 0.3.0 (Docker image crystaldba/postgres-mcp) from crystaldba/postgres-mcp and reading its tools/list answer. Each tier is the tool risk checker’s reading, with our reason wherever we changed it. Written by the people who make VariantGate.

The short answer

Run it with --access-mode=restricted and a role that can only read the tables it needs. 6 of its 9 tools can then run on their own, and analyze_query_indexes too, on that server only. execute_sql and explain_query ask, because restricted mode trusts the role for everything it does not parse.

Can run on their own
6
Should ask a person
3

Which Postgres server this is

This page is about Postgres MCP Pro from Crystal DBA, published as postgres-mcp. The reference Postgres server from the MCP project has been archived and is no longer maintained. Postgres MCP Pro offers the same nine tools in both of its access modes; what changes is what execute_sql, explain_query and analyze_query_indexes will run. Its last release, 0.3.0, is from May 2025, and installing it with today’s Python packages failed for us, so we ran its Docker image.

Two tools that plan queries deleted rows

explain_query has an analyze option, and EXPLAIN ANALYZE in Postgres runs the statement to time it. In unrestricted mode we asked it to explain DELETE FROM orders WHERE id = 1 with analyze on. It returned a plan, and the row was gone. An agent asked to “check why this delete is slow” can do the delete. In restricted mode the same call, and even an analyzed SELECT 1, was refused.

analyze_query_indexes takes a list of queries and recommends indexes for them. It checks only that each one starts with a SELECT, not what follows. We gave it select * from orders where total > 5; delete from orders where id = 1: in unrestricted mode it returned “No index recommendations found”, and the row was gone. Restricted mode refused the same call.

What restricted mode stopped, and what it did not

Restricted mode parses each statement and runs it in a read-only transaction. Against a test database it refused everything we tried that writes:

  • DELETE, and SELECT 1; COMMIT; DELETE … to escape the transaction.
  • set_config to turn the read-only flag off, nextval on a sequence, and pg_terminate_backend on another session.

It did run SELECT * FROM pg_read_file('/etc/passwd'), and returned the file, because we had connected as a superuser. The mode stops writes; what can be read is up to the role. Refusals also came back as ordinary answers starting with “Error:” rather than as failed calls, so check the text, not the status.

Give it a role that can only read

CREATE ROLE agent LOGIN PASSWORD '…';
GRANT CONNECT ON DATABASE app TO agent;
GRANT USAGE ON SCHEMA public TO agent;
GRANT SELECT ON orders, customers TO agent;
-- for get_top_queries
GRANT pg_read_all_stats TO agent;
claude mcp add postgres -e DATABASE_URI=postgresql://agent@db.internal:5432/app -- docker run -i --rm -e DATABASE_URI crystaldba/postgres-mcp --access-mode=restricted

With a role like this, the database refuses what the server lets through, in either mode. One caution: pg_read_all_stats shows the text of every role’s queries, and pg_stat_statements keeps commands such as ALTER ROLE … PASSWORD word for word, so leave it out if you would rather the model never sees them. Keep production on restricted mode anyway: it is what stops explain_query and analyze_query_indexes from running a statement.

All 9 tools

Hard to undo3 toolsAsk a person every time. Consider two people, or deny it if the agent never needs it.

  • explain_query

    Explains the execution plan for a SQL query, showing how the database will execute it and provides detailed cost estimates.

    Server gives no read-only or destructive hint

    Our call: Sounds like a read, but with analyze set it runs the statement: in unrestricted mode, explaining a DELETE deleted the row. Restricted mode refuses analyze.

  • analyze_query_indexes

    Analyze a list of (up to 10) SQL queries and recommend optimal indexes

    Server gives no read-only or destructive hint

    Our call: Plans the queries it is given, but checks only the first statement. In unrestricted mode we gave it a SELECT followed by a DELETE, and the row was deleted. Restricted mode refused it.

  • execute_sql

    Execute any SQL query

    Server gives no read-only or destructive hint

    Our call: Unrestricted, it runs any SQL. Restricted, it refused every write we tried, but it still read /etc/passwd through pg_read_file, because the role it signed in as could.

Only looks6 toolsLet it run. It only looks.

  • list_schemas

    List all schemas in the database

    Server gives no read-only or destructive hint

    Our call: Only reads the catalogue or statistics views, with SQL the server writes itself. The server gives no hints, so we read its code.

  • list_objects

    List objects in a schema

    Server gives no read-only or destructive hint

    Our call: Only reads the catalogue or statistics views, with SQL the server writes itself. The server gives no hints, so we read its code.

  • get_object_details

    Show detailed information about a database object

    Server gives no read-only or destructive hint

    Our call: Only reads the catalogue or statistics views, with SQL the server writes itself. The server gives no hints, so we read its code.

  • analyze_workload_indexes

    Analyze frequently executed queries in the database and recommend optimal indexes

    Server gives no read-only or destructive hint

    Our call: Recommends indexes for the slowest queries in pg_stat_statements, planning each one against hypothetical indexes (hypopg) that last only for the session. It never runs them.

  • analyze_db_health

    Analyzes database health.

    Server gives no read-only or destructive hint

    Our call: Only reads the catalogue or statistics views, with SQL the server writes itself. The server gives no hints, so we read its code.

  • get_top_queries

    Reports the slowest or most resource-intensive queries using data from the 'pg_stat_statements' extension.

    Server gives no read-only or destructive hint

    Our call: Only reads the catalogue or statistics views, with SQL the server writes itself. The server gives no hints, so we read its code.

Let the reads run in Claude Code

Claude Code asks before every MCP tool it has no rule for. Added as postgres, this server’s tools are named mcp__postgres__<tool>. These allow rules, in .claude/settings.json or ~/.claude/settings.json, let the tools that only look run without a prompt. Everything else keeps asking, including any tool a later version of the server adds.

{
  "permissions": {
    "allow": [
      "mcp__postgres__list_schemas",
      "mcp__postgres__list_objects",
      "mcp__postgres__get_object_details",
      "mcp__postgres__analyze_workload_indexes",
      "mcp__postgres__analyze_db_health",
      "mcp__postgres__get_top_queries"
    ]
  }
}

The command that adds the server:

claude mcp add postgres -e DATABASE_URI=postgresql://agent@db.internal:5432/app -- docker run -i --rm -e DATABASE_URI crystaldba/postgres-mcp --access-mode=restricted

Send the rest to a person, not the terminal

A prompt in the terminal only works while someone is watching it. With this hook, every other tool of the server becomes a request in your VariantGate inbox, on your phone or in Slack, and Claude Code waits for the answer. The matcher names the look-only tools, so a tool added later is sent too. Put the key in VARIANTGATE_KEY, or run the one-command setup for Claude Code first.

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "mcp__postgres__(?!(list_schemas|list_objects|get_object_details|analyze_workload_indexes|analyze_db_health|get_top_queries)$).*",
        "hooks": [
          { "type": "command", "command": "variantgate hook claude-code", "timeout": 180 }
        ]
      }
    ]
  }
}

Disagree with a tier, or run the server with other flags? Open these tools in the tool risk checker, change what you like, and copy the settings for your own setup. It runs in your browser and starts from its own reading, so a tool we marked as only looking by hand asks there until you change it.

Any MCP client: put the proxy in front

Claude Desktop, Cursor and most other MCP clients have no hook to send a call to a person. The VariantGate MCP proxy does it in the server’s place: it starts the server, lets the look-only tools above through, and holds every other call until someone approves it in the inbox. Run npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz login once to save a key, then use this in claude_desktop_config.json or ~/.cursor/mcp.json:

{
  "mcpServers": {
    "postgres": {
      "args": [
        "-y",
        "https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz",
        "mcp-proxy",
        "--name",
        "postgres",
        "--look-only",
        "list_schemas,list_objects,get_object_details,analyze_workload_indexes,analyze_db_health,get_top_queries",
        "--",
        "docker",
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "crystaldba/postgres-mcp",
        "--access-mode=restricted"
      ],
      "command": "npx",
      "env": {
        "DATABASE_URI": "postgresql://agent@db.internal:5432/app"
      }
    }
  }
}

Already have it in Claude Desktop? One command rewrites the file for you, with these look-only tools filled in, and keeps the old one (setup vscode does the same for VS Code; how it works):

npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz setup claude-desktop

The same in Claude Code, instead of the hook. The proxy now asks about every call that matters, so an allow rule for the whole server, mcp__postgres, keeps Claude Code from asking a second time in the terminal:

claude mcp add postgres -e DATABASE_URI=postgresql://agent@db.internal:5432/app -- npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz mcp-proxy --name postgres --look-only list_schemas,list_objects,get_object_details,analyze_workload_indexes,analyze_db_health,get_top_queries -- docker run -i --rm -e DATABASE_URI crystaldba/postgres-mcp --access-mode=restricted

Claude Code’s allow rules match a tool’s name, never its arguments, so a rule cannot tell a harmless call of these tools from a risky one. On a server started with --access-mode=restricted, and only there, these rules also let analyze_query_indexes run unasked:

{
  "permissions": {
    "allow": [
      "mcp__postgres__list_schemas",
      "mcp__postgres__list_objects",
      "mcp__postgres__get_object_details",
      "mcp__postgres__analyze_workload_indexes",
      "mcp__postgres__analyze_db_health",
      "mcp__postgres__get_top_queries",
      "mcp__postgres__analyze_query_indexes"
    ]
  }
}

When the agent should write

Some agents need to fix data, not just read it. Then run a second server, unrestricted, with a role that can write only the tables it needs, and give it its own name, such as postgres-write, so the allow rules above, written for mcp__postgres__, do not cover it. Every tool of that server should ask. The person who answers sees the SQL itself, so an unexpected WHERE clause, or the lack of one, is caught before it runs.

See it before you decide.

The playground runs the whole approval loop in your browser, no account needed. When it fits, the free plan covers 100 requests a month.