postgres-mcp
PostgreSQL MCP Server
A Model Context Protocol (MCP) server written in Node.js that exposes a full set of tools for running DDL and DML operations against a PostgreSQL database.
Features
Tool | Category | Description |
| Utility | Test DB connection & get server version |
| DQL | Run a SELECT / EXPLAIN (read-only) |
| DML | Run INSERT / UPDATE / DELETE / MERGE |
| DDL | Run CREATE / ALTER / DROP / TRUNCATE |
| DML+DDL | Run multiple statements atomically |
| Introspection | List all schemas |
| Introspection | List tables in a schema |
| Introspection | Show columns, types, PK, nullability |
| Introspection | Show indexes for a table |
Prerequisites
Node.js >= 18
A running PostgreSQL instance
Setup
# 1. Install dependencies
cd "Postgres MCP"
npm install
# 2. Create your .env file
copy .env.example .env
# Then edit .env with your database credentials.env fields
Variable | Required | Default | Description |
| No |
| DB host |
| No |
| DB port |
| Yes | — | Database name |
| Yes | — | DB username |
| Yes | — | DB password |
| No |
| Pool size |
| No |
| Idle timeout (ms) |
| No |
| Connect timeout (ms) |
Running
# Start the server (communicates over stdio)
npm start
# Development mode (restarts on file changes)
npm run devRegister with Claude Desktop / MCP Client
Add this to your MCP client config (e.g., claude_desktop_config.json):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Pooja Data/services-app/mcps/Postgres MCP/src/index.js"],
"env": {
"POSTGRES_HOST": "localhost",
"POSTGRES_PORT": "5432",
"POSTGRES_DB": "your_database",
"POSTGRES_USER": "your_username",
"POSTGRES_PASSWORD": "your_password"
}
}
}
}Tool Usage Examples
Run a SELECT query
{
"tool": "pg_query",
"sql": "SELECT * FROM users WHERE status = $1 LIMIT 10",
"params": ["active"]
}Insert a row
{
"tool": "pg_execute",
"sql": "INSERT INTO users (name, email) VALUES ($1, $2) RETURNING id",
"params": ["Alice", "alice@example.com"],
"returning": true
}Create a table
{
"tool": "pg_ddl",
"sql": "CREATE TABLE IF NOT EXISTS products (id SERIAL PRIMARY KEY, name TEXT NOT NULL, price NUMERIC(10,2))"
}Run a transaction
{
"tool": "pg_transaction",
"statements": [
{ "sql": "UPDATE accounts SET balance = balance - $1 WHERE id = $2", "params": [100, 1] },
{ "sql": "UPDATE accounts SET balance = balance + $1 WHERE id = $2", "params": [100, 2] }
]
}Safety
pg_queryonly allows DQL statements (SELECT, EXPLAIN, etc.) — DML/DDL are rejected.pg_executeonly allows DML — DDL is rejected.pg_ddlonly allows DDL.pg_transactionwraps all statements in BEGIN/COMMIT and rolls back on any error.Transaction control keywords (BEGIN, COMMIT, ROLLBACK) in raw SQL are blocked — use
pg_transactioninstead.Results are capped at 200 rows to avoid oversized payloads.
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/poojajuneja900/postgres-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server