About Postgres Mcp
Postgres MCP is an MCP server for querying PostgreSQL databases with SQL or plain-English instructions. It combines schema inspection and database switching with query-type-based permission checks.
Key features
- 01Execute SQL with dry-run support
- 02Control permissions by query type
- 03Inspect tables, columns, indexes, and constraints
- 04Switch the active database
- 05Handle errors and rollbacks
Use cases
- 01Inspect table schemas and relationships
- 02Validate queries before execution
- 03Run database operations under permission controls
MCP support
The server exposes query execution, table listing, schema description, and database switching tools to MCP clients.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
npx -y @freakynit/postgres-mcpPOSTGRES_HOSTPOSTGRES_USERPOSTGRES_PASSWORDSecretPOSTGRES_DATABASELocal servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.
Tools
4Saved tool list · updated 2w ago
This tool takes no parameters.
Details
From the project READMEPostgres MCP
A lightweight MCP (Model Context Protocol) server built to query Postgres database using SQL or plain English commands. It provides comprehensive tools for database operations, table introspection, and query execution with smart permission handling.
Features
Smart Query Permission Handling
- Read-only queries: Automatically approved (SELECT, EXPLAIN, SHOW, VALUES)
- Read-write queries: User confirmation required (INSERT, UPDATE, DELETE, MERGE)
- Admin/DDL queries: Elevated permission required (CREATE, ALTER, DROP, etc.)
- Dry-run mode: Validate queries without execution
Comprehensive Table Introspection
- Column definitions with types and constraints
- Primary and foreign key relationships
- Index definitions
- Triggers and check constraints
Database Management
- Multiple database switching capability
- Robust error handling and rollback
Available Tools
| Tool | Description |
|---|---|
execute_raw_query | Execute SQL queries with permission validation and dry-run support |
list_tables | List all non-system tables |
describe_tables | Get comprehensive table information including columns, indexes, triggers, and constraints |
switch_database | Switch the active database connection |
Minimum needed environment variables
POSTGRES_HOSTPOSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_DATABASE
Other environment variables
POSTGRES_PORTPOSTGRES_SSL(boolean)POSTGRES_VERIFY(boolean)POSTGRES_SEND_RECEIVE_TIMEOUT(in seconds)POSTGRES_CONNECT_TIMEOUT(in seconds)
Configuring using mcpServers json
For Mac and Linux
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": ["-y", "@freakynit/postgres-mcp@latest"],
"env": {
"POSTGRES_HOST": "<POSTGRES HOST>",
"POSTGRES_USER": "<POSTGRES USER>",
"POSTGRES_PASSWORD": "<POSTGRES PASSWORD>",
"POSTGRES_DATABASE": "<POSTGRES DATABASE>"
}
}
}
}
For Windows
{
"mcpServers": {
"postgres-mcp": {
"command": "cmd",
"args": ["/k", "npx", "-y", "@freakynit/postgres-mcp@latest"],
"env": {
"POSTGRES_HOST": "<POSTGRES HOST>",
"POSTGRES_USER": "<POSTGRES USER>",
"POSTGRES_PASSWORD": "<POSTGRES PASSWORD>",
"POSTGRES_DATABASE": "<POSTGRES DATABASE>"
}
}
}
}
Development Docs
Prerequisites
- Node.js
- A PostgreSQL server
Installation
npm i -g @freakynit/postgres-mcp
OR
git clone https://github.com/freakynit/postgres-mcp.git
cd postgres-mcp
npm install
Configuration
Create a .env file in the project root with the following variables:
# PostgreSQL
POSTGRES_HOST=your-db-host
POSTGRES_PORT=5432 # Optional, default 5432
POSTGRES_USER=your-username
POSTGRES_PASSWORD=your-password
POSTGRES_DATABASE=your-database
# SSL settings (optional)
POSTGRES_SSL=false # Or true
POSTGRES_VERIFY=false # Verify server cert if SSL true
# Timeouts (optional, seconds)
POSTGRES_SEND_RECEIVE_TIMEOUT=60 # Query timeout
POSTGRES_CONNECT_TIMEOUT=60 # Connection timeout
Usage
Local Development
Start the server (Starts in stdio mode):
node src/index.js
With MCP Inspector
For debugging and development:
npx @modelcontextprotocol/inspector node src/index.js
Debugging with MCP inspector
npx @modelcontextprotocol/inspector node src/index.js
License
This project is licensed under the MIT License. See LICENSE for details.
![]()
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.