> For the complete documentation index, see [llms.txt](https://docs.cloud.olakrutrim.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloud.olakrutrim.com/mcp/connect-codex.md).

# Connect Codex

Connect Codex with Hosted MCP or a local stdio server using your API key.

Connect Codex to Krutrim Cloud using Hosted MCP first, or choose the package-based local stdio alternative below. Both authenticate with a Krutrim Cloud API key.

## 1. Hosted MCP

First, complete the endpoint and API-key prerequisites in [Hosted MCP](https://docs.cloud.olakrutrim.com/mcp/hosted-mcp.md). No local Python package is required for this connection.

Use the HTTPS endpoint exactly as shown, including `/mcp`.

Set `KRUTRIM_API_KEY` privately in the environment that launches your client. Store only the raw API key, without a `Bearer` prefix. A shell export is not enough if a desktop app does not inherit that shell’s environment. Never put the real key in shared configuration, chat, logs, or source control.

{% stepper %}
{% step %}

### Add the hosted server

Open `~/.codex/config.toml`. Merge the hosted server below with your existing MCP configuration. If `krutrim-cloud` already uses stdio, replace that server’s transport settings; do not keep `command` and `args` alongside `url`.

```toml
[mcp_servers.krutrim-cloud]
enabled = true
url = "https://mcp.olakrutrim.com/mcp"
bearer_token_env_var = "KRUTRIM_API_KEY"
```

`bearer_token_env_var` names the environment variable that holds the raw API key. Codex sends it as a Bearer token; do not put `Bearer` inside the variable value. This API-key setup does not require an OAuth login.
{% endstep %}

{% step %}

### Restart and enable the connection

Restart Codex or start a new session after saving. In the CLI, use `codex mcp list` and `/mcp` to inspect the server.
{% endstep %}

{% step %}

### Verify readiness, then Cloud access

Ask your agent to call `krutrim_ping`. It reports server identity, version, readiness, and read-only mode without calling a Cloud API.

Then ask for a read-only Cloud request and review the region:

```
list_vpcs(region="In-Bangalore-1")
```

A successful Cloud response verifies access for that request. Server readiness or tool discovery alone does not prove Cloud permissions. Do not create or delete resources just to test the connection.
{% endstep %}
{% endstepper %}

## 2. Local MCP (stdio)

Choose this alternative when your client should launch the package on your machine. Use it instead of the hosted configuration, not in the same server entry.

* Complete the package installation and API-key setup in [Local MCP (stdio)](https://docs.cloud.olakrutrim.com/mcp/local-mcp-stdio.md) before using the local configuration below.
* Make sure `uvx` is available on the local machine.
* Use the raw API key as `KRUTRIM_API_KEY`, without a `Bearer` prefix or surrounding spaces. Keep it private and restart the client after changing the key.

{% stepper %}
{% step %}

### Open the Codex configuration file

Open `~/.codex/config.toml`. Create the `.codex` directory and configuration file if they do not already exist.

> Scope: The configuration below runs Krutrim Cloud MCP locally through stdio. Do not add actual API keys to a project configuration or commit them to source control.
> {% endstep %}

{% step %}

### Add the Krutrim Cloud MCP server

Add this entry to `~/.codex/config.toml`. If you already have MCP servers, preserve the existing entries and add this one alongside them.

```toml
[mcp_servers.krutrim-cloud]
enabled = true
command = "uvx"
args = ["krutrim-mcp-server"]

[mcp_servers.krutrim-cloud.env]
KRUTRIM_API_KEY = "YOUR_KRUTRIM_API_KEY"
```

{% endstep %}

{% step %}

### Check that Codex sees the server

In a terminal, run:

```bash
codex mcp list
```

In the Codex CLI interactive interface, use `/mcp` to inspect server status. Start a new Codex session after changing the file. In the ChatGPT desktop app or IDE extension, save the configuration and restart the relevant surface.
{% endstep %}

{% step %}

### Verify with a read-only request

Then make a read-only request:

```
List my VPCs in In-Bangalore-1.
```

Review the tool call and allow only the read-only request.
{% endstep %}
{% endstepper %}

## Next steps

Before changing Cloud resources, follow the safety guidance in the [MCP Overview](https://docs.cloud.olakrutrim.com/mcp/overview.md). Start with a read-only request and review the exact region and resource identifiers.

Need help? Open [Troubleshooting](https://docs.cloud.olakrutrim.com/mcp/troubleshooting.md) for startup, API-key, and tool-discovery checks.

For current Codex MCP product behavior and UI paths, see the [OpenAI MCP documentation](https://learn.chatgpt.com/docs/extend/mcp?surface=cli).
