# PostgreSQL MCP server

> Lets AI coding agents query, modify, and inspect PostgreSQL databases, manage connection profiles, and diagnose performance.

- Repository: https://github.com/microsoft/postgres-mcp
- Page: https://hostedmcp.org/servers/microsoft/postgres-mcp
- Official: yes
- Transport: stdio
- Stars: 86
- License: MIT

## Install

### Claude Code

```sh
claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcp
```

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

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

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

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

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

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

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

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

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

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

## FAQ

### How do I connect postgres-mcp to Claude Code or GitHub Copilot?

Add a stdio entry pointing at `npx @microsoft/postgres-mcp run` in your client's mcpServers config; no credentials go in that config.

### Where is the database password stored?

Passwords are saved in the OS keyring with `connection set-password`, not in a config file.

### Is the query tool read-only?

Yes, postgres_mcp_query is read-only, but write tools are available unless the profile sets access_mode to ro.

### Can I use it without saving a profile, e.g. in CI?

Yes, the server can take a database connection string from the environment when no keyring is available.

### What Node.js version does it require?

Node.js 22 or newer is required to run it via npx.
