SequelPG

How it works

An assistant asks questions like “which tables reference orders?” or “how many signups did we have last week?”. To answer, it calls tools that SequelPG provides over the Model Context Protocol: list connections and schemas, describe a table, get an object’s DDL, run a query, explain a query.

The assistant starts SequelPG’s own executable with --mcp-stdio. That process is only a bridge: it forwards messages to the running SequelPG app over a private Unix socket, and opens SequelPG in the background if it isn’t running. The app does the work with the connections you already saved, including SSH tunnels and SSL settings.

AI client ──stdio──▶ SequelPG --mcp-stdio  (bridge)
                         │  ~/Library/Application Support/SequelPG/mcp.sock
                         ▼
                    SequelPG.app ──▶ PostgreSQL
  • Passwords never leave SequelPG. They stay in your Keychain; the assistant only sees connection names, hosts, ports, database and user names.
  • No network port. The socket is readable only by your macOS user, and SequelPG accepts only its own executable on the other end.
  • Off by default. The server is off, every connection is hidden, and each new client needs your approval.
  • Your windows aren’t affected. MCP queries use their own database sessions, so they never interrupt a query you’re running.

Whatever the assistant reads — schema, query results — becomes part of its conversation and is sent to the assistant’s model provider. Share only databases you’re comfortable sending there.

Requirements

  • SequelPG 0.4.0 or later, in your Applications folder. Clients store the path to SequelPG; macOS runs a freshly downloaded app from a temporary location until you move it, and SequelPG warns you in Settings if that’s the case.
  • An MCP client: Claude Code, Claude Desktop, Cursor, VS Code with GitHub Copilot, or any other client that can start a local (stdio) MCP server.
  • A saved SequelPG connection to the database you want to share.

Step 1 — Turn on the MCP server

  1. Open SequelPG → Settings (⌘,) and choose the MCP tab.
  2. Turn on Enable MCP server. Status changes to Running, and later shows how many clients are connected.
SequelPG Settings, MCP tab: Enable MCP server switched on, status Running, and Add buttons for Claude Code, Claude Desktop and Cursor
Settings → MCP with the server running.

The server runs while SequelPG is open. When a client needs it and SequelPG is closed, the bridge opens SequelPG in the background (no window) and waits for the server.

Step 2 — Create a read-only role

SequelPG runs every assistant query in a read-only transaction that is always rolled back. That stops INSERT, UPDATE, DELETE and DDL, but it isn’t a sandbox: a function with side effects (for example pg_terminate_backend, or dblink_exec if installed) still runs inside it. The real boundary is the PostgreSQL role, so give the assistant a role that can only read.

-- Run as an administrator, once per database the assistant may read.
CREATE ROLE ai_reader LOGIN PASSWORD 'choose-a-strong-password';
GRANT CONNECT ON DATABASE app TO ai_reader;

-- Read every table and view in the public schema
GRANT USAGE ON SCHEMA public TO ai_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO ai_reader;

-- …and tables created later by the role running this script
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO ai_reader;

Replace app with your database name, and repeat the schema lines for every schema the assistant should see. ALTER DEFAULT PRIVILEGES applies to tables created later by the role that runs it; add FOR ROLE <owner> if another role creates your tables (for example your migration user).

On PostgreSQL 14 and later there is a shortcut for “read everything”:

-- PostgreSQL 14+: read access to every table in every schema
GRANT pg_read_all_data TO ai_reader;

Optional settings that make the role safer still. SequelPG already sets a 30-second timeout per query; these apply to the role everywhere:

-- Optional hardening
ALTER ROLE ai_reader SET default_transaction_read_only = on;
ALTER ROLE ai_reader SET statement_timeout = '30s';
ALTER ROLE ai_reader CONNECTION LIMIT 10;

Then create a new connection in SequelPG (+ on the start page) with ai_reader as the username, and check it with Test Connection. Keep your normal connection for your own work.

Step 3 — Share the connection

Select the connection, scroll to AI Assistants, and set MCP Access:

MCP AccessWhat assistants get
Off (default)Nothing. The connection doesn’t appear in any tool.
Read-onlySchema browsing and read-only queries. Superusers and roles that can run programs or read and write files on the server are refused.
Read-only, allow superuserThe same, without the role check. For local development databases only — see Superusers.
Connection form, AI Assistants section with MCP Access set to Read-only
The MCP Access setting in the connection form.

Save the connection. Settings → MCP lists it under Shared Connections. Sharing is stored in your Keychain, so another program can’t turn it on by editing SequelPG’s preferences.

Step 4 — Add SequelPG to your AI client

In Settings → MCP → Connect a Client, click Add next to your client. SequelPG writes the entry with the path of the copy you’re running. The examples below assume SequelPG is in /Applications; the footer of that section shows the exact path on your Mac.

Claude Code

Add runs this command in a login shell, so it finds claude wherever your shell profile puts it. You can also run it yourself (Copy Claude Code Command copies it):

claude mcp add --scope user sequelpg -- /Applications/SequelPG.app/Contents/MacOS/SequelPG --mcp-stdio

--scope user makes SequelPG available in every project. Start a new Claude Code session, then check it with claude mcp list in Terminal or /mcp inside a session.

Claude Desktop

Add merges a sequelpg entry into ~/Library/Application Support/Claude/claude_desktop_config.json, keeping your other servers and saving the previous file as claude_desktop_config.json.bak. Quit Claude Desktop (⌘Q) and open it again. To edit the file by hand, add:

{
  "mcpServers": {
    "sequelpg": {
      "args": ["--mcp-stdio"],
      "command": "/Applications/SequelPG.app/Contents/MacOS/SequelPG"
    }
  }
}

Cursor

Add writes the same entry to ~/.cursor/mcp.json (global, for every project), with a .bak backup. Restart Cursor; SequelPG appears in Cursor’s MCP settings with its tools.

VS Code (GitHub Copilot)

VS Code uses a servers key instead of mcpServers. Run MCP: Open User Configuration from the Command Palette for all workspaces, or create .vscode/mcp.json in one workspace, and add:

{
  "servers": {
    "sequelpg": {
      "type": "stdio",
      "command": "/Applications/SequelPG.app/Contents/MacOS/SequelPG",
      "args": ["--mcp-stdio"]
    }
  }
}

Then use SequelPG’s tools from Copilot Chat in agent mode.

Other clients

Any client that starts local (stdio) servers works. Copy JSON Config copies the mcpServers block above. If the client asks for the parts separately:

Namesequelpg
Typestdio
Command/Applications/SequelPG.app/Contents/MacOS/SequelPG
Arguments--mcp-stdio

No environment variables or API keys are needed. If you move SequelPG later, click Add again so the client gets the new path.

Step 5 — Approve the client

The first time an assistant calls a SequelPG tool, SequelPG comes to the front and asks: “Allow ‘claude-code’ to use your SequelPG connections?” (with the name the client reports). Click Allow. The client is remembered and listed under Allowed Clients in Settings → MCP.

If you click Don’t Allow, that client’s tool calls fail until you quit and reopen SequelPG; you’re asked again then.

The client name is what the client says about itself. The approval protects you from surprises, not from a program on your Mac that pretends to be an approved client — that is what the read-only role is for.

Try it

Ask your assistant things like:

  • “Which PostgreSQL connections can you see in SequelPG?”
  • “Describe the orders table and the tables it references.”
  • “Show me the DDL of the refresh_stats function.”
  • “How many users signed up per day over the last two weeks?”
  • “Why is this query slow? Explain it with analyze.”
  • “Write a migration that adds an index for this query” — the assistant reads the schema; you run the migration yourself.

Tools

Every tool except list_connections takes a connection (id or exact name from list_connections) and an optional database to use instead of the connection’s default.

ToolWhat it does
list_connectionsShared connections: id, name, host, port, database, user, SSH tunnel, access.
list_databasesDatabases on the connection’s server.
list_schemasSchemas in a database.
list_objectsTables, views, materialized views, functions, sequences, types and other objects in a schema.
describe_tableColumns (types, nullability, defaults, primary key), indexes, constraints including foreign keys, triggers, and the planner’s row estimate.
get_ddlThe CREATE statement for a table, view, materialized view, function, procedure, trigger function, aggregate, sequence, type, domain or foreign table.
run_queryRuns one statement and returns the rows as a table: 200 rows by default, up to 1000 with max_rows.
explain_queryThe execution plan; with analyze: true the statement runs (read-only) to report actual timings.

Limits & safety

  • One statement per call, and only SELECT, WITH, VALUES, TABLE, SHOW or EXPLAIN. Everything else — DO, CALL, COPY, SET, transaction control, maintenance commands — is rejected before it reaches the server.
  • It runs in BEGIN READ ONLY and is always rolled back, so writes fail even inside a CTE or a function.
  • 30-second timeout per query, enforced by the server (statement_timeout) and by SequelPG.
  • Results are capped (1000 rows, about 100,000 characters; long values are shortened), and the assistant is told when rows were left out.
  • Advisory locks a query takes are released afterwards; a cancelled or failed query closes its database connection instead of reusing it.
  • At most 4 tool calls run at once and 6 database sessions stay open; idle sessions close after 5 minutes.

Superusers

With Read-only, SequelPG checks the role when it connects and refuses superusers and members of pg_execute_server_program, pg_write_server_files and pg_read_server_files. A read-only transaction can’t contain those privileges: through functions, such a role can end other sessions and read or write files on the database server. The assistant then gets an error that names the role and explains what to change.

Local development databases often have only the postgres superuser. If you accept the risk for such a database, set MCP Access to Read-only, allow superuser. The statement allowlist, read-only transaction and timeout still apply, but an assistant can do anything the role can through functions.

Connection form, MCP Access set to Read-only, allow superuser, with a warning that superusers are allowed
The form warns you when superusers are allowed.

Never use it for production or shared databases.

Manage access

  • Stop sharing a connection: set its MCP Access to Off. It disappears from the tools immediately.
  • Remove a client: click Revoke next to it under Allowed Clients. It is asked again on its next call.
  • Turn everything off: turn off Enable MCP server. Clients get a message telling the user to turn it back on in Settings → MCP.
  • Remove SequelPG from a client: claude mcp remove --scope user sequelpg for Claude Code; for the others, delete the sequelpg entry from their config file.

Troubleshooting

SymptomFix
“SequelPG’s MCP server is not available”Open SequelPG, choose Settings → MCP and turn on Enable MCP server.
“No connections are shared with MCP”Set MCP Access to Read-only on a connection and save it.
“The role … is a superuser or can run programs…”Use a read-only role for that connection, or, for a local development database only, allow superusers.
“… statements are not allowed”Only single SELECT/WITH/VALUES/TABLE/SHOW/EXPLAIN statements run. Make changes yourself in the SQL editor.
Tool calls fail right after you clicked Don’t AllowQuit and reopen SequelPG; it asks again on the next call.
The client can’t start the server after you moved or updated SequelPGClick Add again in Settings → MCP so the client gets the current path. If Settings warns that macOS runs SequelPG from a temporary location, move it to Applications first.
“The claude command wasn’t found”Install Claude Code, or run the command from Copy Claude Code Command in Terminal.
“… isn’t valid JSON, so it was left unchanged”The client’s config file has a syntax error. Fix it, or add the entry by hand with Copy JSON Config.
Query timed outQueries stop after 30 seconds. Ask the assistant to add a LIMIT or a narrower WHERE.
Connection fails with an authentication or SSL errorCheck the same connection with Test Connection in SequelPG; assistants use exactly those settings and the password saved in your Keychain.

Back to the documentation. What’s new in this release: SequelPG v0.4.0.