> ## Documentation Index
> Fetch the complete documentation index at: https://midplane.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Claude Code to Postgres over MCP

> Add the gateway to Claude Code, sign in, and choose which Postgres databases it may read or write.

[Midplane](https://midplane.ai/docs/index.md) is a gateway between AI agents and your Postgres databases.
Claude Code queries your data through it, never holds a connection string, and
every statement it sends is checked against your policy before it runs.

You need a running gateway ([get started](https://midplane.ai/docs/get-started.md)). Its URL is on the
project's **Agents** page, under **Connect an agent**.

**1. Add the gateway**

```sh theme={null}
claude mcp add --transport http midplane <gateway URL>
```

**2. Sign in**

Start `claude`, run `/mcp`, pick `midplane` and choose **Authenticate**.

**3. Choose what it may reach**

Set each database to **None**, **Read** or **Read + write**, and **Allow**.

**4. Try it**

Ask Claude Code which tables it can see. Its statement shows up in the
project's **Query log**.

> [!TIP]
>
> You're set: Claude Code can answer questions from your data, and only what your
> policy allows runs. Masked columns stay masked, writes that need approval
> wait for a person, and every statement is in the audit log.

> [!WARNING]
>
> Claude Code runs commands as you. If the gateway runs as you too, Claude Code
> can read its connection strings and reach the database without it. Run the
> gateway as another user or on another host ([deploy the
> gateway](https://midplane.ai/docs/gateway/deploy.md)).

To cut it off, **Revoke** it under **Connected agents** on the **Agents** page.
It has to sign in again within 15 minutes.

> **Use a token instead of signing in**
>
> For scripts, or a gateway in [local mode](https://midplane.ai/docs/gateway/local-mode.md), send a token
> from **Tokens for scripts** on the **Agents** page, or from `midplane token`
> in local mode:
>
> ```sh theme={null}
> claude mcp add --transport http midplane <gateway URL> \
>   --header "Authorization: Bearer $(cat token.txt)"
> ```

## If it doesn't work

* **The consent page says it wants access, with no databases**: you aren't a
  member of the gateway's project, or the gateway isn't registered. Ask an
  owner of the organization.
* **The `localhost` URL does not resolve**: see
  [troubleshooting](https://midplane.ai/docs/troubleshooting.md#the-localhost-url-does-not-resolve).

*Tested by* `apps/gateway/test/auth.test.ts` for the gateway's side; the
client's steps by hand.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.