LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

mcp-postgres

MCP server exposing PostgreSQL tools to AI assistants

TLDR

Start in stdio mode for Claude Desktop integration
$ mcp-postgres --database-url "[postgres://user:pass@localhost:5432/dbname]" --stdio
copy
Start a TCP server on the default port
$ mcp-postgres --database-url "[postgres://user:pass@localhost:5432/dbname]"
copy
Start an HTTP/2 server
$ mcp-postgres --database-url "[postgres://user:pass@localhost:5432/dbname]" --http-port [3001]
copy
Use restricted access mode for production databases
$ mcp-postgres --database-url "[postgres://user:pass@localhost:5432/dbname]" --access-mode restricted
copy
Enable Prometheus metrics
$ mcp-postgres --database-url "[postgres://user:pass@localhost:5432/dbname]" --enable-metrics --metrics-port [9090]
copy

SYNOPSIS

mcp-postgres --database-url URL [options]

DESCRIPTION

mcp-postgres is a Model Context Protocol (MCP) server that connects AI assistants such as Claude to a PostgreSQL database. It exposes over 135 tools covering query execution, schema inspection, DDL operations, data management, monitoring, and security auditing.The server supports three transport modes: stdio for direct integration with Claude Desktop and compatible MCP clients, TCP for network-accessible deployments on port 3000, and HTTP/2 for web-based clients on port 3001. Connection pooling is managed automatically with configurable minimum and maximum pool sizes.Install via Cargo with `cargo install mcp-postgres`, or on macOS via Homebrew with `brew tap corporatepiyush/mcp-postgres && brew install mcp-postgres`.

PARAMETERS

-d, --database-url URL

PostgreSQL connection string (required)
--stdio
Run in stdio mode for Claude Desktop and compatible MCP clients
-H, --host host
TCP server bind address (default: 127.0.0.1)
-p, --port port
TCP server port (default: 3000)
--http-port port
HTTP/2 server port (default: 3001)
--min-connections n
Minimum connection pool size (default: 5)
--max-connections n
Maximum connection pool size (default: 20)
--log-level level
Log verbosity: trace, debug, info, warn, error (default: info)
--access-mode mode
Security level: `unrestricted` (all SQL allowed) or `restricted` (safe queries only)
--enable-metrics
Activate Prometheus metrics endpoint
--metrics-port port
Prometheus metrics server port (default: 9090)
--tls-cert path
PEM certificate file for HTTPS
--tls-key path
PEM private key file for HTTPS
-V, --version
Show version number

CAVEATS

The `unrestricted` access mode permits all SQL operations including DDL statements and destructive queries. Use `restricted` mode when connecting to production databases. Ensure the PostgreSQL user has only the minimum required privileges regardless of the access mode setting.

SEE ALSO

psql(1), pg_dump(1)

RESOURCES

Copied to clipboard
Kai