PostgreSQL MCP
Provides read-only SQL access to PostgreSQL databases, enabling schema discovery, table metadata retrieval, and safe SELECT queries within read-only transactions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCPlist all tables in the public schema"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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: mcp-postgres
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
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- 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/vallaksa/postgresql-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server