# PostgreSQL MCP server

> Lets an AI client access, query, and manage PostgreSQL databases through tools for schema inspection and SQL execution.

- Repository: https://github.com/kristofer84/mcp-postgres
- Page: https://hostedmcp.org/servers/kristofer84/mcp-postgres
- Transport: stdio
- Stars: 4
- License: MIT

## Install

### Claude Code

```sh
claude mcp add mcp-postgres -- npx -y mcp-postgres
```

### Cursor (`~/.cursor/mcp.json`)

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres"
      ]
    }
  }
}
```

### VS Code (`.vscode/mcp.json`)

```json
{
  "servers": {
    "mcp-postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres"
      ]
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"mcp-postgres","type":"stdio","command":"npx","args":["-y","mcp-postgres"]}'
```

### Claude Desktop (`claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres"
      ]
    }
  }
}
```

### Codex

```sh
codex mcp add mcp-postgres -- npx -y mcp-postgres
```

### Codex config.toml (`~/.codex/config.toml`)

```toml
[mcp_servers.mcp-postgres]
command = "npx"
args = ["-y", "mcp-postgres"]
```

### Gemini CLI

```sh
gemini mcp add -s user mcp-postgres npx -- -y mcp-postgres
```

### Gemini settings.json (`~/.gemini/settings.json`)

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres"
      ]
    }
  }
}
```

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `DATABASE_URL` | no | no |  |
| `DB_HOST` | no | no |  |
| `DB_NAME` | no | no |  |
| `DB_PASSWORD` | no | no |  |
| `DB_PORT` | no | no |  |
| `DB_READ_ONLY` | no | no |  |
| `DB_SSL_MODE` | no | no |  |
| `DB_STATEMENT_TIMEOUT` | no | no |  |
| `DB_USER` | no | no |  |
| `POSTGRES_DB` | no | no |  |
| `POSTGRES_HOST` | no | no |  |
| `POSTGRES_PASSWORD` | no | no |  |
| `POSTGRES_PORT` | no | no |  |
| `POSTGRES_SSL_MODE` | no | no |  |
| `POSTGRES_USER` | no | no |  |

## FAQ

### How can I connect to an AWS RDS instance?

The server automatically detects AWS RDS endpoints, downloads the necessary Global Certificate Bundle, and configures SSL with proper validation.

### Can I restrict the server to read-only access?

Yes, by setting the DB_READ_ONLY environment variable to true, all write and DDL tools are hidden and rejected at the server level.

### What are the requirements to run this server?

You need Node.js version 22 or newer installed on your system.
