# sw-postgres-mcp

> sw-postgres-mcp is an open-source MCP server for databases. Safe-write Postgres MCP server with preview-before-execute writes and rollback safety. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Repository:** https://github.com/jpka/sw-postgres-mcp
- **MCP Registry name:** io.github.jpka/sw-postgres-mcp
- **Categories:** databases
- **Listing updated:** 2026-11-13

## About

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

## Install

### Claude Code (Terminal)

```sh
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
```

### Claude Desktop (claude_desktop_config.json)

```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>"
      }
    }
  }
}
```

### Cursor (~/.cursor/mcp.json)

```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>"
      }
    }
  }
}
```

### VS Code (.vscode/mcp.json)

```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>"
      }
    }
  }
}
```

### Windsurf (~/.codeium/windsurf/mcp_config.json)

```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>"
      }
    }
  }
}
```

### Other clients (your client's MCP settings (most use this shape))

```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>"
      }
    }
  }
}
```

## 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

- [Midplane](https://ai-powered.com/mcp/midplane): Midplane is an open-source MCP server for databases.
- [PlatypusDB](https://ai-powered.com/mcp/platypusdb): PlatypusDB is an open-source MCP server for databases.
- [Lorebase](https://ai-powered.com/mcp/lorebase): Lorebase is an open-source MCP server for knowledge and memory.
- [Sovaria](https://ai-powered.com/mcp/sovaria): Sovaria is a freemium MCP server for databases.
- [model2data studio](https://ai-powered.com/mcp/model2data-studio): model2data studio is a freemium MCP server for databases.
- [semlayer](https://ai-powered.com/mcp/semlayer): semlayer is a free MCP server for databases.
- [bricksentry](https://ai-powered.com/mcp/bricksentry): bricksentry is an open-source MCP server for databases.
- [MCP Toolbox for Databases](https://ai-powered.com/mcp/mcp-toolbox-for-databases-2): MCP Toolbox for Databases is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/sw-postgres-mcp
