Sw Postgres MCP logo

Sw Postgres MCP

Previews Postgres writes in rollback-only transactions before allowing exact, approval-gated execution.

Install Sw Postgres MCP

Run the project’s own setup commands, in order.

Setup steps from the project

sw-postgres-mcp installs with its own steps rather than a config we can generate, so these are copied as-is. Follow them in order and run the commands in a terminal. Source: github.com

  1. 1. Start the server
    docker compose up -d
    
  2. 2. Install
    npm install
    
  3. 3. Run
    npm run build
    
  4. 4. Start the server
    node dist/index.js
    
  5. 5. Start the server
    docker compose up
    
  6. 6. Start the server
    docker compose up -d --wait
    

Overview

The sw-postgres-mcp MCP server gives agents read access to PostgreSQL and a controlled workflow for data changes. Read operations use a PostgreSQL readonly role, while delete, insert, update, and migration requests run first in transactions that are rolled back. An execution call can commit only the previously previewed statement and parameters, with plan-token and affected-row checks. Reach for it when agents need database access but write operations must be reviewable and bounded.

Use cases

  • Inspect an allowlisted PostgreSQL schema
  • Run bounded read-only queries from an agent
  • Preview bulk updates or deletes before committing
  • Require human approval for database migrations
  • Detect changed rows before executing a saved plan

Key features

  • Read-only PostgreSQL queries
  • Schema and query-plan inspection
  • Rollback-based write previews
  • Human approval for risky plans
  • Statement fingerprint validation
  • Separate readonly and writer roles

Tools8

What Sw Postgres MCP lets your agent do. Expand a tool for its parameters.

Self-reported~537 tokens of context

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

15/15 checks healthy over the last 78d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

Last commit3mo agoMost recent push to the default branch.
Tools exposed8Callable tools this server registers over MCP.

How Sw Postgres MCP works

What sw-postgres-mcp MCP server does

The sw-postgres-mcp MCP server exposes eight MCP tools for inspecting PostgreSQL, analyzing read queries, previewing changes, and committing approved plans. Its central behavior is separating preview from execution: write requests run against the database, report what they would change, and then roll back rather than modifying persistent data.

The read tools are describe_schema, query, and explain_plan. Schema inspection returns tables, column types, foreign keys, and estimated row counts subject to the read allowlist. query accepts one read-only SELECT statement and returns columns, rows, and a row count. explain_plan returns PostgreSQL's JSON planner estimate without running the candidate statement.

Four tools create previews: delete_rows, insert_rows, update_rows, and run_migration. The first three report the exact affected-row count and a sample of returned rows. Migration previews cover one supported DDL statement and report its target, but do not return DML-style affected rows. execute_plan is the only tool that commits a change.

How it works

The sw-postgres-mcp MCP server uses separate PostgreSQL connection pools and roles. Reads use a readonly role with SELECT access, while preview and execution operations use a writer role. Database permissions therefore provide a safety boundary in addition to the server's SQL checks.

Each DML preview begins a transaction, runs the real statement with its values parameterized, captures the result, and rolls the transaction back. DDL previews use the same rollback approach; PostgreSQL DDL is transactional. A preview returns a plan token, statement, parameters, and a status such as previewed or awaiting_approval.

The token is derived from a SHA-256 fingerprint of the statement and parameters. During execution, the server recomputes that fingerprint and refuses changed input. It also rejects execution when the affected row set differs from the one observed during preview. Plans requiring approval are surfaced through a human-only approval interface bound to localhost; approval is not an MCP tool available to the agent.

Setup and configuration

The repository's quick-start sequence is to start the Docker services, install dependencies, run the test suite, and build the project:

Terminal
docker compose up -d
npm install
npm test
npm run build

Run the built server with node dist/index.js. Startup also launches the approval UI at http://127.0.0.1:4319/ and prints a per-session token once to stderr. Requests to that interface require the token as a bearer credential or query parameter.

Tools and capabilities

  • describe_schema: Lists allowed tables, typed columns, foreign keys, and estimated row counts.
  • query: Executes one allowlisted, read-only SELECT with optional parameters and a result limit.
  • explain_plan: Gets estimated cost and row count without executing the query.
  • delete_rows: Previews a parameterized deletion and returns affected-row details.
  • insert_rows: Previews positional multi-row inserts for a specified table and columns.
  • update_rows: Previews parameterized updates using a set object and where conditions.
  • run_migration: Previews one supported CREATE TABLE, ALTER TABLE, DROP TABLE, or index statement; human approval is always required.
  • execute_plan: Commits only a matching, previously previewed write.

Limitations and notes

Read calls are restricted to a single statement and the configured read allowlist. The readonly database role refuses mutating statements even if SQL text checks were bypassassed. DDL supplied to run_migration is raw SQL rather than parameterized DML, so its protection comes from transactional preview and mandatory human approval.

A preview is not an unrestricted transaction: it always rolls back until execute_plan succeeds. Plans can be refused when their affected-row count exceeds the configured hard maximum, and an approval-required plan cannot be committed until a human approves it through the localhost interface.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Sw Postgres MCP

sw-postgres-mcp is an MCP server that connects AI agents to PostgreSQL through schema inspection, read-only queries, query-plan analysis, previewable inserts, updates, deletes, and migrations. It uses separate readonly and writer roles, rolls back write previews, and commits only an exact plan through the execute_plan tool.

Install it by starting the Docker services, running npm install, testing with npm test, and building with npm run build. Run the built process with node dist/index.js, then configure the MCP stdio server for your client using the repository's config.example.json as a reference.

The server communicates over MCP stdio, and the repository includes a config.example.json reference. Its localhost approval UI runs alongside the server and requires the per-session token printed at startup.

No, execute_plan commits only a matching statement that was previously previewed. Delete, insert, update, and migration tools first run inside transactions that roll back, while the execution call rechecks the statement fingerprint and affected row set before committing.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewSw Postgres MCP AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/sw-postgres-mcp?style=directory)](https://allmcps.com/mcp/sw-postgres-mcp)
HTML Embed
<a href="https://allmcps.com/mcp/sw-postgres-mcp"><img src="https://allmcps.com/api/badge/sw-postgres-mcp?style=directory" alt="Sw Postgres MCP on AllMCPs" /></a>