Registry / database / mcp-postgres

mcp-postgres

JSON →
library1.0.2jsnpmunverified

MCP server providing PostgreSQL database operations—query, schema inspection, data manipulation—for MCP-compatible clients. Current stable version: 1.2.1, released January 2025. Security-focused: v1.2.0 fixed SQL injection in column names and SSL validation. Supports environment variables, DATABASE_URL, or config file; auto-configures SSL for AWS RDS. Releases are frequent (two in Jan 2025) with security patches and fixes. Key differentiator: MCP-native protocol integration vs generic database drivers.

npm install mcp-postgres
INSTALL
IMPORT
SIG · MCP-POSTGRES
M
mcp-postgres
databasejavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (server instance)
import server from 'mcp-postgres'
const server = require('mcp-postgres')
ESM-only package; no CommonJS support. The server starts automatically on import when run as a CLI.
PostgresServer
import { PostgresServer } from 'mcp-postgres'
import { PostgresServer } from 'mcp-postgres'
Class-based export for programmatic usage
Config
import type { Config } from 'mcp-postgres'
TypeScript type for configuration object

Programmatic setup of MCP PostgreSQL server with environment variables, connecting via stdio transport.

import { PostgresServer } from 'mcp-postgres'; import { Server } from '@modelcontextprotocol/sdk/server/index.js'; // The package is typically run as a CLI tool. // To run programmatically: import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; const server = new PostgresServer({ host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '5432'), user: process.env.DB_USER ?? 'postgres', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'postgres', sslmode: process.env.DB_SSL_MODE ?? 'disable' }); const transport = new StdioServerTransport(); await server.connect(transport); console.error('MCP PostgreSQL Server running on stdio');
mcp-postgres --version
Debug
Known issues
breakingv1.2.0: Fixed SQL injection via unquoted column names in update_data, delete_data, insert_data, count_rows, alter_table, create_table. Update immediate if using these tools with untrusted input.
fix
Upgrade to >=1.2.0
affects: <1.2.0
breakingv1.2.0: SSL mode 'require' now validates server certificates (rejectUnauthorized: true). Previously it disabled validation, allowing MITM attacks.
fix
Update to >=1.2.0 and ensure valid certificates.
affects: <1.2.0
gotchav1.2.1: pg.Client does not support concurrent queries. Using Promise.all() on a single client will cause a deprecation warning in pg@9.0.
fix
Upgrade to v1.2.1 which runs queries sequentially.
affects: >=1.0.0 <1.2.1
gotchaConfig file must be named 'config.json' in the working directory. No other names or paths are supported.
fix
Rename or move config file to ./config.json
affects: >=1.0.0
deprecatedUse of DATABASE_URL is deprecated in favor of individual environment variables (DB_HOST, etc.).
fix
Switch to individual env vars: DB_HOST, DB_PORT, etc.
affects: >=1.1.1
Errors
Common errors & fixes
(node:xxx) [PG] Deprecation Warning: pg@9.0 will drop support for concurrent queries on a single client. Use a pool instead.
Using Promise.all() to run multiple queries on a single pg.Client concurrently.
fix
Update to mcp-postgres@1.2.1 or later, which sequences queries.
Error: Invalid input syntax for type ... ... at column '...'
SQL injection attempt or malformed column name (unquoted special characters).
fix
Upgrade to >=1.2.0 which properly quotes identifiers.
Error: getaddrinfo ENOTFOUND ...
PostgreSQL hostname not resolvable or incorrect.
fix
Check DB_HOST or DATABASE_URL value. Ensure the host is reachable and resolveable.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client driver for Node.js
@modelcontextprotocol/sdkrequiredMCP SDK for server implementation
Agent activity
6 hits · last 30 days
node
6
Resources
mcp-postgres — npm install mcp-postgres · libregistry