Postgres MCP logo

Postgres MCP

Connects AI agents to PostgreSQL with runtime .env credentials, explicit tool selection, and read-only defaults.

Install Postgres MCP

Pick your client, then add it in one click or paste the config.

STDIONode.js
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@edelciomolina/postgres-mcp"
      ],
      "env": {
        "MCP_KEY_URL": "YOUR_VALUE_HERE",
        "MCP_KEY_HOST": "YOUR_VALUE_HERE",
        "MCP_KEY_PORT": "YOUR_VALUE_HERE",
        "MCP_KEY_NAME": "YOUR_VALUE_HERE",
        "MCP_KEY_SSLMODE": "YOUR_VALUE_HERE",
        "MCP_KEY_USER": "YOUR_VALUE_HERE",
        "MCP_KEY_PASS": "YOUR_VALUE_HERE",
        "POSTGRES_MCP_ALLOW_WRITE": "YOUR_VALUE_HERE"
      }
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Values are written into the snippet above so you can paste it as is. They never leave your browser.

Claude Code command
claude mcp add --env MCP_KEY_URL=YOUR_VALUE_HERE --env MCP_KEY_HOST=YOUR_VALUE_HERE --env MCP_KEY_PORT=YOUR_VALUE_HERE --env MCP_KEY_NAME=YOUR_VALUE_HERE --env MCP_KEY_SSLMODE=YOUR_VALUE_HERE --env MCP_KEY_USER=YOUR_VALUE_HERE --env MCP_KEY_PASS=YOUR_VALUE_HERE --env POSTGRES_MCP_ALLOW_WRITE=YOUR_VALUE_HERE --transport stdio postgres-mcp -- npx -y @edelciomolina/postgres-mcp

Run in your terminal. Add --scope project to share it with your team through .mcp.json.

We couldn’t confirm it starts correctly

We hit an unexpected error while testing this listing automatically.

npx -y @edelciomolina/postgres-mcp

Rate limit exceeded, please try again later - you have reached the maximum number of concurrent E2B sandboxes (20). If you need more, please visit 'https://e2b.dev/docs/billing'

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

The postgres-mcp MCP server exposes PostgreSQL inspection, querying, analysis, and monitoring tools through the Model Context Protocol. It reads credentials from a project .env file at runtime, using configurable mappings or a full connection URL, so secrets do not need to be placed in mcp.json. Read-only tools are enabled by default, while write-capable tools require explicit tool arguments and an opt-in environment setting. Reach for it when an agent needs structured knowledge of a PostgreSQL schema or controlled database access.

Use cases

  • Inspect a PostgreSQL schema before generating queries
  • Analyze database structure and inferred relationships
  • Run read-only database queries through an MCP client
  • Check query risk before execution
  • Opt into selected schema or index management tools

Key features

  • Runtime .env credential resolution
  • Connection URL or individual credential mapping
  • Read-only tools enabled by default
  • Explicit tool selection with tool arguments
  • PostgreSQL schema and relationship inspection
  • Query risk classification

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

15/15 checks healthy over the last 78d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 9d ago via OSV.dev · @edelciomolina/postgres-mcp (npm)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars5Stargazers on the source repository.
npm downloads565Package downloads in the last 30 days.
Last commit5mo agoMost recent push to the default branch.
Install checkInconclusiveWe hit an unexpected error running the automated check.

How Postgres MCP works

What postgres-mcp does

The postgres-mcp MCP server connects an MCP client to PostgreSQL through a native server built with the Model Context Protocol SDK and the pg package. It gives an agent structured access to database information instead of requiring the agent to guess table names, columns, or relationships.

The server can expose schema metadata, query and database analysis functions, monitoring and debugging operations, and a database graph containing relationships inferred from the live schema. It also provides semantic descriptions of tables and a query-risk classification capability. These features are intended to help an agent understand the database before retrieving or changing data.

How it works

At startup, the server resolves PostgreSQL credentials from a .env file somewhere in the project tree. The MCP configuration maps names such as MCP_KEY_HOST or MCP_KEY_PASS to the variable names that actually hold the values in .env. This allows an existing environment file to use its own naming convention.

A full connection string can be selected with MCP_KEY_URL. When that mapping resolves to a present URL, it takes precedence over the individual host, port, database, SSL mode, user, and password settings.

Tool exposure is controlled through separate tool=<name> command-line arguments. With no tool arguments, the server starts with its curated read-only set. This keeps modification and schema-definition operations unavailable unless they are deliberately configured.

Setup and configuration

The postgres-mcp MCP server requires Node.js 18 or newer and a .env file containing PostgreSQL connection information. It can be launched with npx -y @edelciomolina/postgres-mcp as a stdio server, or installed through the VS Code MCP interface. In VS Code, the server entry belongs in mcp.json and can be edited after installation.

For individual connection fields, map MCP_KEY_HOST, MCP_KEY_PORT, MCP_KEY_NAME, MCP_KEY_SSLMODE, MCP_KEY_USER, and MCP_KEY_PASS to the corresponding .env variables. For platforms that provide a connection string, map MCP_KEY_URL instead.

Tools and capabilities

The documented default read-only tools include:

  • pg_execute_query and pg_manage_query for query-related operations
  • pg_inspect_schema for schema inspection
  • pg_analyze_database for database analysis
  • pg_monitor_database and pg_debug_database for operational investigation
  • pg_inspect_database_graph for schema relationships
  • pg_describe_table_semantics for table meaning and context
  • pg_get_setup_instructions for setup guidance

pg_classify_query_risk can assess query safety before execution. Write-capable examples include pg_manage_schema and pg_manage_indexes; these are not enabled by default.

Limitations and notes

Write-capable tools require POSTGRES_MCP_ALLOW_WRITE=true in the MCP environment. If write tools are requested without that setting, the server exits during startup. Read-only mode does not expose writes, DDL, or arbitrary SQL by default.

The credentials in the examples are stored in .env, while mcp.json contains mappings to variable names rather than the secret values. The server uses the URL configuration in preference to separate credential fields when both are available. Tool selection is explicit in the MCP launch arguments, so changing the exposed tool set requires editing that configuration.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Postgres MCP

postgres-mcp is an MCP server that connects AI clients to PostgreSQL using credentials from a .env file or connection URL. Its main tools support query execution and management, schema inspection, database analysis, monitoring, debugging, relationship graphs, table semantics, setup guidance, and query-risk classification, with read-only access enabled by default.

Install it by running it with npx or by adding it through VS Code’s MCP interface. The documented npx command is `npx -y @edelciomolina/postgres-mcp`; configure the resulting stdio server entry with credential mappings and a project `.env` file.

Map `MCP_KEY_URL` to the variable containing the connection string, such as `DATABASE_URL`. When that URL is present, postgres-mcp uses it instead of the separately mapped host, port, database, SSL mode, user, and password variables.

Enable write tools by adding each tool as a separate `tool=<name>` argument and setting `POSTGRES_MCP_ALLOW_WRITE=true` in the MCP environment. Without that setting, requesting write-capable tools causes the server to exit at startup.

Yes, postgres-mcp can be discovered and installed through VS Code’s MCP interface, then configured in `.vscode/mcp.json`.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewPostgres MCP AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/postgres-mcp?style=directory)](https://allmcps.com/mcp/postgres-mcp)
HTML Embed
<a href="https://allmcps.com/mcp/postgres-mcp"><img src="https://allmcps.com/api/badge/postgres-mcp?style=directory" alt="Postgres MCP on AllMCPs" /></a>