MCP PostgreSQL Server
raw JSON →A Model Context Protocol (MCP) server that enables AI models, particularly Claude, to interact with PostgreSQL databases through standardized tools like query, execute, list_schemas, list_tables, and describe_table. Version 0.1.3 is the latest stable release, currently in early development with active updates. It supports both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders for prepared statements, multi-schema operations, and TypeScript types. Unlike generic database MCP servers, it is purpose-built for PostgreSQL, offering secure connection handling via environment variables and automatic cleanup. It is designed for use with MCP-compatible hosts (e.g., Claude Desktop) and should not be confused with direct database client libraries.
Common errors
error Error: Cannot find module 'mcp-postgres-server' ↓
error Error: getaddrinfo ENOTFOUND your_host ↓
Warnings
breaking Environment variables must be set before starting the server or the connection will fail. ↓
gotcha The package does not support connection pooling; each tool call opens a new connection, which can be slow. ↓
gotcha The 'connect_db' tool is redundant; the server auto-connects using environment variables. Calling connect_db may conflict. ↓
Install
npm install mcp-postgres-server yarn add mcp-postgres-server pnpm add mcp-postgres-server Imports
- default wrong
const server = require('mcp-postgres-server')correctimport server from 'mcp-postgres-server' - Server wrong
import Server from 'mcp-postgres-server'correctimport { Server } from 'mcp-postgres-server'
Quickstart
npx mcp-postgres-server
# Then configure in your MCP client (e.g., Claude Desktop):
# {
# "mcpServers": {
# "postgres": {
# "type": "stdio",
# "command": "npx",
# "args": ["-y", "mcp-postgres-server"],
# "env": {
# "PG_HOST": process.env.PG_HOST ?? 'localhost',
# "PG_PORT": process.env.PG_PORT ?? '5432',
# "PG_USER": process.env.PG_USER ?? 'postgres',
# "PG_PASSWORD": process.env.PG_PASSWORD ?? '',
# "PG_DATABASE": process.env.PG_DATABASE ?? 'mydb'
# }
# }
# }
# }