Skip to content

Connect an agent

To connect an agent, create a token in Codex, then give your MCP client the server address and the token.

Address: https://<your-codex>/mcp, with the token in an Authorization: Bearer header. Replace <your-codex> with the address you open Codex at. On the quick start, the full address is http://localhost:8080/mcp.

  1. Open your account at /account and find the Agent access section.
  2. Enter a name that says where the token will live, such as Claude Code on my laptop.
  3. Tick the scopes the agent needs. Read is always on. Tokens and scopes explains each one.
  4. Choose when the token expires, then select Create token.
  5. Copy the token now. Codex shows it once and keeps only a hash.

The token starts with cdx_pat_.

The box that shows the token also prints a ready claude mcp add command with your address and token filled in. You can copy that command instead of typing the one below.

Run this in a terminal. Replace the address and the token.

Terminal window
claude mcp add --transport http codex https://<your-codex>/mcp \
--header "Authorization: Bearer cdx_pat_<your token>"

This stores the server for the current project only. Add --scope user to make it available in every project. Do not use --scope project with a real token, because it writes the token into .mcp.json, which you may commit. To share the file with a team, read the token from an environment variable instead:

{
"mcpServers": {
"codex": {
"type": "http",
"url": "https://<your-codex>/mcp",
"headers": { "Authorization": "Bearer ${CODEX_TOKEN}" }
}
}
}

Claude Code documents these options in Connect Claude Code to tools via MCP.

In Claude Code, run claude mcp list, or type /mcp in a session. The codex server shows as connected. Then ask the agent a question that needs a tool:

List my books in Codex.

The agent calls list_books and answers with your Library. In the running example it finds the Working Coasts series with Salt and Signal and Tide Tables.

A request without a working token gets HTTP 401. The response carries WWW-Authenticate: Bearer realm="codex" and this message:

Send a Codex personal access token: Authorization: Bearer cdx_pat_…. Create one under Account → Agent access.

Codex answers 401 when the header is missing, is not a bearer token, or holds a token that is unknown, revoked or expired. It also answers 401 when the token’s user is disabled. Check these in order.

  1. The header is Authorization: Bearer cdx_pat_... with one space and no quotes in the stored value.
  2. The token is the one you copied, with all of its characters.
  3. The token is in the list under Agent access and has not expired. If it was revoked or expired, create a new one.
  4. The address ends in /mcp and points at your Codex, not at the sign-in page.

Claude Code does not check a token when you add the server, so a wrong token shows up only when it connects.

If the connection works but a tool fails with forbidden, the token lacks a scope or your role on the book is too low. Tokens and scopes covers both.