PostgreSQL MCP Server
Provides tools for interacting with PostgreSQL databases, including schema inspection, table listing, search, query execution (read-only and modification), and performance analysis via EXPLAIN.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP Serverlist all tables"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL MCP Server 🐘
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
EXPLAINto see query execution plans.Safety First: Separate tools for read-only (
SELECT) and modification queries.
Related MCP server: PostgreSQL MCP Server
🛠️ Available Tools
Tool | Description |
| List all tables in the |
| Get detailed schema information (columns, types, defaults) for a table. |
| View all indexes on a specific table. |
| View Primary Keys, Foreign Keys, and other constraints. |
| Search for a text string in any text column of a table. |
| Execute safe |
| Execute |
| 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 install3. 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 .envEdit .env and set your DATABASE_URL:
# Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE
DATABASE_URL=postgresql://myuser:mypassword@localhost:5432/mydatabase4. 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_URLin the.envfile (if you run the server from the correct working directory) or pass it directly in theenvsection 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_querytool implements a basic check to preventINSERT/UPDATE/DELETEkeywords.Input Sanitization: Table names are validated in search tools to prevent SQL injection.
📜 License
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityFmaintenanceEnables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.Last updated98Apache 2.0
- Alicense-quality-maintenanceProvides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.Last updated1
- Alicense-qualityDmaintenanceEnables LLMs to interact deeply with PostgreSQL databases—query data, manage schema, analyze performance, and administer the database.Last updated1824MIT
- Flicense-qualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.Last updated171
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/longgoll/mcp-postgreSql-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server