How to Connect Codex to WordPress with MCP
Connect Codex to WordPress through Niwa MCP using private TOML configuration, a bearer token and a verified page read before your first edit.
Connect Codex to WordPress by adding Niwa’s HTTP MCP endpoint to your Codex configuration and making its bearer token available to the running client. Start a fresh session, discover the tools and read a known WordPress page. Once that succeeds, you can authorize a specific change and verify the saved result.
Niwa MCP for WordPress supplies the site’s operations. Codex supplies the external assistant that chooses and calls them. You can install the standalone Niwa plugin on an existing WordPress website without commissioning a replacement site.
Copy the endpoint from your own site
In WordPress, open Niwa AI → Niwa MCP. Copy the displayed endpoint and generate a credential with a suitable expiry. A conventional URL looks like https://example.com/wp-json/niwa-ai/v1/mcp. Subdirectory installations may differ, so use the URL your site displays.
Choose the intended environment before copying anything. A production URL paired with a staging credential is a different connection from the one you wanted. Prepare a known staging draft for the first edit and record its page ID, content and status.
The Niwa MCP token grants administrator access. Keep it private and leave optional options-reading access off unless the task needs it. That optional scope is not a general restriction on writes.
Add a Streamable HTTP entry in TOML
Codex supports MCP entries in ~/.codex/config.toml. A trusted project’s .codex/config.toml can also supply project configuration. Inspect the configuration that applies to your session before adding another server with a similar name.
This example uses a private environment variable for the token:
[mcp_servers.niwa]
url = "https://example.com/wp-json/niwa-ai/v1/mcp"
bearer_token_env_var = "NIWA_MCP_TOKEN"
startup_timeout_sec = 60
tool_timeout_sec = 120
default_tools_approval_mode = "prompt"
Replace the URL with your endpoint. niwa is the client-side server label. NIWA_MCP_TOKEN is the environment variable’s name, not the credential itself. The timeout values allow more time than Codex’s documented defaults; they do not make a failed connection healthy.
The Codex MCP reference documents HTTP authentication, configuration locations and approval controls. Use options supported by your installed version. Do not paste Claude’s JSON configuration into this TOML file.
Make the credential available before starting Codex
Load the token through your private credential or environment workflow, then start Codex from the environment where it is available. Setting a variable in a new terminal will not add it to an application already running elsewhere.
In PowerShell, this checks presence without printing the token:
[bool]$env:NIWA_MCP_TOKEN
A true result establishes presence in that shell. It does not prove the token is valid or that a desktop process inherited it. Restart the relevant client after changing its startup environment and inspect its connection status.
Niwa’s own Codex OAuth model connection is separate. Signing Niwa into a supported AI account does not automatically authenticate your external Codex MCP connection. Likewise, an MCP bearer token does not provide a model subscription.
Verify tool discovery and one actual page read
Inspect the configured server with codex mcp list and codex mcp get niwa, using the label from your configuration. In the active assistant session, ask which Niwa tools are available.
Then request get_page with your known page_id. Compare the returned ID, draft status and opening paragraph with WordPress. This checks the intended website and an actual operation, rather than merely checking that a configuration file exists.
For Niwa’s whole-task agent route, niwa_status reports configuration availability. niwa_agent_run returns a job handle; use niwa_agent_result to retrieve its eventual result. Keep the handle after a timeout. Submitting the same write again can duplicate work that already started.
Approve the proposed edit before execution
Ask Codex to prepare a change to the staging draft without invoking a write tool. Review the target ID, current text, replacement and fields to be changed. Authorize that specific write, then read the same page again.
For a content replacement, preserve the complete existing page structure and change only the intended part. Check that the page remains draft. A builder’s visible heading may live outside the stored WordPress title, so verify the field that visitors will see.
Codex can filter visible tools with enabled_tools and disabled_tools. Those controls shape that client’s behavior. They do not reduce the server rights carried by the administrator token. Client prompts provide a review step; server permissions determine what a credential is technically allowed to do.
Separate connection errors from task errors
If discovery fails, check the URL, authentication header, expiry and compatibility. If discovery works but one tool fails, inspect its argument schema and the returned error. A missing Niwa model connection can affect model-dependent agent tasks while deterministic native tools remain usable.
Contact Niwa about your Codex setup with the site, client version and one task you want to complete. Include a sanitized error when needed. The Niwa installation guide covers the WordPress side of the connection.