# axle mcp

The MCP server that lets AI coding agents ask Axle about the repository and run its tasks, and axle setup agents, which configures them.

```sh
axle setup agents
axle mcp
```

`axle mcp` is a [Model Context Protocol](https://modelcontextprotocol.io/) server, so an AI coding agent can ask Axle which projects and tasks there are, what a change affects and why a task wasn't cached, and run tasks the way `axle run` does. Agents start it themselves; [`axle setup agents`](#setting-up-agents) tells them how. [Using Axle with AI agents](https://axlers.dev/docs/getting-started/ai-agents.md) walks through it.

## Tools

| Tool            | Arguments                     | Answer                                                                                                                                   |
| --------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `list_projects` | `filter`, `affected`          | the JSON of [`axle list --json`](https://axlers.dev/docs/reference/list.md#json-output)                                                                      |
| `show_project`  | `name`                        | the JSON of [`axle show --json`](https://axlers.dev/docs/reference/show.md): a package's task settings, its description among them, and where each came from |
| `list_tasks`    | `tasks`, `filter`, `affected` | the JSON of [`axle graph --format json`](https://axlers.dev/docs/reference/graph.md): each task a run would include, its description, and what it waits for  |
| `affected`      | `base`, `head`                | the JSON of [`axle affected --json`](https://axlers.dev/docs/reference/affected.md): the packages a change affects, and why                                  |
| `explain_miss`  | `task`, such as `web#build`   | the text of [`axle why miss`](https://axlers.dev/docs/reference/cache.md#why-a-task-ran)                                                                     |
| `run_tasks`     | `tasks`, `filter`, `affected` | each task's status, and the last 200 lines of each failed task's output                                                                  |

`tasks` is a list of task names, such as `["build"]` or `["web#test"]`, as for [`axle run`](https://axlers.dev/docs/reference/run.md). `filter` is a list of [package selectors](https://axlers.dev/docs/reference/run.md#choosing-packages), such as `["web..."]`, and `affected` is `true` to keep only the packages a change affects. `base` and `head` are the branch, tag or commit to compare, as for [`axle affected`](https://axlers.dev/docs/reference/affected.md).

Each answer is JSON text, also given as `structuredContent`, except `explain_miss`, which answers in words, and `run_tasks`, whose text is a summary with each failed task's output and whose JSON is in `structuredContent`. Warnings come as a second piece of text. When Axle can't answer, such as for a package that doesn't exist, the result has `isError` and Axle's error message.

## Running tasks

`run_tasks` is the only tool that changes anything. It runs with the cache and the repository's settings, as `axle run` would, never with `--force`, and returns:

```json
{
    "passed": 2,
    "cached": 1,
    "failed": 1,
    "skipped": 0,
    "durationMs": 2310,
    "tasks": [
        { "task": "ui#build", "status": "cached", "exitCode": 0, "durationMs": 12 },
        {
            "task": "web#build",
            "status": "failed",
            "exitCode": 2,
            "durationMs": 2280,
            "output": ["src/app.ts(3,7): error TS2322: …"]
        }
    ],
    "warnings": []
}
```

`passed` counts the tasks that came from the cache too. `status` is `passed`, `cached`, `failed` or `stopped`, as in [`axle run`'s JSON events](https://axlers.dev/docs/reference/run.md#json-events), or `skipped`, with a `reason`, for a task that never started because a task it waits for failed. A failed task's `output` holds its last 200 lines. When a task fails, the result has `isError`, so the agent sees the failure as one. `run_tasks` refuses persistent tasks, such as dev servers, since they never finish; start those in a terminal.

## How it works

The server speaks JSON-RPC 2.0 over standard input and output, one message per line, and supports MCP versions 2025-11-25, 2025-06-18 and 2025-03-26. It answers `initialize`, `ping`, `tools/list` and `tools/call`. An unknown method or tool, or a request without `"jsonrpc": "2.0"` or with a `null` id, gets a JSON-RPC error, a notification gets no answer, and a wrong argument gets a result with `isError`. It answers one call at a time, so while `run_tasks` runs, the next call waits for it, and a run can't be cancelled from the agent; stopping the server stops the run.

For each call it runs the `axle` executable it was started from, in the folder it was started in, with `--json` where the command has it. So every answer reads the repository as it is then, and nothing a task prints can get into the protocol. Settings from the environment, such as [`AXLE_CACHE`](https://axlers.dev/docs/reference/system-environment-variables.md), apply as they would in a terminal.

## Setting up agents

```sh
axle setup agents
axle setup agents --agent claude
axle setup agents --dry-run
```

Writes the configuration that starts `axle mcp` into the repository, for each agent that reads one from there, and guidance on working with Axle where each agent looks for instructions:

| Agent                   | Server                  | Guidance                       |
| ----------------------- | ----------------------- | ------------------------------ |
| Claude Code             | `.mcp.json`             | `.claude/skills/axle/SKILL.md` |
| Cursor                  | `.cursor/mcp.json`      | `AGENTS.md`                    |
| GitHub Copilot, VS Code | `.vscode/mcp.json`      | `AGENTS.md`                    |
| Gemini CLI              | `.gemini/settings.json` | `AGENTS.md`                    |

Each server file gets an `axle` server and keeps everything else in it, comments included. A file that already has an `axle` server is left alone, so running the command again changes nothing. Gemini CLI reads only `GEMINI.md` unless told otherwise, so `.gemini/settings.json` also gets `AGENTS.md` added to `context.fileName`, next to `GEMINI.md` or the names already there.

The guidance tells an agent to run tasks through `axle run`, with `--affected` before committing, how to see what a change affects and why a task missed the cache, where the settings are, and that the MCP server exists. It names the command that runs Axle in this repository, such as `pnpm exec axle`, and the usual tasks it has, such as `build`, `lint` and `test`. In `AGENTS.md` it's a short section between two lines:

```md
<!-- Start of Axle's guidance, written by axle setup agents -->

## Axle

…

<!-- End of Axle's guidance -->
```

Running the command again rewrites only what's between them and keeps the rest of the file; a file without them gets the section at its end, and one with only one of them is an [error](https://axlers.dev/docs/messages/file-has-a-mistake.md). The [Agent Skill](https://code.claude.com/docs/en/skills) for Claude Code says the same in more depth, with a `name` and a `description` that tell Claude Code when to load it, between the same lines, so it's kept up to date the same way.

Commit the files, and whoever opens the repository with one of these agents gets Axle's tools and knows how to use them.

The server runs `axle mcp`, unless the root `package.json` lists `@axle-rs/axle`; then it runs that copy with Node, as `node node_modules/@axle-rs/axle/bin/axle.js mcp`, which works the same on every system and with every package manager, or as `yarn axle mcp` with Yarn's Plug'n'Play, which has no `node_modules`. The VS Code entry also sets `cwd` to the workspace folder, so the path is found from wherever VS Code starts it.

| Option            | What it does                                          |
| ----------------- | ----------------------------------------------------- |
| `--agent <AGENT>` | sets up only `claude`, `cursor`, `vscode` or `gemini` |
| `--dry-run`       | shows the changes as a diff, and writes nothing       |

`--agent claude` writes `.mcp.json` and the skill, and each of the others its server file and `AGENTS.md`.
