Postgresql MCP Server

MCP server for PostgreSQL database operations - query, explore schemas, and analyze tables

Local serverstdioPython

What is the Postgresql MCP server?

MCP server for PostgreSQL database operations - query, explore schemas, and analyze tables. That is what the postgresql mcp server brings to an AI assistant: the same capability, reachable through the Model Context Protocol rather than a separate app or dashboard.

The short version

MCP server for PostgreSQL database operations. Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible client.

  • Query Execution — Execute SQL queries with read-only protection by default
  • Schema Exploration — List schemas, tables, views, and functions
  • Table Analysis — Describe structure, indexes, constraints, and statistics
  • Performance Tools — EXPLAIN queries and analyze table health
  • Security First — SQL injection prevention, credential protection, read-only by default
  • MCP Prompts — Guided workflows for exploration, query building, and documentation

The tools it exposes

The server publishes 1 tool. What each one is for:

  • TypeScript — The TypeScript tool exposed by this server

What it needs from you

Configuration is passed through the environment: POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB. Treat anything key-shaped as a real credential — scope it to the minimum the server needs, and rotate it if it ever lands in a shared config.

Getting it running

The server ships on npm as npx, so your MCP client can launch it on demand — there is no separate build step. Add the server block to your client's configuration, restart it, and the tools register themselves.

How it compares

Among the database access options, the useful question is rarely "what can it do" but "what does it cost you to run" — permissions, credentials, and how much of your context its toolset consumes. Postgresql's toolset — TypeScript — is a fair guide to whether it matches your workflow.

This entry was verified against Postgresql's own documentation before publication; SyncDev keeps the directory reviewed rather than auto-generated.

Things to watch

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • Keep per-call confirmation enabled while you learn its behaviour; it is the cheapest safeguard you have.

Available tools

ToolWhat it does
TypeScriptThe TypeScript tool exposed by this server.

How to install the Postgresql MCP server

{
  "mcpServers": {
    "postgresql-1": {
      "command": "npx",
      "args": ["-y", "npx"],
      "env": {
        "POSTGRES_HOST": "your-value",
        "POSTGRES_PORT": "your-value",
        "POSTGRES_USER": "your-value",
        "POSTGRES_PASSWORD": "your-value",
        "POSTGRES_DB": "your-value"
      }
    }
  }
}

Add to claude_desktop_config.json, then restart Claude Desktop.

Configuration

VariableDescriptionRequired
POSTGRES_HOSTEndpoint or connection string the server talks to.Optional
POSTGRES_PORTConfiguration value read at startup.Optional
POSTGRES_USERConfiguration value read at startup.Optional
POSTGRES_PASSWORDConfiguration value read at startup.Optional
POSTGRES_DBConfiguration value read at startup.Optional

Example prompts to try

  • Use Postgresql to TypeScript.

Frequently asked questions

It connects Postgresql to MCP-compatible AI assistants such as Claude and Cursor, exposing 1 tool (TypeScript) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with Postgresql directly.