Skip to content
MCP server

Postgres (read-only)

Read-only Postgres access with four enforcement layers and a shared business-context file

Runs locallyStatus and history
Install
Pricing
Open source
Platforms
CLI, self-hosted
Runs
Locally
Version
0.1.4
Listing updated
1 day ago

About Postgres (read-only)

Postgres (read-only) is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.

The archived reference Postgres server let a COMMIT then DROP SCHEMA payload escape its read-only transaction, and this server exists as a drop-in replacement that stops it in four independent ways: the extended query protocol rejects multi-statement input, every statement runs in BEGIN READ ONLY and ends in ROLLBACK, the real Postgres parser walks the tree to catch writes hidden in CTEs, and a read-only database role is recommended. It admits a user-defined function called from a SELECT is not covered, and that read-only does not mean confidential.

The second idea is a context file, .contextflo/context.md, seeded from COMMENT ON values. It holds business definitions such as what revenue means, is handed to the model, and the agent can append gotchas with add_table_context for you to review in git. Tools are query, list_tables, get_table_context and add_table_context. Results cap at 1,000 rows and 50,000 characters by default and truncation is stated.

The package is MIT licensed and needs Node.js 20 or later. Contextflo sells a team product with access control and audit logs on top, but this server is standalone.

Install

Run in a terminal

claude mcp add postgres-mcp --env DATABASE_URL='<DATABASE_URL>' -- npx -y @contextflo/postgres-mcp

Add to claude_desktop_config.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@contextflo/postgres-mcp"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}

Add to ~/.cursor/mcp.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@contextflo/postgres-mcp"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}

Add to .vscode/mcp.json

{
  "servers": {
    "postgres-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@contextflo/postgres-mcp"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}

Add to ~/.codeium/windsurf/mcp_config.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@contextflo/postgres-mcp"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}

Add to your client's MCP settings (most use this shape)

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@contextflo/postgres-mcp"
      ],
      "env": {
        "DATABASE_URL": "<DATABASE_URL>"
      }
    }
  }
}

Configuration

  • DATABASE_URLPostgres connection string. Use a read-only role.Required

Tools this server provides (4)

Taken from the project documentation; the running server may differ.

query
Runs one read-only statement: SELECT, WITH SELECT, EXPLAIN or SHOW.
list_tables
Lists readable tables with descriptions.
get_table_context
Returns columns, types, keys, enum values and descriptions.
add_table_context
Lets the agent add a note to the context file.

What it does

Four-layer read-only
Protocol, connection, parser and role each block writes.
Context file
Business definitions are handed to the model and editable in git.
Agent notes
The agent can append gotchas for you to review.
Result caps
Defaults to 1,000 rows and 50,000 characters.
Statement timeout
30 seconds by default, configurable.
Schema tools
Lists tables and shows columns, keys and enum values.

Good for

  • Let an assistant query analytics data without write risk
  • Replace the archived reference Postgres server
  • Teach a model what business metrics mean
  • Explore an unfamiliar schema

Pricing

Open source

MIT licensed; Contextflo team product is paid separately

Prices change. Check contextflo.com before you buy.

Postgres (read-only) FAQ

Is it really read-only?

It uses four layers, but the README says a read-only role is still recommended because functions called from a SELECT are not covered.

What does it need?

Node.js 20 or later and a DATABASE_URL, preferably for a read-only role.

Can I swap it for the reference server?

Yes. The tool is still query with an sql argument, with some stricter rules such as rejecting multi-statement SQL.

How are results limited?

1,000 rows and 50,000 characters by default.

Is Postgres (read-only) free?

Yes. Postgres (read-only) is open source, so you can use and self-host it for free.

How do I add Postgres (read-only) to Claude Code?

Run this command in your terminal: claude mcp add postgres-mcp --env DATABASE_URL='<DATABASE_URL>' -- npx -y @contextflo/postgres-mcp

What are the best alternatives to Postgres (read-only)?

The closest alternatives to Postgres (read-only) are Midplane, PlatypusDB, Lorebase, Sovaria and model2data studio.

Alternatives to Postgres (read-only)

  1. Midplane

    MCP server

    Postgres gateway for AI agents with table grants, column masking and approval for writes

    Runs locally
    • Open source
    • 5 GitHub stars
    • Databases
  2. PlatypusDB

    MCP server

    Gives MCP clients access to your PlatypusDB database connections, scoped per agent

    Runs locally
    • Open source
    • Databases
  3. Lorebase

    MCP server

    Lets agents read and change a governed, versioned Postgres knowledge graph

    Runs locally
    • Open source
    • Knowledge and memory
  4. Sovaria

    MCP server

    Manage a Sovaria backend (Postgres, auth, storage, functions) from an AI assistant

    Not checked yet
    • 4 tools
    • Remote
    • Freemium
    • Databases
  5. Generate realistic connected test data, dbt projects and dashboards from a schema

    • Remote
    • Freemium
    • Databases
  6. semlayer

    MCP server

    Infers a semantic layer from your data warehouse and serves it to agents

    Runs locally
    • Free
    • Databases