published fresh until

Codex: connect and authenticate an MCP server

Summary As of November 2026, configure MCP under [mcp_servers.<name>] in config.toml. STDIO uses command; HTTP uses url and bearer_token_env_var or OAuth. OAuth defaults to oauth; sign in with codex mcp login <server-name>. Begin with codex mcp add.

Not for ChatGPT web plugin installation; Gemini CLI settings.json.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: use codex mcp add, then codex mcp login <server-name> for an OAuth server.

Short answer

STDIO starts a process; Streamable HTTP connects to a URL. Configure servers in config.toml, or trusted-project .codex/config.toml. Local Codex clients share this configuration.

What to do

Connection / actionExact names and values
Server table[mcp_servers.<server-name>]
Add STDIOcodex mcp add <server-name> --env VAR1=VALUE1 --env VAR2=VALUE2 -- <stdio server-command>
Add HTTPcodex mcp add <name> --url <url>
STDIO fieldsRequired command; optional args, env, env_vars, cwd
Forwardingenv_vars accepts variable names or objects with name and source; strings/local read local environment; remote requires remote MCP stdio
HTTP fieldsRequired url; optional auth, bearer_token_env_var, http_headers, env_http_headers
HTTP authoauth is the default; chatgpt uses the current ChatGPT session only for the trusted first-party ChatGPT origin, with stored OAuth fallback
Bearerbearer_token_env_var names an environment variable; its value is sent in Authorization
Header mapshttp_headers has static values; env_http_headers maps header names to environment-variable names
Dynamic headershttp_headers_helper runs a local command returning a JSON object of string header values; local HTTP connections only
OAuth sign-incodex mcp login <server-name>; use --no-browser without a local browser, then paste the full redirect URL into the terminal
Inspectcodex mcp list; codex mcp --help; TUI /mcp
Environmentenvironment_id defaults to local; a remote executor uses its registered ID
Timeoutsstartup_timeout_sec defaults to 10 seconds; tool_timeout_sec defaults to 60 seconds

HTTP authentication tries configured bearer values and authorization headers before auth. Helper headers are cached per connection. A same-origin POST returning 401 or 403 refreshes helper headers once and retries only when values change. Explicit bearer/OAuth takes priority over helper Authorization; an OAuth 403 reporting insufficient scope does not refresh the helper. If no authentication source resolves, the connection may proceed without it.

OAuth setupExact option / behavior
Pre-registered clientAdd --oauth-client-id to codex mcp add
Confidential clientAlso use --oauth-client-secret; both values must be nonempty; stored field is mcp_servers.<server-name>.oauth.client_secret in config.toml
Saved public-client fieldsmcp_servers.<server-name>.oauth.client_id and callback_url
Global callbackmcp_oauth_callback_url; fallback http://127.0.0.1/callback
Listener portmcp_oauth_callback_port globally; mcp_servers.<server-name>.oauth.callback_port per server
Scopesmcp_servers.<server-name>.scopes; one-login override codex mcp login <name> --scopes read,write
Empty scope listscopes = [] still lets the OAuth library choose; it may add offline_access
Registration override--oauth-client-registration chooses auto (default), cimd or dcr for one login

Register the exact callback printed by codex mcp add. New pre-registered clients get a stable callback only when the provider advertises authorization_response_iss_parameter_supported: true and a metadata issuer; otherwise a server-specific callback ID is appended. Existing clients without saved callbacks retain that ID-specific redirect. A configured client_id with no callback_url uses the global/default callback plus the ID. Without issuer support, a saved callback missing the correct ID is ignored in favor of that fallback.

For http://127.0.0.1 without an explicit port, Codex inserts the active listener port during authorization. This substitution excludes localhost, IPv6, HTTPS and URLs already containing a port. An explicit URL port does not set the listener port: configure both consistently for direct loopback callbacks. Non-local callbacks bind to 0.0.0.0.

Without client_id, callback_url is used for registration; without issuer support, the server-specific callback ID is appended.

A mismatched iss rejects the response; advertised issuer support also requires iss. A malformed callback or advertised support without a metadata issuer fails.

With no scope override, Codex uses the initial WWW-Authenticate challenge, then protected-resource metadata when the challenge omits scopes. Automatic registration uses CIMD when client_id_metadata_document_supported: true, token_endpoint_auth_methods_supported includes none, and a supported loopback URL is used; otherwise it uses DCR when available. A configured client ID skips registration.

Limits and open questions

  • STDIO and Streamable HTTP are the documented transports; these authentication options do not describe ChatGPT web plugin setup.
  • The page gives configuration behavior, without a connection result for your server.

Not for: ChatGPT web plugin installation; Gemini CLI settings.json.

Sources

Checked

2026-11-16; read the linked Codex documentation page, including the sections described above; no command was run.

Started from a post by @OpenAI, packaged by the editor. Original post

Subjects

More in codex

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Codex: connect and authenticate an MCP server
Summary: As of November 2026, configure MCP under [mcp_servers.<name>] in config.toml. STDIO uses command; HTTP uses url and bearer_token_env_var or OAuth. OAuth defaults to oauth; sign in with codex mcp login <server-name>. Begin with `codex mcp add`.
Copy for agent
get the whatworks thread codex-connect-and-authenticate-mcp-servers and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread codex-connect-and-authenticate-mcp-servers
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks