# Codex

Add Artifacts to Codex as an MCP server in its config file, so it can make and change items in your spaces.

Codex connects to Artifacts as a remote MCP server, with an agent key you make in Artifacts.

::::::steps
:::::step{title="Make a key for Codex"}
In [Settings › Agents](https://tryartifacts.com/settings#agents), click **New agent key**, name the agent, choose **Codex** and click **Create key**. Copy the key: it is shown only once.
:::::
:::::step{title="Add the server to the config"}
Add this to `~/.codex/config.toml`, with your key in place of `fk_…`:

```toml
[mcp_servers.artifacts]
url = "https://tryartifacts.com/mcp"
http_headers = { Authorization = "Bearer fk_…" }
```
:::::
:::::step{title="Start a new session"}
Codex loads MCP servers when a session starts. In a new session, ask it to call `list_spaces` to check the connection.
:::::
::::::

## Let your team @mention it

While the Artifacts helper runs on your computer, people in a space can @mention your Codex in the chat and it answers there, using your own Codex. See [Answer @mentions](/docs/answer-mentions).

```bash
node artifacts-agent.mjs --url https://tryartifacts.com --key fk_… --run codex
```

## Troubleshooting

### Codex doesn't show the Artifacts tools

Codex loads MCP servers when a session starts, so start a new one after changing `config.toml`. In the Codex TUI, `/mcp` shows the active servers; from your shell, `codex mcp list` lists the configured ones. A server with `enabled = false` in its table is kept but not loaded. ChatGPT on the web does not read your local Codex configuration.

### It answers 401

Artifacts answers HTTP 401 when the request has no key, or a key it does not know or that was revoked. Check the `Authorization` value in `http_headers` reads `Bearer ` followed by the whole key, then make a new key in [Settings › Agents](https://tryartifacts.com/settings#agents) if it still fails.

### Keep the key out of the config file

Codex can read the key from an environment variable instead, with `bearer_token_env_var`:

```toml
[mcp_servers.artifacts]
url = "https://tryartifacts.com/mcp"
bearer_token_env_var = "ARTIFACTS_KEY"
```

Then set `ARTIFACTS_KEY` to your `fk_…` key in the shell that starts Codex.

### A tool times out

Codex waits 10 seconds for a server to start and 60 seconds for a tool to finish. If a tool stops on that limit, raise it in the server's table:

```toml
[mcp_servers.artifacts]
url = "https://tryartifacts.com/mcp"
http_headers = { Authorization = "Bearer fk_…" }
tool_timeout_sec = 180
```

### Where are the other errors explained?

See [Agent keys](/docs/agent-keys) for making and revoking keys, and the [MCP reference](/docs/reference) for what each tool takes. OpenAI's own guide to MCP in Codex is at [learn.chatgpt.com/docs/extend/mcp](https://learn.chatgpt.com/docs/extend/mcp).
