Database MCP Postgres
PostgreSQL MCP server that starts read-only, with row caps and statement timeouts
Database MCP Postgres is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, Self-hosted
- Runs
- Locally
- What it can do
- Can change data (1 tool)
- Version
- 0.5.0
Similar MCP servers
Install
Add with the CLI
Run in a 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/postgresAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.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>"
}
}
}
}Add to claude_desktop_config.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.
Add to ~/.cursor/mcp.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.
Add to ~/.copilot/mcp-config.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.
Add with the CLI
Run in a terminal
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/postgresOr add to config.toml
Add to ~/.codex/config.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>" }Add to your client's MCP settings (most use this shape)
{
"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>"
}
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.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
Antigravity
Add to ~/.gemini/config/mcp_config.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 (formerly Windsurf)
Add to ~/.config/devin/mcp_config.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
Add to cline_mcp_settings.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
Add to Zed settings.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
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "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.
Junie
Add to ~/.junie/mcp/mcp.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
Add to ~/.kiro/settings/mcp.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.
Using several servers? Build one config file with the MCP config generator.
Configuration
POSTGRES_HOSTDatabase hostRequiredPOSTGRES_USERDatabase user (a read-only user is recommended)RequiredPOSTGRES_PASSWORDDatabase password (or use POSTGRES_PASSWORD_FILE)POSTGRES_DATABASEDatabase nameRequiredPOSTGRES_HOSTDatabase hostRequiredPOSTGRES_USERDatabase user (a read-only user is recommended)RequiredPOSTGRES_PASSWORDDatabase password (or use POSTGRES_PASSWORD_FILE)POSTGRES_DATABASEDatabase nameRequiredPOSTGRES_HOSTDatabase hostRequiredPOSTGRES_USERDatabase user (a read-only user is recommended)RequiredPOSTGRES_PASSWORDDatabase password (or use POSTGRES_PASSWORD_FILE)POSTGRES_DATABASEDatabase nameRequired
About Database MCP Postgres
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.
Tools this server provides (2)
Taken from the project documentation; the running server may differ.
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_sqlName suggests: changes
- Run SQL against the database, read-only by default.
- search_objectsName suggests: reads
- List tables, or show columns, indexes and foreign keys for a table.
What it does
- 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
Pricing
Open source
MIT licensed
More servers for the same service
Database MCP Postgres 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.