Contextflo is now SOC 2 Type II compliant. See more

Add Postgres to Codex as an MCP server

Connect Codex to Postgres over MCP. Run the read-only @contextflo/postgres-mcp server from config.toml, or use Contextflo for a team with an audit trail.

Updated

Jump to a section

Codex runs local MCP servers, so Postgres is a short config away. Run a read-only Postgres MCP server on your machine, or connect the database to Contextflo and give Codex one URL. Either way, make a read-only role first.

Make a read-only role

Both options start here. Point it at a read replica if you have one.

Loading code sample...

Option 1: a local Postgres MCP server in Codex

@contextflo/postgres-mcp is MIT licensed and enforces read-only in four layers. Run it with npx:

Loading code sample...

In ~/.codex/config.toml (or a project .codex/config.toml):

Loading code sample...

@bytebase/dbhub is an alternative. Skip @modelcontextprotocol/server-postgres. It is archived and has a SQL-injection bypass.

Option 2: Contextflo

In Contextflo, go to Data Sources, then Add data source, and choose Postgres. Paste a postgresql:// connection string for the read-only role. It works with RDS, Supabase, Neon, Cloud SQL, Azure, Railway, Render and self-hosted databases. Pick the tables and invite your team.

In Codex:

Loading code sample...
Loading code sample...

codex mcp list shows what is connected. Contextflo runs SELECT only.

Which one to use

Just you, in your own terminal: Option 1.

Your team asks too: Contextflo. It writes table and column descriptions, your team saves shared definitions, each person gets their own table access, and you get an audit trail of prompts and the SQL that ran. pg_stat_statements has query text, not the person.

More servers compared in best Postgres MCP servers. On Claude? See Claude with Postgres.

You do the modeling, we do the rest. Connect Postgres free.

FAQ

Can Codex connect to a local Postgres MCP server?

Yes. Codex runs local stdio servers. Add a [mcp_servers.name] table with command and args to ~/.codex/config.toml, and put credentials in [mcp_servers.name.env] when the server needs them.

Should I use the official modelcontextprotocol Postgres server with Codex?

No. @modelcontextprotocol/server-postgres is archived and has a known SQL-injection bypass. Use @contextflo/postgres-mcp or @bytebase/dbhub instead.

Which Postgres hosts work with Contextflo?

RDS, Supabase, Neon, Cloud SQL, Azure, Railway, Render and self-hosted Postgres. Contextflo takes a postgresql:// connection string.

Why point Codex at a read replica?

An agent can write expensive queries. A replica keeps them away from your primary. Pair it with a read-only role so nothing can write.