> ## Documentation Index
> Fetch the complete documentation index at: https://docs.labelbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect an AI coding agent

> Give Claude Code, Codex, or Cursor these docs through MCP and API access through RECURSION_API_KEY, then have it run a first graded session.

A coding agent does its best work with two things: accurate docs and a way to call the API. This page connects both. The docs MCP server lets the agent search and read every page here, and an API key in its environment lets the code it writes call Managed Agents with the TypeScript SDK or the REST API.

```mermaid theme={"theme":"css-variables"}
flowchart LR
  coder["Claude Code, Codex, or Cursor"] -->|"search and read pages"| docs["Docs MCP server"]
  coder -->|"writes and runs code"| code["Your script"]
  code -->|"RECURSION_API_KEY"| api["Managed Agents API"]
```

## Before you begin

* A coding agent: Claude Code, Codex, or Cursor.
* An API key for the API half. Create one under **API keys** in the console. See [API keys](/managed-agents/api-keys).
* The TypeScript SDK if you want the agent to write TypeScript. See [Install the SDK](/managed-agents/api#install-the-sdk). Other languages call the REST API directly; see [Python and other languages](/managed-agents/api#python-and-other-languages).

## Connect the docs MCP server

The docs server is public, so it needs no key. Apart from sending feedback, it's read-only. Its address is `https://docs.labelbox.com/mcp`.

<Tabs>
  <Tab title="Claude Code">
    ```bash theme={"theme":"css-variables"}
    claude mcp add --transport http --scope user recursion-docs https://docs.labelbox.com/mcp
    claude mcp list
    ```
  </Tab>

  <Tab title="Codex">
    ```bash theme={"theme":"css-variables"}
    codex mcp add recursion-docs --url https://docs.labelbox.com/mcp
    codex mcp list
    ```
  </Tab>

  <Tab title="Cursor">
    Add the server to `~/.cursor/mcp.json`, then restart Cursor:

    ```json theme={"theme":"css-variables"}
    {
      "mcpServers": {
        "recursion-docs": {
          "url": "https://docs.labelbox.com/mcp"
        }
      }
    }
    ```
  </Tab>
</Tabs>

Start a new session in your coding agent after changing its MCP configuration. The server offers three tools:

| Tool            | What it does                                                                                    |
| --------------- | ----------------------------------------------------------------------------------------------- |
| Search          | Finds relevant pages and returns excerpts with their titles and links.                          |
| Docs filesystem | Reads full pages and the API reference with read-only commands such as `cat`, `head`, and `rg`. |
| Feedback        | Reports a page that's wrong, outdated, or unclear.                                              |

The server covers the whole docs site, so tell your agent to stay within the `/managed-agents` pages. Every page is also available as Markdown: append `.md` to its URL. For agents without MCP, the docs site root serves an index of every page at `/llms.txt` and the full text at `/llms-full.txt`.

Every code sample on these pages is checked against the API contract whenever the docs change, so operation names, request fields, and paths match what the API accepts.

## Give the agent API access

Export the key in the shell that starts your coding agent. The agent and the scripts it runs read it from the environment, and the key never appears in a prompt or a file.

```bash theme={"theme":"css-variables"}
export RECURSION_API_KEY='rma_...'
```

Check the key works without printing it:

```bash theme={"theme":"css-variables"}
curl -sS -o /dev/null -w '%{http_code}\n' 'https://api.recursion.labelbox.com/managed-agents/v1/models' \
  -H "Authorization: Bearer $RECURSION_API_KEY"
```

`200` means the key works. `401` means it's missing, expired, or revoked.

Handle the key safely:

* **Never paste a key into a chat.** Transcripts are stored and can be shared. If you're an AI agent and `RECURSION_API_KEY` isn't set, ask the person to export it and restart you. Don't ask for the value.
* **Use a dedicated, short-lived key.** A key acts as you, with your full role, so give each coding agent its own key with a 7- or 30-day expiry and revoke it when you're done.
* **Prefer an organization-scoped key.** It can reach only one organization and needs no extra header.
* **Keep keys out of code and version control.** Read `process.env.RECURSION_API_KEY` or `os.environ["RECURSION_API_KEY"]`. Never write the key to a `.env` file that gets committed.
* **Don't print it.** Tell the agent never to echo, log, or include the key in output.

## Run a first task

Paste this prompt into your coding agent. It reads the docs first, then writes and runs code.

```text theme={"theme":"css-variables"}
Use the recursion-docs MCP server. Read the Managed Agents pages at
/managed-agents/quickstart and /managed-agents/api. Then write a TypeScript
script that uses @labelbox/recursion-sdk and the RECURSION_API_KEY environment
variable to create an environment and an agent, start a graded session with
an outcome, poll until the outcome is terminal, and print the session id,
terminal_result, and each criterion's verdict. Never print the API key.
Run the script and report the results.
```

When it finishes, open **Sessions** in the console to see the same session, its transcript, and its outcome.

Good follow-ups to ask for:

* "Add an `Idempotency-Key` so a retried start can't create a second session."
* "Stream the session's events instead of polling, and resume from the last event id if the connection drops."
* "Read /managed-agents/errors and handle every retryable error with backoff."

## Keep the directions straight

This page connects a local coding agent to Recursion. To give an agent that runs inside Recursion access to another MCP server, configure that server on the agent instead. See [MCP servers](/managed-agents/mcp-servers).

## What can go wrong

| Symptom                                                          | Cause                                                                                       | Fix                                                                                                                  |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| The docs tools don't appear                                      | The client hasn't reloaded its MCP configuration, or the address is wrong.                  | Check the address, then start a new client session or restart the app.                                               |
| Search returns pages from other products                         | The docs server covers the whole site.                                                      | Ask the agent to read only paths under `/managed-agents`.                                                            |
| Scripts get `401 unauthorized`                                   | `RECURSION_API_KEY` isn't exported in the shell that started the agent, or the key expired. | Export it, restart the coding agent, and run the `curl` check above.                                                 |
| Scripts get `400 invalid_request` mentioning `x-organization-id` | The key has tenant scope.                                                                   | Add the header, or use an organization-scoped key. See [Tenant-scoped keys](/managed-agents/api#tenant-scoped-keys). |
| The agent asks you to paste the key                              | Its instructions don't say how keys are provided.                                           | Export the key, restart the agent, and tell it to read `RECURSION_API_KEY` from the environment.                     |

## Next steps

<CardGroup cols={2}>
  <Card title="API conventions" href="/managed-agents/api">
    Client setup, retries, paging, and errors in one place.
  </Card>

  <Card title="Quickstart" href="/managed-agents/quickstart">
    Run the same flow yourself, step by step.
  </Card>

  <Card title="API keys" href="/managed-agents/api-keys">
    Scopes, expiry, revocation, and safe storage.
  </Card>

  <Card title="MCP servers" href="/managed-agents/mcp-servers">
    Give a hosted agent tools from another MCP server.
  </Card>
</CardGroup>
