How to connect Postgresql to Codex

  • Codex gets 13 Postgresql tools through one Metorial MCP URL.
  • Setup is 3 steps; teammates then sign in with SSO.
  • You need the Codex CLI, IDE extension or ChatGPT desktop app.

What Codex can do with Postgresql

Ask your agent in plain language. Each of these maps to a real tool on the server.

  • Ask Codex to use the manage indexes tool in Postgresql
  • Ask Codex to use the update rows tool in Postgresql
  • Ask Codex to use the execute sql query tool in Postgresql
  • Ask Codex to use the manage schemas tool in Postgresql
  • Ask Codex to use the manage views tool in Postgresql

Add the Postgresql MCP server to Codex

Run these once. Afterwards, everyone you give access to signs in the same way.

  1. 1. Enable Postgresql in Metorial

    In your Metorial portal, enable the Postgresql MCP server and sign in with the account that owns the data. Access stays governed by your team policies.

  2. 2. Add the server and sign in

    The Codex CLI, IDE extension and ChatGPT desktop app share this config.

    codex mcp add metorial --url <your-magic-mcp-url>
    codex mcp login metorial
  3. 3. Check the connection

    Type /mcp in Codex to see Metorial and its Postgresql tools.

Give your team Postgresql in Codex

Once Postgresql is enabled in Metorial, teammates sign in with SSO and get the same connection in Codex, with only the tools their role allows.

One link covers every app you approve. See how the MCP gateway handles access, roles and audit logs for the whole company.

Postgresql tools available in Codex

Full descriptions and inputs are on the Postgresql MCP server page.

  • List Tables: List all tables in the PostgreSQL database, optionally filtered by schema.
  • Delete Rows: Delete rows from a PostgreSQL table based on a WHERE condition.
  • List Schemas: List all schemas in the PostgreSQL database with their table counts and sizes.
  • Insert Rows: Insert one or more rows into a PostgreSQL table.
  • Manage Table: Create, alter, or drop a PostgreSQL table.
  • Describe Table: Get detailed schema information for a specific table, including columns, data types, constraints, indexes, and foreign keys.
  • Manage Roles: Manage PostgreSQL roles and their privileges.
  • Manage Indexes: Create or drop indexes on PostgreSQL tables.
  • Update Rows: Update rows in a PostgreSQL table based on a WHERE condition.
  • Execute SQL Query: Execute an arbitrary SQL query against the PostgreSQL database.
  • Manage Schemas: Create, rename, or drop PostgreSQL schemas.
  • Manage Views: Create and drop PostgreSQL views or materialized views, and refresh materialized views.
  • Select Query: Run a read-only SELECT query against the PostgreSQL database.

Using Postgresql tools in Codex

What to expect once Postgresql is connected.

  • Limit which Postgresql tools Codex sees with enabled_tools and disabled_tools on the metorial server in config.toml.
  • Set default_tools_approval_mode to auto, prompt, writes or approve. writes prompts only for tools that are not marked read-only.
  • Type /mcp in the composer to see the connected servers.
  • Override the approval behavior for a single Postgresql tool with tools.<tool>.approval_mode.

Troubleshooting Codex

Metorial is listed but tools are missing
Codex can connect without credentials and then see nothing. Run codex mcp login metorial to complete the OAuth sign-in.
Metorial times out at startup
Codex waits 10 seconds by default. Raise startup_timeout_sec under [mcp_servers.metorial] in ~/.codex/config.toml.
Long tool calls fail after a minute
The default tool timeout is 60 seconds. Raise tool_timeout_sec for the metorial server in config.toml.

Based on the Codex MCP documentation.

Frequently asked questions

Common questions about connecting Postgresql to AI agents with Metorial.

  1. Does Codex support the Postgresql MCP server?
    Yes. Codex connects to the Postgresql MCP server through one CLI command, pointed at your Metorial URL. You need the Codex CLI, IDE extension or ChatGPT desktop app.
  2. No. You sign in to Postgresql once through Metorial, and Codex uses that connection. No API keys go into Codex's settings.
  3. All 13 Postgresql tools your team allows, such as List Tables, Delete Rows, List Schemas. Admins can narrow that list per team.
  4. Yes. Role-based access control decides who can use Postgresql and which of its tools appear in Codex, and every call is logged with the person's identity.
  5. Codex can connect without credentials and then see nothing. Run codex mcp login metorial to complete the OAuth sign-in.