> For the complete documentation index, see [llms.txt](https://docs.codna.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codna.ai/guides/mcp.md). Agents can also search and read this documentation through its [MCP server](https://docs.codna.ai/~gitbook/mcp).

# MCP Server

Run Codna as a Model Context Protocol server so Cursor, Claude Desktop, or your own agent can triage, fix, secure, recall code, and file reports.

`codna mcp` runs Codna as a [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server over stdio. It exposes five tools that any MCP client can call. Use it when you want Codna inside your editor or chat client (Cursor, Claude Desktop, or your own agent) instead of, or alongside, the `codna` command line.

```bash
codna mcp
```

Run bare, `codna mcp` (equivalent to `codna mcp start`) serves over standard input/output, the transport Cursor and Claude Desktop expect. It stays in the foreground waiting for a client and prints nothing on success; the client spawns it from the config below, so you rarely run it by hand. It also accepts `--repo <repo>` to set a default repo for the tools, an `install` subcommand (below) that writes a client's config for you, and a `browser` subcommand that reports the [browser tool's](#the-browser-tool) status.

## Installation

The MCP server is an optional channel, installed with the `mcp` extra:

```bash
pip install "codna[mcp]"
```

This adds the `mcp` package on top of a normal `pip install codna`. It is kept out of the base install because `mcp` pulls a small web stack that CLI and CI use do not need. If you already have Codna, add the extra:

```bash
pip install --upgrade "codna[mcp]"
```

If you run `codna mcp` without the extra, Codna prints `MCP support isn't installed. Add it with: pip install 'codna[mcp]' then re-run codna mcp.` The base `codna` command, triage, fix, review and secure work without it.

## Configuration

The server and the CLI share the same local runtime and the same keys. Because the MCP client spawns `codna mcp` as a child process, set credentials in the `env` block of the client configuration, or store them in the OS keychain with `codna key set`; the server inherits nothing else from your shell.

| Variable                                                      | Purpose                                                                                                                                        | Default |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` / `GEMINI_API_KEY` / … | Provider key for `codna_fix`. Or store one with `codna key set`.                                                                               | —       |
| `GITHUB_TOKEN` / `CODNA_GITHUB_TOKEN`                         | Write token for `codna_fix` with `open_pr=true`, and for `codna_report_bug`.                                                                   | —       |
| `CODNA_MCP_DEFAULT_REPO`                                      | Default repo for tools when the caller passes `.` (same as `--repo`).                                                                          | `.`     |
| `CODNA_API_KEY`                                               | Your Codna key from the one-time free `codna login` (device authorization, free community license). Required to execute any of the five tools. | —       |

All five tools require the one-time free `codna login` — introspection (`initialize`/`tools/list`) stays credential-free, but every tool call checks the device authorization and otherwise returns a `login_required`-style error. Fully offline thereafter: `codna_triage`, `codna_secure`, and `codna_recall` then need no key at all; `codna_fix` additionally needs a provider key, and `codna_report_bug` needs a GitHub token to auto-file.

## Exposed tools

The server registers five tools. Each one returns a JSON **string** (pretty-printed, two-space indent) and is wrapped so a failure never crashes the server: errors come back as a plain string of the form `codna_<tool> error: <message>`, which the client surfaces as the tool result.

### `codna_triage`

Understands a repository and locates the code relevant to an issue. Read-only and deterministic. 0 model tokens.

| Parameter | Type   | Default | Description                                                                                                                 |
| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------- |
| `repo`    | string | `.`     | A local path or a git URL. A local directory is read directly; an `http(s)://` or `.git` URL is fetched.                    |
| `issue`   | string | `""`    | Optional description of what to look for. When empty, Codna uses `"Map this repository and locate its most relevant code."` |

Returns a JSON object with these fields (values shown for the shape):

```json
{
  "suspect_files": [
    "src/auth/session.py",
    "src/auth/tokens.py"
  ],
  "reduction_ratio": 312.0,
  "raw_repo_tokens": 1842030,
  "evidence_bundle_tokens": 5904
}
```

| Field                    | Meaning                                                                                  |
| ------------------------ | ---------------------------------------------------------------------------------------- |
| `suspect_files`          | The files Codna identified as most relevant to the issue.                                |
| `reduction_ratio`        | How much smaller the evidence bundle is than the raw repo (e.g. `312.0` = 312x smaller). |
| `raw_repo_tokens`        | Estimated token count of the whole repository.                                           |
| `evidence_bundle_tokens` | Token count of the reduced bundle handed to an agent.                                    |

### `codna_fix`

Finds and fixes a bug. Runs the full Codna agent and a deterministic risk simulation.

| Parameter | Type    | Default                          | Description                                                                                                                                                                              |
| --------- | ------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `repo`    | string  | (required)                       | A local path or a git URL.                                                                                                                                                               |
| `issue`   | string  | (required)                       | What is broken, e.g. the failing test or the observed behavior.                                                                                                                          |
| `ref`     | string  | `""`                             | Optional branch, tag, or commit to check out before analysis.                                                                                                                            |
| `open_pr` | boolean | `false`                          | When `false`, plan only. When `true`, open a pull request; requires a git URL for `repo`, a non-empty `issue`, and `GITHUB_TOKEN` or `CODNA_GITHUB_TOKEN` in the MCP server environment. |
| `model`   | string  | `repository.verified_agentic_v1` | Optional provider-qualified planner model, e.g. `openai/gpt-5`.                                                                                                                          |

Returns a JSON object (values shown for the shape):

```json
{
  "root_cause": "Session token expiry compared against a naive datetime, so tokens never expire under UTC.",
  "impacted_symbols": ["Session.is_expired", "TokenStore.purge"],
  "blast_radius": "low",
  "confidence": 0.91,
  "patch_ref": "…",
  "model": "repository.verified_agentic_v1",
  "cost_usd": 0.021
}
```

| Field              | Meaning                                           |
| ------------------ | ------------------------------------------------- |
| `root_cause`       | Why the bug occurs.                               |
| `impacted_symbols` | Functions and classes the fix touches.            |
| `blast_radius`     | Scope of the change.                              |
| `confidence`       | Planner confidence in the fix, `0.0`–`1.0`.       |
| `patch_ref`        | Reference to the generated patch.                 |
| `model`            | The runtime planner model that produced the plan. |
| `cost_usd`         | Planner cost for the run.                         |

{% hint style="info" %}
By default, `codna_fix` **plans** the fix and returns a `patch_ref`; it does not apply patches to a local checkout. Set `open_pr=true` only when the repo is a git URL and the MCP server environment contains a write-capable GitHub token. To apply a patch directly to a local checkout, use `codna fix --apply` from the command line (see [CLI Reference](https://docs.codna.ai/reference/cli.md)).
{% endhint %}

With `open_pr=true`, the tool returns the opened PR URL instead of a local patch reference:

```json
{
  "root_cause": "Checkout total subtracts discounts twice, so carts with coupons underflow.",
  "confidence": 0.78,
  "pull_request_url": "https://github.com/acme/shop/pull/482",
  "status": "opened_pull_request",
  "model": "repository.verified_agentic_v1"
}
```

### `codna_secure`

Proves which scanner findings are reachable. Ingests a SARIF report (CodeQL, Semgrep, Snyk, or Trivy), classifies each finding (`exploitable`, `production-reachable`, `unreachable`, or `unknown`), and reports which are autofix-eligible. Read-only. 0 model tokens.

| Parameter    | Type   | Default    | Description                                                                                                  |
| ------------ | ------ | ---------- | ------------------------------------------------------------------------------------------------------------ |
| `repo`       | string | `.`        | A local path or a git URL.                                                                                   |
| `sarif_path` | string | (required) | Path to the scanner's SARIF output. If empty, the tool returns `codna_secure error: sarif_path is required`. |
| `ref`        | string | `""`       | Optional branch, tag, or commit.                                                                             |

The SARIF report must carry complete provenance. If it does not, the tool returns `codna_secure error: SARIF provenance incomplete: …` listing the missing fields, and does nothing else. On success it returns:

```json
{
  "counts": {
    "production-reachable": 2,
    "unreachable": 5,
    "unknown": 1
  },
  "autofix_eligible": 2,
  "findings": [
    {
      "rule_id": "py/sql-injection",
      "kind": "sql-injection",
      "classification": "production-reachable",
      "eligible": true,
      "reason": "autofix-eligible"
    },
    {
      "rule_id": "py/clear-text-logging",
      "kind": "sensitive-data",
      "classification": "unreachable",
      "eligible": false,
      "reason": "no reachable path from an entry point"
    }
  ]
}
```

| Field              | Meaning                                                                         |
| ------------------ | ------------------------------------------------------------------------------- |
| `counts`           | A map of classification to count across all findings.                           |
| `autofix_eligible` | Total number of findings Codna deems autofix-eligible.                          |
| `findings[]`       | Per-finding `rule_id`, `kind`, `classification`, `eligible` flag, and `reason`. |

{% hint style="info" %}
The MCP `codna_secure` tool classifies and reports only. To remediate eligible findings or open security fix PRs, use `codna secure --fix` / `--open-pr` from the command line. See [Security Autofix](https://docs.codna.ai/guides/security-autofix.md).
{% endhint %}

### `codna_recall`

Recalls code from local on-device memory. Read-only and local; it does not call a model or change the repository. Like every tool on this page, it requires the one-time free `codna login` (device authorization, free community license); the same `codna login` installs the on-device memory runtime, and after that recall runs fully offline with no key.

| Parameter  | Type    | Default    | Description                                                                                           |
| ---------- | ------- | ---------- | ----------------------------------------------------------------------------------------------------- |
| `repo`     | string  | `.`        | Local repository path to index and search.                                                            |
| `query`    | string  | (required) | Natural-language or symbol query. If empty, the tool returns `codna_recall error: query is required`. |
| `service`  | string  | `""`       | Optional service/module filter.                                                                       |
| `language` | string  | `""`       | Optional language filter.                                                                             |
| `final_k`  | integer | `8`        | Maximum number of recalled results.                                                                   |

Returns a JSON object with ranked symbols (each with `id`, `score`, `symbol_type`, `path`), an `explain` payload, and the number of candidates searched:

```json
{
  "symbols": [
    {
      "id": "src/checkout/pricing.py::apply_discount",
      "path": "src/checkout/pricing.py",
      "symbol_type": "function",
      "score": 0.93
    }
  ],
  "explain": {
    "query": "checkout discount calculation",
    "final_k": 8
  },
  "candidate_count": 41
}
```

Recall indexes for the MCP server live outside your checkout, under `~/.codna/telys-memory/mcp/` (override with `CODNA_TELYS_MEMORY_ROOT`). See [Code Memory](https://docs.codna.ai/concepts/memory.md).

### `codna_report_bug`

Files a bug, feature request, or question to [thyn-ai/feedback](https://github.com/thyn-ai/feedback), the public front door for algenta, codna, telys, and sqai. This is a write: it creates a real GitHub issue, unlike every other tool on this page.

| Parameter             | Type    | Default    | Description                                                                                                 |
| --------------------- | ------- | ---------- | ----------------------------------------------------------------------------------------------------------- |
| `title`               | string  | (required) | A short summary. If empty, the tool returns `codna_report_bug error: title is required`.                    |
| `body`                | string  | `""`       | What happened, or what you want, in as much detail as you have.                                             |
| `product`             | string  | `codna`    | One of `algenta`, `codna`, `telys`, `sqai`, `accounts`, `docs`.                                             |
| `include_diagnostics` | boolean | `false`    | Attach the same redacted output `codna doctor` prints: presence and source of config, never a secret value. |

Filing needs a GitHub token the MCP server's environment can see (`GITHUB_TOKEN`, `GH_TOKEN`, or an already-authenticated `gh` CLI on `PATH`). Without one, or if the network call fails, the tool does not error out: it returns a pre-filled `github.com/.../issues/new` link instead, so nothing is lost.

```json
{
  "submitted": true,
  "url": "https://github.com/thyn-ai/feedback/issues/128",
  "local_path": null
}
```

When it falls back, `submitted` is `false`, `url` is the pre-filled link, and `local_path` points at a saved copy of the report on disk (under `CODNA_RUNTIME_ROOT`).

This is the same submission path the `codna report` CLI command uses (see [CLI Reference](https://docs.codna.ai/reference/cli.md#codna-report)), so an agent and a human land in the same place with the same fields.

## The browser tool

Codna can drive a real browser: open a page, read its accessible text, click, type, wait, and take a screenshot. That is what makes a browser check an agent can perform rather than a human's job — navigate, assert, act, assert again.

It is **off by default**. A browser is a network client that loads untrusted code and writes files, so it is opt-in:

```bash
export CODNA_BROWSER_TOOL=1
codna mcp browser      # what will launch, and whether it can
```

`codna mcp browser` starts nothing: it prints the resolved configuration, the exact `npx` command that would run, and whether this machine can run it.

### What it needs

**Node.js 18+ on `PATH`, and a browser.** Codna runs [Playwright's own MCP server](https://github.com/microsoft/playwright-mcp) — pinned, as `@playwright/mcp@0.0.85` — rather than re-implementing a browser driver, and that server is what launches Chromium. Codna ships the Python *launcher* and nothing else: **no Node, and no browser**, in the app bundle or the wheel. Both are runtime prerequisites of the machine, not payloads of the product.

`npx` missing is blocking, and is reported as such — with a machine-readable `reason_code` beside the sentence:

```
the browser tool is on but `npx` is not on PATH. Install Node.js 18+, or point
CODNA_BROWSER_PACKAGE at a local @playwright/mcp install — Codna does not bundle Node.
```

```json
{ "enabled": true, "launchable": false, "reason_code": "browser_tool_npx_missing" }
```

The first launch downloads the pinned package and its browser through `npx`; after that it runs from the local cache. So an **empty browser cache is not a failure** — it is a first-run download that needs network. `codna mcp browser` reports it as a coded warning and leaves `launchable` alone, because the launcher *can* start; it is the download that may fail offline:

```json
{ "launchable": true,
  "warnings": [{ "code": "browser_chromium_not_cached",
                 "message": "no Playwright browser is in the local cache yet, so the FIRST launch downloads Chromium through `npx` (needs network)…" }] }
```

That warning is skipped when `CODNA_BROWSER_NAME` names an installed channel (`chrome`, `msedge`, …) — those do not use the Playwright cache — and is reported as *unknown* rather than *missing* when `PLAYWRIGHT_BROWSERS_PATH=0` puts the browser inside the package, where it cannot be found without launching.

No `codna login` is needed — browsing is local.

### The tools

Seven tools, registered only when the switch is on. A tool listed and then refusing every call is a worse contract than a tool that is absent, so the switch decides whether they exist at all.

| Tool                       | What it does                                                       | Playwright tool           |
| -------------------------- | ------------------------------------------------------------------ | ------------------------- |
| `codna_browser_navigate`   | Open a URL, return the page's accessible text.                     | `browser_navigate`        |
| `codna_browser_snapshot`   | Read the current page as accessible text. The assertion primitive. | `browser_snapshot`        |
| `codna_browser_click`      | Click an element, return the page after the click.                 | `browser_click`           |
| `codna_browser_type`       | Type into an input or contenteditable.                             | `browser_type`            |
| `codna_browser_screenshot` | Screenshot the page and return the **image**.                      | `browser_take_screenshot` |
| `codna_browser_wait`       | Wait for text to appear or disappear, or for a pause.              | `browser_wait_for`        |
| `codna_browser_close`      | Close the session and its browser process.                         | —                         |

The session is **one live page**, reused across calls, because "navigate, then click what the snapshot showed" is only meaningful if the page outlives the call. It starts lazily on the first browser call — listing tools costs nothing — and `codna_browser_close` shuts it down.

The allowlist above is the whole surface. Playwright also ships `browser_evaluate` and `browser_run_code_unsafe` (arbitrary in-page JavaScript), `browser_file_upload` and `browser_handle_dialog`; none of them is reachable through Codna.

### Screenshots

`codna_browser_screenshot` returns real image content, not a path in text, so the model sees the page. The file is also written to `$CODNA_RUNTIME_ROOT/browser` (default `~/.codna/browser`), which is where every other piece of Codna's local state lives — never your checkout.

`filename` is a name **relative to that directory**. An absolute path or `..` is refused rather than clamped, because a tool that writes wherever a model says can overwrite a source file.

### Settings

| Variable                              | Purpose                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Default                       |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| `CODNA_BROWSER_TOOL`                  | `1` turns the tool on. Unset/`0` is off. A value in neither set is refused.                                                                                                                                                                                                                                                                                                                                                                               | unset (off)                   |
| `CODNA_BROWSER_PACKAGE`               | The Playwright MCP package to run. Pinned so a browser check means the same thing tomorrow.                                                                                                                                                                                                                                                                                                                                                               | `@playwright/mcp@0.0.85`      |
| `CODNA_BROWSER_OUTPUT_DIR`            | Where screenshots are written.                                                                                                                                                                                                                                                                                                                                                                                                                            | `$CODNA_RUNTIME_ROOT/browser` |
| `CODNA_BROWSER_HEADLESS`              | `0` shows a visible window (useful while debugging a check).                                                                                                                                                                                                                                                                                                                                                                                              | `1`                           |
| `CODNA_BROWSER_ISOLATED`              | `0` keeps the browser profile on disk between sessions.                                                                                                                                                                                                                                                                                                                                                                                                   | `1`                           |
| `CODNA_BROWSER_VIEWPORT`              | Page viewport, `WIDTHxHEIGHT`.                                                                                                                                                                                                                                                                                                                                                                                                                            | `1280x720`                    |
| `CODNA_BROWSER_NAME`                  | Browser channel: `chrome`, `firefox`, `webkit`, `msedge`. Empty uses the bundled Chromium.                                                                                                                                                                                                                                                                                                                                                                | empty                         |
| `CODNA_BROWSER_FILE_ACCESS`           | `unrestricted` passes `--allow-unrestricted-file-access`, which is also what makes `file://` URLs work. **This widens access**; leave it unset unless you need it.                                                                                                                                                                                                                                                                                        | `restricted`                  |
| `CODNA_BROWSER_ACTION_TIMEOUT_MS`     | Per-action timeout.                                                                                                                                                                                                                                                                                                                                                                                                                                       | `5000`                        |
| `CODNA_BROWSER_NAVIGATION_TIMEOUT_MS` | Per-navigation timeout.                                                                                                                                                                                                                                                                                                                                                                                                                                   | `60000`                       |
| `CODNA_BROWSER_OUTPUT_MAX_BYTES`      | Screenshot eviction threshold for the output directory.                                                                                                                                                                                                                                                                                                                                                                                                   | `67108864`                    |
| `CODNA_BROWSER_CONNECT_TIMEOUT_S`     | How long the MCP client may wait for one exchange with the browser server, in seconds. Raises the engine's 1.5 s unconfigured connect probe, which a cold `npx @playwright/mcp` start (\~1.3 s) intermittently loses — and a lost race drops the server, leaving the session with no browser tool at all. Floored at `10` and at `CODNA_BROWSER_NAVIGATION_TIMEOUT_MS` (the engine applies it to tool calls too); values outside `10`–`3600` are refused. | `180`                         |

**The connect timeout is not a generation bound.** It bounds one MCP exchange — the `initialize` handshake and each `tools/call` — not how long a run may think. The engine applies the same number to both, so the default is set to clear the larger one: a `browser_navigate` may legitimately run for Playwright's 60 s navigation timeout, so 180 s is chosen (60 s navigation + the bridge's 30 s call margin with room to spare) and it is also the same budget `browser_bridge` gives the server to answer `initialize` in-process. Setting it below `CODNA_BROWSER_NAVIGATION_TIMEOUT_MS` is refused rather than silently truncating navigations that would have succeeded.

`data:` URLs and a loopback HTTP server need **no** widening — that is how a just-built app is served, and it is what the smoke test uses.

### Where the tool is available

The same server entry reaches every path Codna carries MCP servers on, so a check that works in one works in the others:

* **`codna mcp`** registers the seven tools above, for Cursor, Claude Desktop or any MCP client.
* **A durable run** (`codna run`, goal mode) attaches it automatically when the switch is on. If the run's own config already defines a server named `browser`, that one wins.
* **The IDE chat panel** carries it too, including in a repository with no `.codna/mcp.json` at all.

### Verify it works

```bash
CODNA_BROWSER_TOOL_E2E=1 python -m pytest cli/tests/test_browser_tool_e2e.py
```

That is a live smoke test: it starts the real server, serves a page over loopback, and asserts that navigating reads the page, that a click changes it, that typing lands, that a screenshot is a real PNG, and that waiting for absent text times out instead of hanging. It is gated because it needs Node and a browser; without the variable it skips.

### In the packaged app

The desktop app runs the bridge from its own payload rather than from a `pip` install: `python -m codna.mcp_bridge` is executed by the **bundled** CPython (`Resources/telys/python/bin/python3.12`) with the payload's `site-packages` on its path. Both halves are required, and each was a defect found on a shipped build:

* **the modules must be staged.** The package ships the *closure* the app imports, computed by importing the entry modules in a sandbox (`-S`, so the build machine's packages cannot mask a gap) and then **calling** the ones whose real imports live inside a function body. That second step is not optional: `rules_bridge`, `skills_bridge` and `agents_bridge` import `codna.rules` inside `handle()`, and `cli` reaches the durable stack inside `build_parser()`, so an import-only closure closes cleanly and still fails the first call;
* **the interpreter must be the payload's.** A bare `python3` on the user's `PATH` is the host's, and its `site-packages` is not the bundle's — measured: `python3 -m codna.mcp_bridge` answered `ModuleNotFoundError: No module named 'codna'` with the files staged correctly. Every bridge spawner therefore resolves its interpreter through the same install resolver the memory helpers use (`resolveTelysEnv`), and a dev checkout keeps the `python3` fallback.

`install-manifest.json` records what was staged, with a SHA-256 per file, and the build refuses to produce a payload whose bridges do not answer. The project-rules, subagent-roster, skills and scheduler bridges are covered by the same staging and the same resolver — a bridge that cannot run reports a coded `unavailable` state instead of an empty list, so "the reader never ran" is never presented as "you have none".

## Install into a client

Instead of hand-editing the config, let Codna write the client entry for you:

```bash
codna mcp install --client cursor            # writes ~/.cursor/mcp.json
codna mcp install --client cursor --project  # writes ./.cursor/mcp.json (repo-scoped)
codna mcp install --client claude            # writes the Claude Desktop config
```

* `--client cursor|claude` (required) picks the client.
* `--project` writes the project-local Cursor config instead of the user config (Cursor only).
* `--repo <repo>` bakes a default repo into the server entry.

The command merges a `codna` server into `mcpServers` (preserving any existing servers), writes atomically, and prints a JSON summary with the resolved config `path`. It does **not** write credentials. Store your provider key with `codna key set`, or add it to the config's `env` block afterward. To configure a client by hand instead, use the blocks below.

## Editor setup

Both clients use the same `codna` server block; only the config file location differs. Pick your client below.

{% tabs %}
{% tab title="Cursor" icon="laptop-code" %}
Add a `codna` entry to your MCP servers configuration. Use `~/.cursor/mcp.json` for all projects, or `.cursor/mcp.json` inside a project for project-scoped access:

{% code title=".cursor/mcp.json" lineNumbers="true" %}

```json
{
  "mcpServers": {
    "codna": {
      "command": "codna",
      "args": ["mcp"],
      "env": {
        "ANTHROPIC_API_KEY": "$ANTHROPIC_API_KEY"
      }
    }
  }
}
```

{% endcode %}

After saving, reload Cursor's MCP servers (Settings → MCP, or restart). The `codna_triage`, `codna_fix`, `codna_secure`, `codna_recall`, and `codna_report_bug` tools then become available to the agent. Paste the key value in place of `$ANTHROPIC_API_KEY`, or leave the `env` block out when the key is in the OS keychain (`codna key set anthropic`).
{% endtab %}

{% tab title="Claude Desktop" icon="message" %}
Add the same block to your Claude Desktop configuration file, on macOS at `~/Library/Application Support/Claude/claude_desktop_config.json`:

{% code title="claude\_desktop\_config.json" lineNumbers="true" %}

```json
{
  "mcpServers": {
    "codna": {
      "command": "codna",
      "args": ["mcp"],
      "env": {
        "ANTHROPIC_API_KEY": "$ANTHROPIC_API_KEY"
      }
    }
  }
}
```

{% endcode %}

Restart Claude Desktop to load the server. The five Codna tools then appear in the tools (plug) menu in the message composer.
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
`"command": "codna"` requires the `codna` executable to be on the `PATH` of the process that launches the MCP client, which is often **not** your shell's `PATH` (GUI apps on macOS frequently ignore it). If the client cannot find it, set `command` to the absolute path of the binary, the output of `which codna`:

```json
{
  "mcpServers": {
    "codna": {
      "command": "/Users/you/.venvs/codna/bin/codna",
      "args": ["mcp"]
    }
  }
}
```

{% endhint %}

## Example prompts

Once a client is connected, you drive Codna in natural language; the client picks the tool and fills the parameters:

```
Use codna to triage this repo and tell me where the auth code lives.
```

```
codna_triage the github.com/acme/api repo for "checkout returns 500 on empty cart"
```

```
The test tests/test_session.py::test_expiry is failing — use codna to find and fix the bug.
```

```
Run codna_fix on this repository for the issue "JWT refresh tokens never expire" and show me the root cause and confidence.
```

```
I have a CodeQL report at ./results.sarif — use codna to tell me which findings are actually reachable.
```

```
Recall where discounts are applied in this repo.
```

```
File a bug: codna fix hangs on a monorepo. Include diagnostics.
```

## End-to-end: Cursor on a local repo

{% stepper %}
{% step %}

#### Install Codna with the MCP extra

```bash
pip install "codna[mcp]"
codna key set anthropic
```

{% endstep %}

{% step %}

#### Write the Cursor config

```bash
codna mcp install --client cursor --project
```

This writes `.cursor/mcp.json` in the repository with a `codna` server entry (`"command": "codna"`, `"args": ["mcp"]`). If Cursor cannot find `codna` on its `PATH`, set `command` to the output of `which codna`.
{% endstep %}

{% step %}

#### Reload MCP servers in Cursor

The `codna` server shows five tools.
{% endstep %}

{% step %}

#### Drive Codna from the agent panel

In the agent panel, type:

```
Use codna_triage on . and summarize the suspect files.
```

Codna returns the suspect files and the context-reduction ratio, and the agent summarizes them. From there, ask it to `codna_fix` a specific issue. Use `open_pr=true` for a git URL when you want Codna to open a PR, or take the returned `patch_ref` to the CLI to apply it locally.
{% endstep %}
{% endstepper %}

## Verifying the server

You can confirm the server starts by running it directly. It will block waiting for a client; that is success:

```bash
codna mcp
```

Nothing is printed and the process does not exit. Press Ctrl-C to stop. To confirm the client side, check your MCP client's logs for the `codna` server connecting and discovering five tools.

## Troubleshooting

<details>

<summary>Server not detected / tools missing in the client</summary>

The client could not spawn `codna mcp`. Most often `codna` is not on the launching process's `PATH`. Fix by pointing `command` at the absolute path from `which codna` (see the editor-setup warning above), or run `codna mcp install --client cursor|claude`, then reload the client. Verify the binary runs at all:

```bash
codna --version
```

```
codna 0.x.y
```

</details>

<details>

<summary><code>MCP support isn't installed</code> or <code>ModuleNotFoundError: No module named 'mcp'</code></summary>

The `mcp` extra is not installed in the interpreter the client launches. Install it into the **same** interpreter the MCP `command` path points at:

```bash
which codna
python -m pip install --upgrade "codna[mcp]"
```

A mismatched virtualenv is the usual cause of "I installed it but it still fails."

</details>

<details>

<summary><code>codna_fix</code> fails on the model call</summary>

The server did not see a provider key. Store one with `codna key set <provider>`, or add it to the `env` block of the server entry (GUI clients do not inherit your shell environment), then reload the client.

</details>

<details>

<summary><code>codna_secure</code> rejects the SARIF</summary>

Two specific errors come from this tool:

```
codna_secure error: sarif_path is required
```

Pass a `sarif_path`. And:

```
codna_secure error: SARIF provenance incomplete: <missing fields>
```

The report lacks the provenance Codna requires to bind findings to a commit. Re-run your scanner so its SARIF records the full commit and the driver name and version, then retry.

</details>

<details>

<summary><code>repo</code> is neither a directory nor a URL</summary>

If `repo` is not an existing local directory and not an `http(s)://` or `.git` URL, the tool errors with:

```
'<repo>': not a local directory or a git URL.
```

Pass an absolute or relative path to a real checkout, or a git URL.

</details>

## Using MCP servers in the Codna IDE chat

Everything above is Codna acting as an MCP **server**. The IDE chat panel is the other direction: it can **carry** MCP servers into a session, so a database or Linear integration you configured is available while you type in chat — not only in `codna run`.

### Where the IDE looks

One precedence order, highest first. The first file to define a server name wins.

| Source                                                            | Kind   | Notes                                                 |
| ----------------------------------------------------------------- | ------ | ----------------------------------------------------- |
| `<workspace>/.codna/mcp.json`                                     | Codna  | Codna's own format.                                   |
| `~/.codna/mcp.json`                                               | Codna  | User scope.                                           |
| `<workspace>/.cursor/mcp.json`                                    | Cursor | Read as-is — a migrating repository needs no changes. |
| `~/.cursor/mcp.json`                                              | Cursor |                                                       |
| `<workspace>/.theia/settings.json` → `ai-features.mcp.mcpServers` | Theia  | Migration source only.                                |
| `~/.theia/settings.json` → same key                               | Theia  |                                                       |

All of these are read and validated by the **same** validator durable runs use (`codna.durable.mcp`), through `python -m codna.mcp_bridge`. The three transports, the 16-server cap, and the `{"from_env": "NAME"}` rule are therefore identical on both surfaces.

### Cursor's format works unmodified

Cursor spells a local server without a transport discriminant, and a remote one as `url`:

```json
{
  "mcpServers": {
    "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"] },
    "linear": { "command": "npx", "args": ["-y", "linear-mcp"], "env": { "LINEAR_API_KEY": "lin_api_…" } },
    "docs": { "url": "https://mcp.example.com/mcp" }
  }
}
```

That file is used as written. One thing changes, and it is deliberate: a **literal** value under `env` is not used. The variable is read from the environment at launch instead, and the IDE logs a warning saying so. The value is never serialized into a session request, so a credential in a config file cannot end up in a request body, a log, or a replay.

### Codna's own format is the durable format

```json
{
  "mcpServers": {
    "linear": {
      "transport": {
        "type": "stdio",
        "command": "npx",
        "args": ["-y", "linear-mcp"],
        "env": { "LINEAR_API_KEY": { "from_env": "LINEAR_API_KEY" } }
      }
    },
    "docs": { "transport": { "type": "streamableHttp", "url": "https://mcp.example.com/mcp" } }
  }
}
```

A literal value here is **refused** — the durable path refuses it because the spec is history, and the chat path refuses it for the same reason rather than accepting what a durable run denies.

### How a secret reaches the server

The reference is resolved without putting anything on the wire. The engine spawns an MCP stdio child with `env: {...process.env, ...transport.env}`, so a variable that is in the **sidecar's** environment is already in the child's. The create-session request therefore carries no `env` at all.

The sidecar's environment is an explicit allowlist (`sidecarProcess.ts` `ENV_ALLOWLIST`, plus `CODNA_TELYS_*` plumbing). A variable an MCP server needs must be added to that list **on purpose**. If it is not there, session creation fails with `mcp_env_not_forwarded` and names the variable — it never starts a server that silently lacks its credential.

### What does not work yet, and is refused rather than dropped

A **remote** server that carries an auth header (`serverAuthToken` in Theia's format, or a `headers` block) is refused with `mcp_remote_auth_unsupported`. A header value read from a config file is a credential, and the engine accepts string header values only — there is no reference form for a header, so there is no shape that carries it without serializing it. Use a local server (whose credentials travel as environment references) or a server that authenticates over OAuth.

### Theia's registry is bridged one way

Codna **reads** Theia's MCP registry so a server added through Theia's own UI is visible to Codna chat. The reverse is not bridged: a server defined only in `.codna/mcp.json` does not appear in Theia's MCP UI. Codna chat is the surface those servers are for, and mirroring one file into another product's preference store would create two writers for the same setting.

* [CLI Reference](https://docs.codna.ai/reference/cli.md) — the `codna` command, including `codna fix --apply` / `--open-pr` to act on a plan.
* [Security Autofix](https://docs.codna.ai/guides/security-autofix.md) — `codna secure` reachability proofs and remediation PRs.
* [Code Memory](https://docs.codna.ai/concepts/memory.md) — how `codna_recall` builds and queries the index.
* [Configuration](https://docs.codna.ai/reference/configuration.md) — environment variables and the `codna.yaml` file.
