---
url: /en/develops/mcp.md
description: >
  Explains how to expose CNB capabilities to AI clients over MCP (Model Context
  Protocol): one config entry lets an Agent log in, run cnb commands, and fetch
  platform guides on demand.
---
**MCP Setup** explains how to hand CNB platform capabilities to an AI client as an MCP server.

**When to use**: when you would rather not install the local [CNB CLI](./cnb-cli.md) and
[Skills](./skills.md), and only want a single MCP config entry so an Agent can work with CNB —
for example letting the AI view repositories, create issues, or query build status, or fetch
platform guides such as how to write `.cnb.yml`.

`cnb mcp` starts a local MCP server over stdio and wraps every OpenAPI command of the CLI into a
single `cnb_run` tool. Command usage (common commands, parameters, output conventions) ships inside
the tool description and always matches the CLI version you run.

## Configure the MCP Server

Add one entry to your client's MCP config:

```json title="mcp.json"
{
  "mcpServers": {
    "cnb": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@cnbcool/cnb-cli@latest", "mcp"]
    }
  }
}
```

Where common clients keep it:

* CodeBuddy: Settings → MCP, stored in `~/.codebuddy/mcp.json`
* Claude Desktop: `claude_desktop_config.json`
* Other clients that accept a `mcpServers` stdio config work the same way

Two things you can change in `args`:

* **Version**: `@latest` pulls the latest release on every start; pin the major version with `@1`
* **Platform**: append `"--host", "<platform domain>"` to lock the platform, which is useful for
  private deployments or when the workspace is not a CNB repository. A port is allowed; no scheme
  prefix is needed

## Available Tools

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `cnb_run` | Runs any `cnb` command, covering all OpenAPI operations: issues, PRs, repositories, builds, artifact registries | `args`: argument array after `cnb`; `cwd`: absolute workspace path |
| `cnb_guide` | Returns platform guides on demand: `.cnb.yml` syntax and CI troubleshooting, attachment uploads, how to query the official docs | `query`: search; `name` + `path`: topic and volume; `cwd` |
| `cnb_status` | Shows login status and refreshes the token automatically when it expires | `cwd` |
| `cnb_login` | OAuth2 device authorization login, returns an authorization link | `cwd` |
| `cnb_logout` | Logs out and removes the local credentials for that platform | `cwd` |

`cnb_run` passes `args` to the CLI as an array, without a shell: multi-line bodies go in as a single
element, for example `["issues","comment","--number","12","--body","line 1\nline 2"]`, with no
quoting or escaping. The `login` and `mcp` subcommands are blocked; use `cnb_login` to log in.

`cnb_guide` fetches content on demand, so it does not occupy the context permanently. With no
arguments it lists all topics; `{"query":"cron job not triggered"}` returns the most relevant
excerpts with sources; `{"name":"cnb-pipeline"}` returns the main file plus its volumes, and
`{"name":"cnb-pipeline","path":"crontab.md"}` returns one volume.

## Platform and Repository Inference

* **Platform**: the `--host` startup argument → the git remote of `cwd` → the `CNB_API_ENDPOINT`
  environment variable → `cnb.cool`. The resolved platform decides both the API domain and which
  credentials are read
* **Repository**: when `--repo` is omitted, it is inferred from the git remote of `cwd`
  (`https://`, `ssh://`, and `git@host:org/repo.git` are all supported); pass
  `--repo org/repo` explicitly for cross-repository operations or when `cwd` is not a git repository
* **Precedence**: an explicit `--repo` always wins over the inferred value

## First Use: Log In

1. Call `cnb_status` (pass the workspace path) to check login status, then follow the returned hint
2. Call `cnb_login` and give the returned authorization link to the user; clients that support URL
   elicitation show the link directly
3. After the user confirms in the browser, call `cnb_status` again to confirm the login

Once logged in, use `cnb_run` for your tasks without repeating the repository on every call:

```json
{
  "args": ["issues", "list-issues", "--state", "open", "--page-size", "5"],
  "cwd": "/path/to/repo"
}
```

For commands outside the quick reference, have the Agent call `["<module>","--help"]` to look up the
parameters first.

## Authentication and Security

* The token lives in `~/.cnb/token` (mode `600`) and is shared with `cnb login`; authorizations
  obtained through MCP are written there too
* `cnb_login` uses the device code flow and never handles your password; the authorization link is
  valid for about 10 minutes
* Credentials are stored per platform domain, and `cnb_status`, `cnb_login`, and `cnb_logout` all
  resolve the platform with the same rules

## Relationship with Skills

MCP covers every CLI command, so it is equivalent to "the `cnb-api` Skill + the CLI" and you do not
need to install Skills as well.

Platform guidance is built in as `cnb_guide`, whose content comes from `cnb-pipeline`,
`cnb-upload-attachment`, and `cnb-docs` in the
[Skills repository](https://cnb.cool/cnb/skills/cnb-skill), and follows the CLI version.

If you do not configure MCP and let an Agent work locally, or you need Skills that are not built in
such as `cnb-code-review` or `cnb-code-commit`, install [Skills](./skills.md) as described.

## FAQ

| Symptom | What to do |
| --- | --- |
| `cnb_status` reports not logged in | Call `cnb_login`, confirm in the browser, then call `cnb_status` again |
| "Not a git repository, cannot infer repository" | `cwd` is not a git repository or has no remote: pass `--repo org/repo` explicitly, or point `cwd` at the workspace |
| Commands hit the wrong platform | Check the git remote of `cwd`, or add `"--host", "<platform domain>"` to the config |
| `unknown option` on a parameter | The CLI suggests the correct spelling (for example `--page-size`) with full help; follow the hint |
| Output is truncated | Output over 100KB returns only the head and tail, with the full content written to a temp file; drop `--verbose` or page through the results |

## Related Documentation

* [CNB CLI](./cnb-cli.md) — the command-line tool the MCP server calls; see `cnb mcp --help` for its
  parameters
* [Skills](./skills.md) — the capability set installed in runtime images, an alternative to MCP
* [NPC](../build/npc.md) — the built-in AI assistant that works with Skills
* [OpenAPI](./openapi.md) — the API that `cnb_run` ultimately calls
