AI Agents

How to Connect Codex to WhatsApp via MCP

WhatsMCP Engineering
Sep 21, 2026 · 12 min read

OpenAI's Codex already sits where you work — in the terminal, in your editor and in the ChatGPT desktop app — reading the repository, running commands and writing code. Connect it to WhatsApp and it can also read the message a user complained about, text you when a long job finishes, or run a support-bot prototype against a real number, all without leaving the session.

This guide shows how to connect Codex to WhatsApp through WhatsMCP, a hosted MCP server for your own WhatsApp numbers. Setup is one command with OAuth sign-in, or a short config entry with an API key, and the same configuration then serves the Codex CLI, the IDE extension and the ChatGPT desktop app. After that: read-only access, approval rules, prompts that work, and fixes for what usually goes wrong. The commands, output and config below were checked against Codex CLI 0.163.0 in October 2026.

Diagram: Codex — the CLI, the IDE extension or the ChatGPT desktop app — connects over MCP to api.whatsmcp.com/mcp, which reaches your WhatsApp number as a linked device or through Meta's Cloud API

What you need

  • A WhatsMCP workspace. Sign up free.
  • A linked WhatsApp number.
    • Personal number: at Add a number (setup opens it; later it's Fleet → Add Number) choose Personal WhatsApp → Link a device via QR and scan the code from WhatsApp → Settings → Linked devices → Link a device. The first Personal number in a workspace takes the free line automatically; any other stays suspended until you choose a plan. New Personal numbers run through WhatsMCP's Default Random VPN unless you set your own WireGuard or SOCKS5 egress.
    • Official Business number: choose WhatsApp Business → Connect with Facebook, then a Business plan — the number stays suspended until it has one, and your workspace's first Business plan starts with a 7-day free trial. Not sure which kind you need? Read Personal WhatsApp vs WhatsApp Business API.
  • Codex — the Codex CLI, the Codex extension for VS Code, Cursor or Windsurf, or the ChatGPT desktop app. All three read one MCP configuration, so you set WhatsMCP up once per machine.
  • The endpoint: https://api.whatsmcp.com/mcp (Streamable HTTP).

The WhatsMCP console Pair device page: a QR code above a progress indicator reading code, scanned, syncing, ready

Connect Codex to WhatsApp in one command

In a terminal, run:

codex mcp add wamcp --url https://api.whatsmcp.com/mcp

wamcp is just the name Codex will use for the server. Codex saves it to ~/.codex/config.toml, sees that WhatsMCP supports OAuth, and starts the sign-in at once:

Added global MCP server 'wamcp'.
Detected OAuth support. Starting OAuth flow…
Authorize `wamcp` by opening this URL in your browser:
https://console.whatsmcp.com/oauth/authorize?response_type=code&client_id=https%3A%2F%2Fchatgpt.com%2Foauth%2Fcodex%2Fclient.json&…

Open the link if your browser didn't open by itself. The WhatsMCP console shows an Allow access page, and two things on it are worth knowing before you click:

  • It names the client chatgpt.com, "verified by chatgpt.com". Codex identifies itself with a client metadata document that OpenAI hosts on chatgpt.com, and WhatsMCP shows that verified host rather than a name the client picked for itself. It's Codex.
  • It warns that the code goes to a program running on this computer. Codex is waiting for the answer on 127.0.0.1. You started it a moment ago, so carry on.

Click Allow and you're connected. Nothing secret lands in the config file, which holds only:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"

Codex keeps the OAuth tokens in its own credential store — your operating system's keyring where one is available — and refreshes them by itself. The token is bound to WhatsMCP's endpoint, its refresh token rotates on every use, and you can revoke Codex on its own, without touching your other clients, at Console → Connections.

To check, run codex mcp list. Its Auth column reads Not logged in until the sign-in completes; if you closed the browser too early, codex mcp login wamcp starts it again. Inside a Codex session, /mcp lists the servers that are connected.

No browser on this machine? Use --no-browser

On a server, in a container or over SSH, have Codex print the link instead of waiting for a local browser. If codex mcp add has already started a sign-in there, press Ctrl+C — the server entry is saved by then — and run:

codex mcp login wamcp --no-browser

Open the printed link in any browser where you can sign in to the WhatsMCP console and click Allow. The browser then tries to load a 127.0.0.1 address that doesn't exist on that machine; that's expected. Copy the full URL from the address bar and paste it at Codex's Callback URL (input hidden): prompt, and Codex completes the sign-in from there.

Give Codex read-only access

By default Codex asks for every permission WhatsMCP offers, and the consent page grants the ones your plan includes. For an assistant that should only read, ask for less:

codex mcp login wamcp --scopes wa:accounts,wa:read

The consent page then lists just List and inspect your paired WhatsApp numbers and Read message history under It will be able to. Below, under You can also allow, it offers the rest of your plan, with Send messages from your numbers already ticked because most people connect an agent in order to send. Untick it for a read-only connection.

The consent page for a read-only Codex sign-in: chatgpt.com, verified by chatgpt.com, may list your numbers and read message history; sending, pairing and webhooks are offered but unticked

WhatsMCP enforces the grant on every call, not only at sign-in. A tool outside it is refused even when your plan includes it, and the refusal tells Codex which permission is missing and how to add it. To change your mind later, run codex mcp logout wamcp, then codex mcp login wamcp and tick what you need.

Permission What the consent page says Tools it unlocks, for example
wa:accounts List and inspect your paired WhatsApp numbers wa_list_accounts, wa_get_plan, wa_unpair_account
wa:read Read message history wa_list_messages, wa_get_chat, wa_get_media, wa_list_groups
wa:send Send messages from your numbers wa_send_message, wa_react, wa_create_group, wa_create_template
wa:pair Pair a new WhatsApp number wa_pair_account, wa_pair_status
wa:webhooks Configure inbound webhooks wa_set_webhook, wa_get_webhook

Two more permissions route a number through your own WireGuard tunnel or SOCKS5 proxy. Every connection gets wa:accounts and wa:read as a floor, and wa:accounts includes unpairing a number — so for a strictly read-only assistant, also limit the tools Codex sees, as shown in Trim the tool list below.

Codex IDE extension and the ChatGPT desktop app

The CLI, the IDE extension and the ChatGPT desktop app read the same ~/.codex/config.toml. If you ran codex mcp add on this machine, WhatsMCP is already configured; restart the extension or the app and it appears. To add it without a terminal:

  • IDE extension (VS Code, Cursor, Windsurf): open the gear menu → MCP servers → Add server. Enter wamcp as the name, choose Streamable HTTP, paste https://api.whatsmcp.com/mcp, save, and select Restart extension. Then select Authenticate to sign in.
  • ChatGPT desktop app (macOS, Windows and Linux): open Settings → MCP servers → Add server, fill in the same three fields, save and select Restart. Authenticate signs you in, and typing /mcp in the composer shows the connected servers.

Three ways to add WhatsMCP to Codex: codex mcp add with OAuth in a terminal, the Add server dialog in the desktop app or IDE extension, or a config.toml entry with an API key from an environment variable

You can also keep the server with a single repository by putting the same table in that project's .codex/config.toml; Codex reads project configuration only for projects you have marked as trusted.

ChatGPT on the web is a different product surface: it doesn't read config.toml and reaches remote MCP servers through plugins instead. For that, follow Connect WhatsApp to ChatGPT.

Use an API key instead

OAuth is the better default on your own laptop. For CI, a remote box, or anywhere a browser sign-in is awkward, use a key from Console → API keys — keys look like wamcp_live_… and are shown once — and keep it in the environment rather than in the file:

export WHATSMCP_API_KEY=wamcp_live_…
codex mcp add wamcp --url https://api.whatsmcp.com/mcp --bearer-token-env-var WHATSMCP_API_KEY

With a key configured, Codex skips the sign-in, answers Added global MCP server 'wamcp'., and writes:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
bearer_token_env_var = "WHATSMCP_API_KEY"

codex mcp list then shows Bearer token in the Auth column, and Codex sends the key as Authorization: Bearer … on every request. If you'd rather use WhatsMCP's x-api-key header, map it from the environment instead:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
env_http_headers = { "x-api-key" = "WHATSMCP_API_KEY" }

Three things to know about keys:

  • A key carries your whole plan. It isn't narrowed the way an OAuth grant is, so use the approval and tool settings below to limit what Codex does with it.
  • Use one key per machine or pipeline, so you can revoke one at Console → API keys without breaking the others.
  • Desktop apps may not see your shell's variables. An app started from the Dock, the Start menu or a launcher usually doesn't load your shell profile, so a key that works in the terminal can be missing there. In the ChatGPT desktop app, sign in with OAuth instead.

Decide what Codex may do without asking

Every WhatsMCP tool tells clients whether it only reads, and whether it destroys something. Codex uses those hints. It always asks before a destructive tool: deleting a message, a group, a template or a webhook, leaving a group, removing members, unpairing a number, replacing your profile photo, or hanging up an AI call.

For everything else, set the server's approval mode. With writes, Codex runs WhatsMCP's 19 read-only tools freely and asks before any of the 27 that send or change something:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
default_tools_approval_mode = "writes"
Mode What Codex does
auto The default: decides from each tool's hints
writes Asks before any tool that isn't marked read-only
prompt Asks before every tool
approve Runs tools without asking

What Codex runs without asking under default_tools_approval_mode writes: 19 read-only WhatsMCP tools run freely, 18 tools that send or change something ask first, and 9 destructive tools always ask

A tools.<name> table overrides the mode for a single tool. For example, to approve every message Codex sends from your number, whatever the server's mode:

[mcp_servers.wamcp.tools.wa_send_message]
approval_mode = "prompt"

Trim the tool list

Codex can hide the tools a job doesn't need, which keeps its context lean and its mistakes small. enabled_tools is an allow list, and disabled_tools is a deny list applied after it. A strictly read-only assistant:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
enabled_tools = ["wa_list_accounts", "wa_list_messages", "wa_get_chat", "wa_get_message", "wa_get_media"]

Or everything except unpairing:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
disabled_tools = ["wa_unpair_account"]

To switch WhatsMCP off for a while without losing the setup, add enabled = false to the table.

Get a WhatsApp message when codex exec finishes

codex exec runs Codex without the interactive interface, which turns "do the work, then text me" into a one-liner for scripts, cron jobs and CI. Nobody is there to approve a prompt, so give that machine its own key, show Codex only the two tools the job needs, and pre-approve sending:

[mcp_servers.wamcp]
url = "https://api.whatsmcp.com/mcp"
bearer_token_env_var = "WHATSMCP_API_KEY"
enabled_tools = ["wa_list_accounts", "wa_send_message"]

[mcp_servers.wamcp.tools.wa_send_message]
approval_mode = "approve"
codex exec "Run the test suite. Then send a WhatsApp message from my test number +44 7700 900456 to +44 7700 900123 with the pass and fail counts and the slowest test."

Use a dedicated test number for jobs like this, and a key you can revoke on its own.

Teach Codex your WhatsApp rules with AGENTS.md

Codex reads standing instructions from AGENTS.md — ~/.codex/AGENTS.md for every project, plus one at the root of each repository. A few lines there save you repeating yourself and keep the agent away from the wrong number:

## WhatsApp (wamcp)
- Use the test number +44 7700 900456 for anything WhatsApp-related, never a production number.
- When a task takes longer than ten minutes, send a two-line summary to +44 7700 900123.
- Never message anyone else without asking me first.

Codex also reads the instructions WhatsMCP sends when it connects, so it already knows to start with wa_list_accounts and to page through messages with a cursor. Your AGENTS.md only needs your own rules.

What Codex can do on WhatsApp

WhatsMCP has 46 tools. A Personal number can use nearly all of them: messaging, reactions, edits and deletes, contacts and profiles, groups and channels with full admin, the blocklist, calls and AI voice agents, and webhooks. A Business number covers messaging, templates and webhooks under Meta's 24-hour window. Your plan decides which tools Codex sees, and wa_list_accounts tells it what each number supports, so it doesn't reach for a feature the number can't serve. The complete list is in the MCP reference.

Prompts for developers

  1. Reproduce a bug from a real message.

    "Find the last message my test number received from +44 7700 900111, save its raw JSON as a fixture, and write a failing test for our parser."

    Codex reads the chat with wa_get_chat, then writes the fixture and the test in your repository.

  2. Tell me when it's done.

    "Run the full test suite. When it finishes, send me a WhatsApp message with the pass and fail counts and the slowest test."

  3. Scaffold a webhook receiver.

    "Write a small HTTP handler that verifies WhatsMCP's webhook signature and logs each inbound message, then register it with wa_set_webhook at my tunnel URL."

    wa_set_webhook returns the signing secret once, so have Codex put it in your .env. Webhooks need a paid plan; see WhatsMCP webhooks: setup guide.

  4. Triage beta feedback.

    "Read this week's messages in the 'Beta testers' WhatsApp group, list each bug report with who sent it, and point me at the code most likely responsible."

    Group tools need a Personal number on a paid plan.

  5. Ship a template (Business numbers).

    "Create a utility template order_shipped with name, order number and date variables, check its status, and once Meta approves it, send it to my test number."

    Codex chains wa_create_template, wa_list_templates and wa_send_message. The rules that get templates approved are in How to write WhatsApp message templates Meta approves.

Troubleshooting

  • codex mcp list says Not logged in. The sign-in didn't finish. Run codex mcp login wamcp, or add --no-browser on a machine without one.
  • 401 with an API key. The variable isn't set in the environment Codex runs in — export it in that shell, or start the app from it — or the key was revoked.
  • A tool is refused for a missing permission. Your OAuth grant is narrower than the tool. Run codex mcp logout wamcp, then codex mcp login wamcp, and keep that permission ticked on the consent page.
  • A tool is missing. It isn't in your plan, or enabled_tools/disabled_tools filters it out, or Codex hasn't reloaded since you edited config.toml — start a new session. Ask Codex to run wa_get_plan, or open Console → Help to see what your plan includes.
  • A tool says the number can't do that. Groups, contacts, calls and the other linked-device features are Personal-only, so a Business number refuses them with a backend_capability reason.
  • Codex sends without asking. Set default_tools_approval_mode = "writes", or approval_mode = "prompt" on wa_send_message.

Good habits

  • Develop against a test number, never your main WhatsApp or a customer-facing line.
  • Prefer OAuth on your own machines. Each client gets its own revocable grant at Console → Connections, and nothing secret sits in a file.
  • Treat inbound messages as untrusted input. Anyone can text your number, and a message can contain instructions aimed at your agent. Keep approvals on for anything that sends, and don't let Codex run commands a message suggests.
  • Keep keys in the environment, one per machine or pipeline, and revoke a key at Console → API keys when its machine is gone.
  • Mind the terms. Personal numbers connect as linked devices, which falls outside WhatsApp's terms of service; for customer messaging, use an official Business number.

FAQ

Does Codex support remote MCP servers?

Yes. Codex connects to Streamable HTTP MCP servers by URL. It signs in with OAuth, registering through a client metadata document or dynamic client registration, or sends a bearer token from an environment variable.

Do the CLI, the IDE extension and the desktop app need separate setup?

No. On one machine they share ~/.codex/config.toml, so a server added in one of them shows up in the others after a restart.

Why does the consent page say chatgpt.com?

Codex identifies itself with a client metadata document hosted on chatgpt.com, and WhatsMCP names each client by that verified host rather than by the name it gives itself.

Can I give Codex read-only access?

Yes. Sign in with codex mcp login wamcp --scopes wa:accounts,wa:read, untick sending on the consent page, and list only reading tools in enabled_tools.

Which WhatsApp numbers work?

Both Personal and official Business numbers, through the same endpoint. wa_list_accounts shows each number's kind and what it supports.

Does this work with other AI clients?

Yes. See the guides for Claude, ChatGPT, Grok and Cursor.

Get started

Create your free WhatsMCP workspace, link a test number, and run one command. The complete tool reference is at whatsmcp.com/docs/mcp, and OpenAI documents the Codex side in its MCP guide.

About WhatsMCP Engineering

Engineering Team at WhatsMCP. The team building WhatsMCP's MCP server and SIP bridge — the people who wrote the code these posts describe.

Related posts

AI Agents
Sep 15, 2026

Connect WhatsApp to Cursor via MCP

Integrations
Sep 14, 2026

Sync WhatsApp with HubSpot and Pipedrive