---
title: "PostgreSQL MCP Server Setup Guide and Schema"
slug: "postgres"
category: "databases"
package: "@modelcontextprotocol/server-postgres"
transport: "stdio"
canonical: "https://mcp-codex.com/servers/postgres"
source: "MCP Codex (https://mcp-codex.com)"
dateModified: "2026-09-28"
---

# PostgreSQL MCP Server

> Query, inspect schemas, and explore PostgreSQL databases with read-only safety.

## Overview
Enable your AI agent to inspect PostgreSQL database schemas, query tables, list indexes, and explore relationships with read-only access by default. The official PostgreSQL MCP server exposes database metadata as MCP resources and provides a safe query execution tool.

## Quick Install
```bash
npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost:5432/mydb
```

## Client Configurations

### Claude Desktop (`claude_desktop_config.json`)
```json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:pass@localhost:5432/mydb"
      ]
    }
  }
}
```

### Cursor (`mcp.json`)
```json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:pass@localhost:5432/mydb"
      ]
    }
  }
}
```

### OpenAI Codex CLI (`~/.codex/config.toml`)
```toml
[mcp_servers.postgres]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost:5432/mydb"]
```

## Available Tools (1)

- `query`

## Exposed Resources

- `postgres://schemas`
- `postgres://tables`

## Documentation & Links
- Canonical Web Page: https://mcp-codex.com/servers/postgres
- Weekly Protocol Changelog: https://mcp-codex.com#newsletter
- GitHub Repository: https://github.com/modelcontextprotocol/servers/tree/main/src/postgres
- Setup Tutorial Guide: https://mcp-codex.com/articles/postgresql-mcp-server-setup

