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.
CREATE ROLE contextflo_ro LOGIN PASSWORD '<generated>';
GRANT CONNECT ON DATABASE mydb TO contextflo_ro;
GRANT USAGE ON SCHEMA public TO contextflo_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO contextflo_ro;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO contextflo_ro;
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:
npx -y @contextflo/postgres-mcp postgresql://contextflo_ro:pass@replica-host:5432/mydb
In ~/.codex/config.toml (or a project .codex/config.toml):
[mcp_servers.postgres]
command = "npx"
args = ["-y", "@contextflo/postgres-mcp", "postgresql://contextflo_ro:pass@replica-host:5432/mydb"]
@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:
[mcp_servers.contextflo]
url = "https://mcp.contextflo.com/mcp"
codex mcp login contextflo
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.
See it on your own data.
Connect your warehouse and your team can ask Claude about it the same day, without waiting on a data team. Want a walkthrough first? Grab 20 minutes.
Book a 20-minute callSee how teams use Contextflo
Related posts
Keep reading

Conversational analytics: 5 ways to set it up, compared
7 min read

How to connect Claude to BigQuery? What works and what doesn't in 2026
8 min read

How to connect Claude to Postgres without giving it write access
9 min read

How to build a BI dashboard with Claude that your team can actually trust
8 min read

How to give Claude read-only access to your database (it isn't always the default)
7 min read

You connected your warehouse to Claude, now what?
5 min read

ClickHouse MCP: how to connect ClickHouse to Claude, Cursor or Codex
6 min read

Query BigQuery from the Codex CLI with MCP
5 min read

Run ClickHouse queries from Codex with MCP
6 min read

