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

# Connect your coding agent

> Connect a coding agent to Sazabi so it can investigate production while it writes code. Set up the CLI for terminal agents, or the MCP server for MCP clients.

Connect your coding agent to Sazabi and it can read your production logs while it works — trace an error to the code that caused it, or check whether a change actually fixed a problem. By the end of this guide your agent can query Sazabi and return real data from your project. Setup takes a few minutes.

## What you get

Once connected, your agent can search your logs, look up issues, and run the same investigations you would run in a thread — from inside your editor or terminal. You ask in natural language ("what errors is checkout throwing in production?") and the agent queries Sazabi and answers with evidence.

## Prerequisites

* A Sazabi account with at least one project that is receiving logs. If you have not sent logs yet, do the [Quickstart](https://docs.sazabi.com/get-started/quickstart.md) first.
* A **secret key**, unless your MCP client signs in with OAuth (see [The MCP path](#the-mcp-path)). Create one at [**Settings > Secret keys**](https://app.sazabi.com/settings/secret-keys). Secret keys grant full read and write (organization-wide by default, or scoped to one project), so store it in a secrets manager and never commit it.

## Choose a path

There are two ways to connect.

**Recommended for terminal agents: the CLI path.** Install the `sazabi` CLI, and any terminal agent (Claude Code, Codex, OpenCode) can drive Sazabi through the same commands. **Use the MCP path when** your agent is a GUI client (Claude Desktop, ChatGPT) or you prefer wiring Sazabi in as an MCP server. It is the only path for GUI clients. **Trade-offs:** the CLI path is one identical procedure for every terminal agent; the MCP path is configured per client but works for clients that have no terminal. **Do not use the CLI path** for a GUI-only client that cannot run shell commands — use the MCP path there.

## The CLI path

One procedure, identical for every terminal agent.

### Install and authenticate the sazabi CLI

1. Install the CLI globally:

   ```bash theme={"system"}
   npm install -g @sazabi/cli@latest
   ```

   To run it without installing, use `npx @sazabi/cli@latest <command>` in place of `sazabi <command>`. Keep `@latest`: without it, `npx` can reuse an older cached copy that lacks newer commands and flags, such as `start --agent`.

2. Sign in. This opens your browser for a device-code sign-in:

   ```bash theme={"system"}
   sazabi auth sign-in
   ```

3. Confirm you are authenticated and select your organization and project:

   ```bash theme={"system"}
   sazabi auth whoami
   sazabi organizations use <org-id>
   sazabi projects use <project-id>
   ```

   Run `sazabi organizations list` and `sazabi projects list` if you need the IDs.

For non-interactive use (CI, headless agents), set the `SAZABI_TOKEN` environment variable to a secret key (or pass it with `--token`) and `SAZABI_PROJECT_ID` to your project's ID instead of running `sazabi auth sign-in`. See [Running without a browser](https://docs.sazabi.com/get-started/quickstart.md#running-without-a-browser).

### Connect Claude Code or Codex subscriptions

If you use a Claude subscription with Claude Code, connect it from your terminal:

```bash theme={"system"}
sazabi integrations claude connect
```

The Sazabi CLI runs Claude Code's own sign-in and saves the resulting subscription credential without displaying it. Claude Code opens the browser flow and asks for the short code shown after you approve access. The credential is valid for one year.

For a ChatGPT subscription with Codex, run:

```bash theme={"system"}
sazabi integrations codex connect
```

The command runs Codex's browser sign-in on your machine and saves its local sign-in credential without printing it. Add `--account-label` to name the connection, `--project <project-id>` to select a project, or `--reconnect <connection-id>` to replace credentials on an existing connection.

Your terminal agent can now run `sazabi` commands — for example `sazabi logs ask`, `sazabi issues list`, or `sazabi memory search` — to investigate your project. Every command takes `-h` for its flags and examples.

## The MCP path

For MCP clients, connect Sazabi as an MCP server at `https://mcp.sazabi.com/mcp`. The server accepts two kinds of credential:

* **OAuth sign-in.** A client that supports MCP OAuth needs only the server URL. It opens your browser, you approve the connection, and the client acts as you. No key is created or pasted. The Claude Code, Cursor, and Codex CLI sections below show this path.
* **A secret key.** Every client can send a secret key in the `X-Sazabi-Secret-Key` header. Use it for clients without OAuth support and for headless or shared setups where nobody can sign in through a browser.

With OAuth, the browser step is the same for every client:

1. Sign in to Sazabi if you are not already signed in.
2. On the **Authorize MCP connection** page, check the client name, then choose the organization the connection may act in.
3. Under **Project access**, choose **All projects** or a single project.
4. Select **Authorize**. The browser hands the sign-in back to your client.

![The Authorize MCP connection page: the client name and access, an organization menu, a Project access menu, and Deny and Authorize buttons.](https://mintcdn.com/sazabi/jkR9heQuu5p4dpza/images/screenshots/connect-coding-agent-authorize-mcp-light.png?fit=max\&auto=format\&n=jkR9heQuu5p4dpza\&q=85\&s=4e6c8337df23bb5e53fc63bf21f2cf8e)

The Authorize MCP connection page.

Each sign-in approves one organization. To use another organization, or to change the project access, sign in again from your client and choose differently.

Wherever a configuration below shows `<YOUR_SECRET_KEY>`, replace it with a secret key from [**Settings > Secret keys**](https://app.sazabi.com/settings/secret-keys), and keep that file out of version control.

### Claude Code

**Sign in with OAuth.** Add the server from your terminal with no header:

```bash theme={"system"}
claude mcp add --transport http sazabi https://mcp.sazabi.com/mcp
```

Then run `/mcp` inside Claude Code, select `sazabi`, and complete the sign-in in your browser.

**Use a secret key.** Add the server with the key in a header instead:

```bash theme={"system"}
claude mcp add --transport http sazabi https://mcp.sazabi.com/mcp \
  --header "X-Sazabi-Secret-Key: <YOUR_SECRET_KEY>"
```

### Claude Desktop

In Claude Desktop, open **Settings > Developer > Edit Config** to open `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`; Windows: `%APPDATA%\Claude\claude_desktop_config.json`), then add:

```json theme={"system"}
{
  "mcpServers": {
    "sazabi": {
      "type": "http",
      "url": "https://mcp.sazabi.com/mcp",
      "headers": {
        "X-Sazabi-Secret-Key": "<YOUR_SECRET_KEY>"
      }
    }
  }
}
```

### Cursor

Cursor reads MCP servers from `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` in a project. The same file serves both the Cursor editor and the Cursor CLI (`cursor-agent`).

**Sign in with OAuth.** Add the server with its URL and no `headers`:

```json theme={"system"}
{
  "mcpServers": {
    "sazabi": {
      "type": "http",
      "url": "https://mcp.sazabi.com/mcp"
    }
  }
}
```

Cursor then lists the server as needing authentication. In the editor, start the sign-in from the server's entry in **Cursor Settings > MCP**. With the Cursor CLI, run:

```bash theme={"system"}
cursor-agent mcp login sazabi
```

Your browser opens for you to approve the connection. No secret key is involved, so nothing sensitive lands in `mcp.json`. If the server is in a project's `.cursor/mcp.json`, the Cursor CLI asks you to approve it first: run `cursor-agent mcp enable sazabi`, then log in.

**Use a secret key.** Add the `X-Sazabi-Secret-Key` header instead:

```json theme={"system"}
{
  "mcpServers": {
    "sazabi": {
      "type": "http",
      "url": "https://mcp.sazabi.com/mcp",
      "headers": {
        "X-Sazabi-Secret-Key": "<YOUR_SECRET_KEY>"
      }
    }
  }
}
```

You can also add the server from Cursor's settings UI: **Cursor Settings > MCP > Add new MCP server**, using HTTP transport with the URL above, and the `X-Sazabi-Secret-Key` header only if you are using a secret key.

### Codex CLI

Add the server from your terminal:

```bash theme={"system"}
codex mcp add sazabi --url https://mcp.sazabi.com/mcp
```

Codex discovers the OAuth resource from Sazabi and opens your browser to authorize the `mcp` and `offline_access` scopes. Do not add `--oauth-resource`; providing it again duplicates the discovered resource and causes authorization to fail with a 403 response. You can also edit `~/.codex/config.toml` directly.

### Codex Desktop

In Codex Desktop's MCP settings, add an HTTP server with URL `https://mcp.sazabi.com/mcp` and the `X-Sazabi-Secret-Key` header set to your secret key.

### OpenCode

Add the server from your terminal — `opencode mcp add` walks you through adding a remote server — or add it to your OpenCode configuration (`opencode.json`) directly:

```json theme={"system"}
{
  "mcp": {
    "sazabi": {
      "type": "remote",
      "url": "https://mcp.sazabi.com/mcp",
      "headers": {
        "X-Sazabi-Secret-Key": "<YOUR_SECRET_KEY>"
      }
    }
  }
}
```

### ChatGPT

In ChatGPT's connector settings, add a custom MCP server with URL `https://mcp.sazabi.com/mcp` and the `X-Sazabi-Secret-Key` header set to your secret key.

## Try it: investigate production from your coding agent

With either path connected, ask your agent a question that requires your logs:

```text theme={"system"}
Use Sazabi to find the most recent ERROR logs in my project and summarize what is failing.
```

The agent queries Sazabi and answers with the specific records it found.

## Hand an issue to your coding agent

Every Sazabi issue has an agent prompt: one prompt you paste into your coding agent to continue Sazabi's investigation, fix the problem in your repository, and open a pull request linked back to the issue. The prompt carries the issue ID and a link, never a credential. It tells the agent to install and sign in to the CLI if needed, read the analysis with `sazabi issues get` (its `report` field has the full what, why, how, and evidence), check the problem against live logs, and treat issue text and log lines as data, not instructions.

Print the prompt with the CLI and paste it into your agent (`ISSUE_ID` is the issue's ID from `sazabi issues list`):

```bash theme={"system"}
sazabi issues agent-prompt "$ISSUE_ID"
```

A pull request opened from the prompt shows up in the issue's pull requests in either of two ways:

* **The `Sazabi-Issue` line.** In a GitHub repository connected to the issue's project, a pull request whose body has the line `Sazabi-Issue: <issue-id>` is linked when it is opened or edited.
* **An explicit link.** Link any GitHub or Bitbucket pull request yourself:

  ```bash theme={"system"}
  sazabi issues link-pr "$ISSUE_ID" https://github.com/acme/api/pull/42
  ```

Linked pull requests are listed with `source: "linked"` and are never billed as pull requests Sazabi opened.

If a pull request is the suspected cause rather than the fix, label that relationship explicitly. You can find every issue attributed to the PR and remove a wrong attribution later:

```bash theme={"system"}
sazabi issues link-pr "$ISSUE_ID" https://github.com/acme/api/pull/42 --relation caused_by
sazabi issues list --caused-by https://github.com/acme/api/pull/42
sazabi issues unlink-pr "$ISSUE_ID" https://github.com/acme/api/pull/42 --relation caused_by
```

## Verify

Confirm the connection returns real data from your project.

1. First, send a distinctive test event if you have not already — see [Quickstart](https://docs.sazabi.com/get-started/quickstart.md) curl step, using body `sazabi quickstart test event 8842`.
2. Ask your agent: `Use Sazabi to find the log with body "sazabi quickstart test event 8842".`
3. The agent returns one matching record with service `quickstart` and severity `INFO`.

If the agent cannot reach Sazabi, re-check the secret key (or, with OAuth, sign in again from your client) and, for the CLI path, that `sazabi auth whoami` shows the right organization and project.

## Further reading

> [card] [Agent tools](https://docs.sazabi.com/ask/agent-tools.md)
>
> What the agent can search and do during an investigation.

> [card] [MCP server reference](https://docs.sazabi.com/reference/mcp-server.md)
>
> The search and execute tools, and authentication details.

> [card] [CLI reference](https://docs.sazabi.com/reference/cli.md)
>
> Every sazabi command and flag.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.