Postgres MCP
Provides tools for executing SQL queries against PostgreSQL, listing tables, describing table schemas and constraints, switching databases, and validating queries with permission handling and dry-run support.
Click on "Deploy 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., "@Postgres MCP list all tables in my database and describe the users table"
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.
Postgres 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
Related MCP server: PostgreSQL MCP Server
Available Tools
Tool | Description |
| Execute SQL queries with permission validation and dry-run support |
| List all non-system tables |
| Get comprehensive table information including columns, indexes, triggers, and constraints |
| 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-mcpOR
git clone https://github.com/freakynit/postgres-mcp.git
cd postgres-mcp
npm installConfiguration
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 timeoutUsage
Local Development
Start the server (Starts in stdio mode):
node src/index.jsWith MCP Inspector
For debugging and development:
npx @modelcontextprotocol/inspector node src/index.jsDebugging with MCP inspector
npx @modelcontextprotocol/inspector node src/index.js
License
This project is licensed under the MIT License. See LICENSE for details.
![]()
Available Tools
4 toolsdescribe_tablesGet complete table description including columns, indexes, triggers, and constraints for one more tablesA
Get comprehensive table information for one or more tables including columns, indexes, triggers, foreign keys, and constraints
Inputs: table_names (required), table_schema.
execute_raw_queryExecute a SQL queryB
Execute a SQL query. The system will automatically detect the required permission level and request user approval for write operations and dangerous DDL commands.
Inputs: sql (required), dry_run.
list_tablesList all user tables in the databaseC
List all user tables in the database
Inputs: no named parameters.
switch_databaseSwitch current databaseB
Switches the active database to the specified one. If an error occurs during the switch, the system automatically reverts back to the previous active database
Inputs: database_name (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool targets a distinct capability: table listing, schema introspection, SQL execution, and database switching. The only potential overlap is that execute_raw_query can query metadata, but the dedicated list/describe tools are clearly scoped as conveniences.
All tools use consistent snake_case with a clear verb_noun pattern (list_tables, describe_tables, execute_raw_query, switch_database). The minor adjective in execute_raw_query does not break the convention.
Four tools is lean but reasonable for a database MCP server, and each tool has a clear role. Slightly under-provisioned for broader database workflows, but still within a well-scoped range.
The surface covers core discovery, schema inspection, arbitrary SQL execution, and database switching. Minor gaps exist around listing databases or schemas without raw SQL, but execute_raw_query makes these workarounds possible.
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Ask plain-English questions of your database: answers, the SQL that ran, and the rows.
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceEnables secure read-only interactions with PostgreSQL databases through natural language. Provides database inspection, table listing, and SQL query execution with built-in security validation.-
- FlicenseBqualityDmaintenanceEnables natural language interaction with PostgreSQL databases, converting questions to safe SQL queries and executing them with result validation.1-
- AlicenseAqualityCmaintenanceEnables read-only interaction with PostgreSQL databases through natural language queries, supporting dynamic connections and secure query validation.3178 npm2MIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language querying of PostgreSQL databases with intelligent SQL generation using LLMs.1Apache 2.0