# PostgreSQL MCP server

> Enables AI agents to interact with PostgreSQL databases using specialized tools, schema introspection, and a secure V8 isolate for complex operations.

- Repository: https://github.com/neverinfamous/postgresql-mcp
- Page: https://hostedmcp.org/servers/neverinfamous/postgresql-mcp
- Transport: stdio
- Stars: 12
- License: MIT
- Latest version: 1.0.2

## Install

### Claude Code

```sh
claude mcp add postgresql-mcp -- npx -y @neverinfamous/postgres-mcp
```

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

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

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

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

### VS Code CLI

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

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

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

### Codex

```sh
codex mcp add postgresql-mcp -- npx -y @neverinfamous/postgres-mcp
```

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

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

### Gemini CLI

```sh
gemini mcp add -s user postgresql-mcp npx -- -y @neverinfamous/postgres-mcp
```

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

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

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `MCP_AUTH_TOKEN` | no | no |  |
| `POSTGRES_DATABASE` | no | no |  |
| `POSTGRES_HOST` | no | no |  |
| `POSTGRES_PASSWORD` | no | no |  |
| `POSTGRES_PORT` | no | no |  |
| `POSTGRES_USER` | no | no |  |

## Tools (25)

- `codemode`
- `core`
- `transactions`
- `jsonb`
- `text`
- `performance`
- `admin`
- `monitoring`
- `backup`
- `schema`
- `introspection`
- `migration`
- `partitioning`
- `stats`
- `vector`
- `postgis`
- `cron`
- `partman`
- `kcache`
- `citext`
- `ltree`
- `pgcrypto`
- `security`
- `roles`
- `docstore`

## FAQ

### How can I reduce token usage when using this server?

You can use 'Code Mode', which executes complex operations inside a secure V8 isolate to reduce AI overhead by up to 90%.

### What PostgreSQL extensions are supported?

The server provides first-class API support for extensions including pgvector, PostGIS, pg_cron, pgcrypto, citext, ltree, pg_stat_kcache, and HypoPG.

### Can I limit which tools my AI agent has access to?

Yes, you can use the `--tool-filter` argument to dynamically compile the server with specific tool groups or individual tool names.
