# Codex CLI + VidMachine MCP

> Keep the key in an environment variable, not in the config file.

Codex CLI reads MCP servers from `~/.codex/config.toml`. The `bearer_token_env_var` field names the variable that holds the key, so the file itself never contains a secret.

Page: https://vidmachine.ai/codex

## Connect

Create an API key under [API & MCP](https://vidmachine.ai/api-keys), then add an entry to `~/.codex/config.toml`:

```toml
[mcp_servers.vidmachine]
url = "https://vidmachine.ai/api/mcp"
bearer_token_env_var = "VIDMACHINE_MCP_KEY"
```

```bash
export VIDMACHINE_MCP_KEY="vidm_..."   # raw key, no "Bearer " prefix
codex mcp list
```

- The value is the raw key. Codex adds the `Bearer ` prefix when it calls the server.
- Open a new terminal after exporting so the variable is visible to Codex.
- The agent gets 28 tools in five groups: find, build, render, post, brand.

## The loop: find, inspect, make, schedule

### 1. Find — find out what's already there

Ask for a project or a video in plain language. The read tools answer with real IDs, statuses, and the first missing stage — and cost nothing.

Tools: `search_documentation`, `get_documentation`, `list_projects`, `list_videos`

### 2. Inspect — inspect before spending credits

Read the script, scenes, and cover, then quote the credits the remaining stages will cost and check the balance. Every paid step is priced before it runs.

Tools: `get_video_content`, `estimate_video_cost`, `get_credit_balance`

### 3. Make — make your version

Rewrite a scene, regenerate just that scene's media, and resume the pipeline. Work that already exists is reused, so a one-scene change does not redo the video.

Tools: `update_scene`, `generate_scene_media`, `generate_video`, `export_video`

### 4. Schedule — schedule it and get the link

Set the post time and status, then have the final URL handed back to you. The scheduler publishes it with the same rules as the dashboard.

Tools: `update_video`, `export_video`

## Three prompts to try

1. Search the docs for how narrator timing works, then summarize it in five lines.
2. Create a 30-second video about espresso ratios and run the pipeline.
3. Move this month's Thursday videos to 9:00 and list what changed.

## Full tool list

Every tool, input schema, protocol version, and header rule: [MCP server docs](https://vidmachine.ai/docs/mcp.md).

Other guides: [Claude Code](https://vidmachine.ai/claude) · [ChatGPT](https://vidmachine.ai/chatgpt) · [Cursor](https://vidmachine.ai/cursor)
