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

# Codex

[Codex](https://developers.openai.com/codex/) can work with CARTO through a remote MCP server, the CARTO Agent Skills, and the CARTO CLI.

* **MCP** — gives Codex access to CARTO tools.
* **Agent Skills** — gives Codex reusable CARTO-specific instructions and workflows.
* **CARTO CLI** — provides command-line access for scripting, automation, and administration.

Together, these let Codex use CARTO tools while following CARTO-specific patterns and workflows.

> **Before you start:** Copy your **MCP Server URL** from CARTO Workspace under **Workspace > Settings > MCP Server**

## MCP

### Connect to the MCP Server

Add CARTO using the Codex CLI:

```
codex mcp add carto --url https://<region>.api.carto.com/mcp/<account_id>
```

Alternatively, add the server manually to `~/.codex/config.toml`:

```
[mcp_servers.carto]url = "https://<region>.api.carto.com/mcp/<account_id>"bearer_token_env_var = "CARTO_TOKEN"  # optional; sent as Authorization: Bearer <value>
```

Replace `<region>` and `<account_id>` with the values from your CARTO MCP Server URL.

#### Authentication

For **OAuth**, which provides the full CARTO tool surface, start the browser-based login:

```
codex mcp login carto
```

For **read-and-discovery access**, set `CARTO_TOKEN` to a CARTO [API Access Token](/carto-user-manual/developers/managing-credentials/api-access-tokens.md):

```
export CARTO_TOKEN="<your-CARTO-token>"
```

The token is sent as:

```
Authorization: Bearer <value>
```

## CARTO CLI

Codex runs in a terminal, so the [CARTO CLI](/carto-for-agents/cli.md) can be used alongside MCP and Agent Skills for scripting, automation, and administration.

Install the CLI:

```
npm install -g @carto/carto-cli
```

Authenticate:

```
carto auth login
```

The CLI is useful when a task is better suited to command-line operations, scripting, or CARTO administration than to an MCP tool call.

## Agent Skills

[CARTO Agent Skills](/carto-for-agents/agent-skills.md) complement MCP and the CLI. They provide CARTO-specific instructions and workflows that help Codex use both interfaces consistently and idiomatically.

Install the CARTO Agent Skills through the Codex plugin manifest. See [**Agent Skills → Installation**](/carto-for-agents/agent-skills/installation.md) for setup instructions.

MCP provides Codex with access to CARTO tools, while the CLI provides command-line capabilities. Skills provide the guidance for using them effectively.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.carto.com/carto-for-agents/connect-your-platform/codex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
