PostgreSQL MCP Server

PostgreSQL MCP Server

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

Category
Visit Server

README

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured