Skip to content
MCP server

sw-postgres-mcp

Safe-write Postgres MCP server with preview-before-execute writes and rollback safety.

Runs locallyStatus and history
Install
Pricing
Open source
Runs
Locally
Version
0.3.1
Listing updated
4 days ago

About sw-postgres-mcp

sw-postgres-mcp is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.

Install

Run in a terminal

claude mcp add sw-postgres-mcp --env DATABASE_URL_READONLY='<DATABASE_URL_READONLY>' --env DATABASE_URL_WRITER='<DATABASE_URL_WRITER>' -- npx -y sw-postgres-mcp

Add to claude_desktop_config.json

{
  "mcpServers": {
    "sw-postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "<DATABASE_URL_READONLY>",
        "DATABASE_URL_WRITER": "<DATABASE_URL_WRITER>"
      }
    }
  }
}

Add to ~/.cursor/mcp.json

{
  "mcpServers": {
    "sw-postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "<DATABASE_URL_READONLY>",
        "DATABASE_URL_WRITER": "<DATABASE_URL_WRITER>"
      }
    }
  }
}

Add to .vscode/mcp.json

{
  "servers": {
    "sw-postgres-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "<DATABASE_URL_READONLY>",
        "DATABASE_URL_WRITER": "<DATABASE_URL_WRITER>"
      }
    }
  }
}

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

{
  "mcpServers": {
    "sw-postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "<DATABASE_URL_READONLY>",
        "DATABASE_URL_WRITER": "<DATABASE_URL_WRITER>"
      }
    }
  }
}

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

{
  "mcpServers": {
    "sw-postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "<DATABASE_URL_READONLY>",
        "DATABASE_URL_WRITER": "<DATABASE_URL_WRITER>"
      }
    }
  }
}

Configuration

  • DATABASE_URL_READONLYPostgres connection string for the read-only role.Required
  • DATABASE_URL_WRITERPostgres connection string for the writer role.Required

Pricing

Open source

sw-postgres-mcp FAQ

Is sw-postgres-mcp free?

Yes. sw-postgres-mcp is open source, so you can use and self-host it for free.

How do I add sw-postgres-mcp to Claude Code?

Run this command in your terminal: claude mcp add sw-postgres-mcp --env DATABASE_URL_READONLY='<DATABASE_URL_READONLY>' --env DATABASE_URL_WRITER='<DATABASE_URL_WRITER>' -- npx -y sw-postgres-mcp

What are the best alternatives to sw-postgres-mcp?

The closest alternatives to sw-postgres-mcp are Midplane, PlatypusDB, Lorebase, Sovaria and model2data studio.

Alternatives to sw-postgres-mcp

  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