# Postgres MCP server security: what it can access

> The reference Postgres MCP server was archived in 2025. See what replaced it, which modes are read-only and how to limit database access.

The reference Postgres MCP server, `@modelcontextprotocol/server-postgres`, was archived on May 29, 2025. The archive README says archived servers are no longer maintained and points to the active servers repository, without naming a PostgreSQL replacement. It had one tool, `query`, which ran SQL inside a read-only transaction. Current options include Postgres MCP Pro from Crystal DBA and Google’s MCP Toolbox for Databases. The PostgreSQL MCP server you use decides whether an agent can change your data, so check its access mode and the database role behind it.

## What the archived server did

It exposed a single tool, `query`, taking one `sql` string. The source says all queries run in a READ ONLY transaction. You passed a connection URL as a positional argument, such as `postgresql://user:password@host:port/db-name`. The repository sits in `modelcontextprotocol/servers-archived` and is read-only, so it gets no fixes.

## Postgres MCP Pro

Crystal DBA says it creates and maintains this project (crystaldba/postgres-mcp). You set `DATABASE_URI` and choose an access mode with `--access-mode`.

| Mode | Behavior |
| --- | --- |
| `unrestricted` | full read and write access to data and schema, meant for development |
| `restricted` | read-only transactions and an execution time limit, meant for production |

Its tools are `list_schemas`, `list_objects`, `get_object_details`, `execute_sql`, `explain_query`, `get_top_queries`, `analyze_workload_indexes`, `analyze_query_indexes` and `analyze_db_health`. `execute_sql` is the one that matters. Transport is stdio by default, with SSE when you pass `--transport=sse`.

## MCP Toolbox for Databases

Google’s googleapis/mcp-toolbox is an open source MCP server for many databases, with PostgreSQL support. You describe sources and tools in `tools.yaml`. A source has `type: postgres` and connection fields. A tool has `type: postgres-sql` with a fixed `statement`, so the agent can run only the queries you wrote. A prebuilt option, `--prebuilt=postgres`, loads ready-made tools, and the README names `list_tables` and `execute_sql` as examples. It documents no read-only switch, so the database role has to do that job.

## The risks

SQL is a write language. A read-only transaction blocks writes from that connection, but a connection with a broad role is one setting away from changing data. Rows can contain text written by users, and that text can carry instructions to the agent. Query results go to your model provider. A connection string with a password in your MCP config or in a command argument is a secret sitting in a file.

## Make the database enforce it

The agent’s limit should live in Postgres, not in the prompt.

- Create a role that can only `SELECT` the tables you want.
- Point it at a read replica or a copy when you can.
- Pick `restricted` mode in Postgres MCP Pro.
- With Toolbox, write fixed statements instead of free SQL.

See [Keeping keys and your email out of agent logs](https://www.excellent.so/guides/keep-keys-and-email-out-of-agent-logs) for passwords that end up in logs.

## Limit it in Claude Code

Rules use `mcp__<server>__<tool>`. Here the server is named `postgres`.

```json
{
  "permissions": {
    "ask": ["mcp__postgres__execute_sql"],
    "allow": ["mcp__postgres__list_schemas", "mcp__postgres__get_object_details"]
  }
}
```

Add it with `claude mcp add --env DATABASE_URI=... postgres -- uvx postgres-mcp --access-mode=restricted`. The README also shows Docker and `pipx` installs.

## Limit it in Codex

```toml
[mcp_servers.postgres]
command = "uvx"
args = ["postgres-mcp", "--access-mode=restricted"]
env_vars = ["DATABASE_URI"]
disabled_tools = ["analyze_workload_indexes"]
```

`env_vars` forwards `DATABASE_URI` from your shell. Use `enabled_tools` instead if you prefer a short allow list.

## Checklist

- Replace the archived server if you still run it.
- Use a least-privilege role and a replica.
- Choose restricted mode.
- Keep the connection string out of the repository.

Checked against the vendor documentation on November 25, 2026. [servers-archived](https://github.com/modelcontextprotocol/servers-archived) · [Postgres MCP Pro](https://github.com/crystaldba/postgres-mcp) · [MCP Toolbox](https://github.com/googleapis/mcp-toolbox) · [Claude Code permissions](https://code.claude.com/docs/en/permissions) · [Codex MCP](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)

## What Excellent covers

Excellent doesn’t inspect MCP servers themselves, so it can’t tell you what a server exposes. Its free scan reads supported logs on the Mac and reports findings for review. It reads the session logs of Claude Code, Codex, Grok Build, GitHub Copilot CLI, Gemini CLI and Qwen Code, which shows what an agent did after it used a server. For a local report without installing an app, [run the free scan](https://www.excellent.so/scan). Its script uses Python 3.9 or later when your Mac has it and the shell when it doesn’t, reads the logs locally and makes no network requests. [See a sample report](https://www.excellent.so/r/sample).

Excellent Pro adds checks before supported actions. Claude Code can display an ask prompt. With Codex, an Excellent “ask” refuses the action and tells the agent to ask you. Commands sent into an already running Codex shell fall outside that check. [Agent coverage](https://www.excellent.so/agents) · [Pricing](https://www.excellent.so/pricing). Pro is US-only for now.

Source: https://www.excellent.so/guides/postgres-mcp-server
