PostgreSQL MCP
Provides read-only SQL access to PostgreSQL databases, enabling schema discovery, table metadata retrieval, and safe SELECT queries within read-only transactions.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
PostgreSQL MCP
Read-only Model Context Protocol server for PostgreSQL. Works with any MCP client — Cursor, Claude Desktop, Claude Code, VS Code, or custom clients over stdio or Streamable HTTP.
Database credentials stay on the server. Clients connect with a URL and API key (HTTP) or spawn the binary locally (stdio).
Features
query— read-only SQL (SELECT,WITH,EXPLAIN,SHOW) with row capslist_tables— list tables in a schemadescribe_table— column names, types, nullability, defaultsResources — per-table schema JSON via MCP resources
Safety — SQL keyword guard +
BEGIN READ ONLYtransactionsTransports — stdio (local) and Streamable HTTP (hosted)
Related MCP server: db-mcp
Quick start
git clone https://github.com/vallaksa/postgresql-mcp.git
cd postgresql-mcp
npm install
npm run buildstdio (local MCP clients)
export DATABASE_URL="postgresql://mcp_reader:password@localhost:5432/devstrom"
npm start
# or: node dist/index.jsHTTP (hosted / remote MCP)
export DATABASE_URL="postgresql://mcp_reader:password@localhost:5432/devstrom"
export MCP_API_KEY="your-long-random-secret"
npm run start:http
# listens on http://0.0.0.0:3000/mcpClient configuration
stdio — Claude Desktop, local Cursor, etc.
{
"mcpServers": {
"postgresql": {
"command": "node",
"args": ["/absolute/path/to/postgresql-mcp/dist/index.js"],
"env": {
"DATABASE_URL": "postgresql://mcp_reader:password@localhost:5432/devstrom"
}
}
}
}Or publish to npm:
{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": ["-y", "postgresql-mcp"],
"env": {
"DATABASE_URL": "postgresql://mcp_reader:password@localhost:5432/devstrom"
}
}
}
}Streamable HTTP — any remote MCP client
Point the client at your hosted endpoint. No database URL in client config.
{
"mcpServers": {
"postgresql": {
"url": "https://postgres-mcp.example.com/mcp",
"headers": {
"Authorization": "Bearer your-api-key"
}
}
}
}Clients that only support stdio can bridge with mcp-remote:
{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://postgres-mcp.example.com/mcp",
"--header",
"Authorization:Bearer your-api-key"
]
}
}
}Docker
Compose (homelab / shared Postgres network)
cp docker-compose.example.yml docker-compose.yml
cp .env.example .env # set DATABASE_URL, MCP_API_KEY; encode @ in passwords as %40
docker compose up -d --build
curl -s http://127.0.0.1:3000/healthExpects an existing global-network and a Postgres container reachable as postgres (see comments in docker-compose.example.yml).
Single container
docker build -t postgresql-mcp .
docker run --rm -p 3000:3000 \
-e DATABASE_URL="postgresql://mcp_reader:password@host.docker.internal:5432/devstrom" \
-e MCP_API_KEY="your-api-key" \
postgresql-mcpRead-only database user
MCP_READER_PASSWORD='your-password' psql -U postgres -d devstrom \
-v ON_ERROR_STOP=1 -f scripts/setup_readonly_user.sqlEnvironment variables
Variable | Description |
| PostgreSQL connection string (server-side) |
| Alias for |
|
|
| Bearer token for HTTP auth (required on non-loopback hosts) |
| HTTP bind address (default |
| HTTP port (default |
| HTTP MCP path (default |
| Max rows per query (default |
CLI
postgresql-mcp # stdio (default)
postgresql-mcp stdio # stdio, explicit
postgresql-mcp http # Streamable HTTP server
postgresql-mcp postgresql://... # stdio with URL argDevelopment
npm test
npm run typecheck
npm run dev -- postgresql://...
npm run dev:httpLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Read-only MCP server for The Quiet Protocol's engines, benchmarks, proof, and business data.
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceRead-only PostgreSQL MCP server that enables running SELECT queries, listing tables and schemas, and describing columns, with built-in protection against writes and malicious SQL attacks.MIT
- FlicenseAqualityDmaintenanceRead-only PostgreSQL database MCP server for safely exploring schema, tables, relationships, and sample data without modification.10-
- AlicenseNot gradedqualityDmaintenanceA zero-config, read-only PostgreSQL MCP server that enforces read-only access at the database level using READ ONLY transactions, allowing AI agents to safely explore schemas and run SELECT queries without risk of mutation.11 npmMIT
- FlicenseNot gradedqualityBmaintenanceRead-only MCP server for PostgreSQL enabling schema introspection and SELECT queries via MCP clients like Claude, with multi-layered write protection.-