Skip to main content
Glama
vallaksa

PostgreSQL MCP

by vallaksa

PostgreSQL MCP

Read-only Model Context Protocol server for PostgreSQL. Gives LLM agents safe SQL access: schema discovery, table metadata, and SELECT queries inside READ ONLY transactions.

Built as a maintained alternative to the deprecated @modelcontextprotocol/server-postgres package.

Features

  • query — read-only SQL (SELECT, WITH, EXPLAIN, SHOW) with row caps

  • list_tables — list tables in a schema

  • describe_table — column names, types, nullability, defaults

  • Resources — per-table schema JSON via MCP resources

  • Safety — SQL keyword guard + BEGIN READ ONLY transactions

  • Config — connection string via CLI arg or DATABASE_URL / MCP_POSTGRES_URL

Related MCP server: PostgreSQL MCP Server

Quick start

git clone https://github.com/vallaksa/postgresql-mcp.git
cd postgresql-mcp
npm install
npm run build

Run with a connection string:

export DATABASE_URL="postgresql://mcp_reader:password@localhost:5432/devstrom"
npm start

Or pass the URL as the first argument:

node dist/index.js "postgresql://mcp_reader:password@localhost:5432/devstrom"

Cursor / Claude Desktop

Add to .cursor/mcp.json or Claude config:

{
  "mcpServers": {
    "postgresql": {
      "command": "node",
      "args": [
        "/absolute/path/to/postgresql-mcp/dist/index.js",
        "postgresql://mcp_reader:password@localhost:5432/devstrom"
      ]
    }
  }
}

After publishing to npm:

{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": ["-y", "postgresql-mcp", "postgresql://mcp_reader:password@localhost:5432/devstrom"]
    }
  }
}

Read-only database user

Create a dedicated reader (example for Dev-Strom):

psql -U postgres -d devstrom -f scripts/setup_readonly_user.sql

Set MCP_READER_PASSWORD before running the script.

Environment variables

Variable

Description

DATABASE_URL

PostgreSQL connection string

MCP_POSTGRES_URL

Alias for DATABASE_URL

MCP_MAX_ROWS

Max rows per query (default 100, max 1000)

Dev-Strom integration

In Dev-Strom, point scripts/start_mcp.sh at this server and set MCP_POSTGRES_URL in .env.

Development

npm test
npm run typecheck
npm run dev -- "postgresql://..."

License

MIT

A
license - permissive license
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

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