# Database MCP Postgres

> Database MCP Postgres is an open-source MCP server for databases. PostgreSQL MCP server that starts read-only, with row caps and statement timeouts. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted
- **Repository:** https://github.com/arifulislamat/database-mcp
- **MCP Registry name:** io.github.arifulislamat/database-mcp-postgres
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-11-23

## About

This PostgreSQL build reads POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD (or a POSTGRES_PASSWORD_FILE) and POSTGRES_DATABASE; the README also mentions a DATABASE_URL form. All of it is set at launch, never through the chat, and the registry recommends a read-only database role.

An assistant gets two tools. search_objects discloses the schema progressively, so the model only loads detail it asks for, and execute_sql runs queries inside a session-level read-only transaction behind a conservative SQL guard, with a default cap of 1000 rows and a 30-second timeout.

It is the Postgres member of a family that also covers SQLite, libSQL, MySQL and MariaDB, published to npm, PyPI and crates.io under the MIT licence.

## Features

- **Postgres connection:** Reads POSTGRES_* variables or DATABASE_URL.
- **Two-tool design:** Only execute_sql and search_objects to save context.
- **Read-only session:** Combines a SQL guard with a database-side read-only setting.
- **Limits:** 1000 rows and 30 seconds by default.
- **Config flexibility:** Flags, YAML config file or environment variables.
- **Rust option:** A native binary can be installed with cargo as database-mcp-rs-postgres.

## Good for

- Explore an unfamiliar Postgres schema through an assistant
- Run read-only analytics queries on staging
- Document tables, indexes and foreign keys
- Debug a slow query with schema context

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add database-mcp-postgres --env POSTGRES_HOST='<POSTGRES_HOST>' --env POSTGRES_USER='<POSTGRES_USER>' --env POSTGRES_PASSWORD='<POSTGRES_PASSWORD>' --env POSTGRES_DATABASE='<POSTGRES_DATABASE>' -- npx -y @database-mcp/postgres
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

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

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add database-mcp-postgres --env POSTGRES_HOST='<POSTGRES_HOST>' --env POSTGRES_USER='<POSTGRES_USER>' --env POSTGRES_PASSWORD='<POSTGRES_PASSWORD>' --env POSTGRES_DATABASE='<POSTGRES_DATABASE>' -- npx -y @database-mcp/postgres
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.database-mcp-postgres]
command = "npx"
args = ["-y", "@database-mcp/postgres"]
env = { POSTGRES_HOST = "<POSTGRES_HOST>", POSTGRES_USER = "<POSTGRES_USER>", POSTGRES_PASSWORD = "<POSTGRES_PASSWORD>", POSTGRES_DATABASE = "<POSTGRES_DATABASE>" }
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e POSTGRES_HOST='<POSTGRES_HOST>' -e POSTGRES_USER='<POSTGRES_USER>' -e POSTGRES_PASSWORD='<POSTGRES_PASSWORD>' -e POSTGRES_DATABASE='<POSTGRES_DATABASE>' database-mcp-postgres npx -- -y @database-mcp/postgres

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "database-mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@database-mcp/postgres"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_USER": "<POSTGRES_USER>",
        "POSTGRES_PASSWORD": "<POSTGRES_PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES_DATABASE>"
      }
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 1 of 2 tools changes data. From the server's own tool labels and tool names; not verified by us.

- `execute_sql` (name suggests: changes): Run SQL against the database, read-only by default.
- `search_objects` (name suggests: reads): List tables, or show columns, indexes and foreign keys for a table.

## FAQ

### Can I use a connection URL?

The README lists DATABASE_URL alongside POSTGRES_* variables.

### Is write access possible?

Read-only is the default, enforced in two layers.

### What are the defaults for limits?

1000 rows and a 30 second statement timeout.

### How is Database MCP Postgres installed?

With npx @database-mcp/postgres, uvx database-mcp-postgres or cargo install database-mcp-rs-postgres.

### Is Database MCP Postgres free?

Yes. Database MCP Postgres is open source, so you can use and self-host it for free.

### How do I add Database MCP Postgres to Claude Code?

Run this command in your terminal: claude mcp add database-mcp-postgres --env POSTGRES_HOST='<POSTGRES_HOST>' --env POSTGRES_USER='<POSTGRES_USER>' --env POSTGRES_PASSWORD='<POSTGRES_PASSWORD>' --env POSTGRES_DATABASE='<POSTGRES_DATABASE>' -- npx -y @database-mcp/postgres

### What are the best alternatives to Database MCP Postgres?

The closest alternatives to Database MCP Postgres are Midplane, Datatomcp, Gulliver, GaussDB Read-Only MCP and Zektor.

## Where this comes from

- Description: written from the project's README.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [Midplane](https://ai-powered.com/mcp/midplane): Midplane is an open-source MCP server for databases.
- [Datatomcp](https://ai-powered.com/mcp/datatomcp-2): Datatomcp is a freemium MCP server for analytics and data.
- [Gulliver](https://ai-powered.com/mcp/gulliver): Gulliver is an open-source MCP server for databases.
- [GaussDB Read-Only MCP](https://ai-powered.com/mcp/gaussdb-read-only-mcp): GaussDB Read-Only MCP is an open-source MCP server for databases.
- [Zektor](https://ai-powered.com/mcp/zektor): Zektor is a freemium MCP server for databases.
- [Sqlite Graph MCP](https://ai-powered.com/mcp/sqlite-graph-mcp): Sqlite Graph MCP is an MCP server for databases.
- [Trino](https://ai-powered.com/mcp/trino-2): Trino is an open-source MCP server for databases.
- [APoint MS SQL](https://ai-powered.com/mcp/apoint-ms-sql): APoint MS SQL is a free MCP server for databases.

---
Source: https://ai-powered.com/mcp/database-mcp-postgres
