PostgreSQL MCP
Read-only MCP server for PostgreSQL, enabling schema discovery, table metadata, and safe SELECT queries via READ ONLY transactions.
README
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, defaults- Resources — per-table schema JSON via MCP resources
- Safety — SQL keyword guard +
BEGIN READ ONLYtransactions - Transports — stdio (local) and Streamable HTTP (hosted)
Quick start
git clone https://github.com/vallaksa/postgresql-mcp.git
cd postgresql-mcp
npm install
npm run build
stdio (local MCP clients)
export DATABASE_URL="postgresql://mcp_reader:password@localhost:5432/devstrom"
npm start
# or: node dist/index.js
HTTP (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/mcp
Client 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
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-mcp
See docker-compose.example.yml for a compose snippet.
Read-only database user
MCP_READER_PASSWORD='your-password' psql -U postgres -d devstrom \
-v ON_ERROR_STOP=1 -f scripts/setup_readonly_user.sql
Environment variables
| Variable | Description |
|---|---|
DATABASE_URL |
PostgreSQL connection string (server-side) |
MCP_POSTGRES_URL |
Alias for DATABASE_URL |
MCP_TRANSPORT |
stdio (default) or http |
MCP_API_KEY |
Bearer token for HTTP auth (required on non-loopback hosts) |
HOST / MCP_HOST |
HTTP bind address (default 0.0.0.0) |
PORT / MCP_PORT |
HTTP port (default 3000) |
MCP_HTTP_PATH |
HTTP MCP path (default /mcp) |
MCP_MAX_ROWS |
Max rows per query (default 100, max 1000) |
CLI
postgresql-mcp # stdio (default)
postgresql-mcp stdio # stdio, explicit
postgresql-mcp http # Streamable HTTP server
postgresql-mcp postgresql://... # stdio with URL arg
Development
npm test
npm run typecheck
npm run dev -- postgresql://...
npm run dev:http
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.