Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
Your own AI agent, running 24/7 with QwikClaw logoYour own AI agent, running 24/7 with QwikClaw

QwikClaw sets up and runs an always-on OpenClaw agent for you. One click, no config files, no server setup.

Deploy now
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 47,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

Enables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.

README.md

PostgreSQL MCP Server 🐘

English | Tiếng Việt

A robust Model Context Protocol (MCP) server for PostgreSQL databases. This server allows AI assistants (like Claude, Antigravity, or VS Code extensions) to safely interact with your PostgreSQL data, perform queries, and inspect schemas.

🌟 Features

  • Direct Database Access: Connect to any PostgreSQL database using a connection string.
  • Schema Inspection: Easily view tables, columns, constraints, and indexes.
  • Full Text Search: Search for content across all text columns in a table.
  • Performance Analysis: Run EXPLAIN to see query execution plans.
  • Safety First: Separate tools for read-only (SELECT) and modification queries.

🛠️ Available Tools

| Tool | Description | | ------------------------ | ----------------------------------------------------------------------- | | list_tables | List all tables in the public schema. | | describe_table | Get detailed schema information (columns, types, defaults) for a table. | | list_indexes | View all indexes on a specific table. | | list_constraints | View Primary Keys, Foreign Keys, and other constraints. | | search_in_table | Search for a text string in any text column of a table. | | run_read_only_query | Execute safe SELECT queries. Blocks modification commands. | | run_modification_query | Execute INSERT, UPDATE, DELETE, CREATE commands. | | explain_query | Get the JSON execution plan for performance tuning. |

🚀 Installation & Setup

1. Prerequisites

  • Node.js (v18 or higher)
  • A running PostgreSQL database

2. Installation

Clone this repository and install dependencies:

git clone <your-repo-url>
cd mcp-postgre-server
npm install

3. Configuration (.env)

Create a .env file in the root directory to store your database credentials. Important: Never commit your real .env file to version control.

cp .env.example .env

Edit .env and set your DATABASE_URL:

# Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE
DATABASE_URL=postgresql://myuser:mypassword@localhost:5432/mydatabase

4. Build

Compile the TypeScript code:

npm run build

🔌 Connect to Clients

VS Code (Claude / MCP Extension) & Antigravity

To use this server with MCP-compliant clients, add the following configuration to your MCP settings file (e.g., mcp_config.json or VS Code extension settings).

Config Path (Example):

  • Windows: %APPDATA%\Code\User\globalStorage\mcp-server\mcp_settings.json (varies by extension)
  • Antigravity: c:\Users\<User>\.gemini\antigravity\mcp_config.json

JSON Configuration:

{
  "mcpServers": {
    "postgre-server": {
      "command": "node",
      "args": ["D:\\Path\\To\\mcp-postgre-server\\build\\index.js"],
      "env": {
        "DATABASE_URL": "postgresql://myuser:mypassword@localhost:5432/mydatabase"
      }
    }
  }
}

Note: You can either set DATABASE_URL in the .env file (if you run the server from the correct working directory) or pass it directly in the env section of the JSON config as shown above. Using the JSON config is often more reliable for absolute paths.

🔒 Security

  • Read-Only Enforcement: The run_read_only_query tool implements a basic check to prevent INSERT/UPDATE/DELETE keywords.
  • Input Sanitization: Table names are validated in search tools to prevent SQL injection.

📜 License

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use Databases servers.