Skip to content
kmem

Connect Codex

Codex reads kmem from its configuration file, and it reads the token from the KMEM_TOKEN environment variable.

kmem has tested this route with Codex.

Create a connection

  1. In kmem, select Connect. The MCP tab opens.
  2. Select Codex in the list of clients.
  3. Fill in the New connection form, for example with the name "Codex nightly checks".
  4. Select Create connection.

Create a connection explains each field. Copy the token now. kmem shows it only one time.

Merge the configuration

Codex keeps its MCP servers in the file ~/.codex/config.toml.

  1. Under Configuration for Codex, select Copy configuration.
  2. Open ~/.codex/config.toml in a text editor. If the file does not exist, create it.
  3. Add the kmem section at the end of the file. Keep your other servers.
  4. Save the file.

The configuration looks like this:

[mcp_servers.kmem]
url = "https://acme.kmem.app/mcp"
bearer_token_env_var = "KMEM_TOKEN"

Replace acme with your org's subdomain. The Connect screen fills it in for you.

The configuration holds no token. The line bearer_token_env_var tells Codex to read the token from the variable KMEM_TOKEN.

Set KMEM_TOKEN

Set KMEM_TOKEN to the token of your connection, in the environment that starts Codex.

  1. Open the profile file of your shell, for example ~/.zshrc or ~/.bashrc.
  2. Add this line, with your token in place of YOUR_TOKEN:
export KMEM_TOKEN="YOUR_TOKEN"
  1. Save the file.
  2. Open a new terminal. The new terminal reads the profile file and gets the variable.

If you start Codex from an app and not from a terminal, set the variable where that app gets its environment.

Keep the profile file private. Do not commit it to a shared repository.

Check the connection

  1. Start Codex again.
  2. Check that the MCP tools of Codex include kmem.
  3. Send the check prompt:
Use kmem to list the docs I can access. If there are none, say so.
  1. In kmem, select Check connection. The three checks must show Complete.

If Codex cannot reach kmem, check these points:

  • The terminal that starts Codex has a value in KMEM_TOKEN. Run echo $KMEM_TOKEN to see the value.
  • The token belongs to an active connection.
  • The url ends with /mcp.

Add kmem with a command instead

Codex can also add the server with a command. The command writes the same section to ~/.codex/config.toml:

codex mcp add kmem --url https://acme.kmem.app/mcp --bearer-token-env-var KMEM_TOKEN

Replace acme with your org's subdomain. You still need to set KMEM_TOKEN.

Next steps