# MCP, Cursor and Codex

> The Lanekeeper MCP server for agents without Claude Code hooks, and Cursor's hooks.

`lanekeeper mcp` runs a [Model Context Protocol](https://modelcontextprotocol.io) server over stdio. Any agent that
speaks MCP can ask Lanekeeper before it changes shared code. `lk init` registers it for Claude Code
(`.mcp.json`) and Cursor (`.cursor/mcp.json`).

## Tools

| Tool | Input | Returns |
|---|---|---|
| `lanekeeper_status` | none | Lanes, the agents in them and what they're doing, open clashes, claims. |
| `lanekeeper_check_change` | `file`, optional `symbol`, optional `newContent` | With `newContent`: the clashes that change would create. Without: what other lanes are doing to the file or symbol. |
| `lanekeeper_claim` | `target`, `intent`, optional `exclusive`, `ttlMinutes` | The claim, or who holds an overlapping exclusive claim. |
| `lanekeeper_release` | optional `claimId` | How many claims were released. |
| `lanekeeper_clashes` | optional `severity`, `refresh` | Open clashes with this lane, each with what to do. |
| `lanekeeper_merge_plan` | none | The suggested merge order and why. |
| `lanekeeper_report_usage` | `model`, `inputTokens`, `outputTokens`, optional `cacheRead`, `cacheWrite`, `sessionId` | Records the usage and its estimated cost, if the repository set `cost.acceptReportedUsage` ([cost tracking](https://lanekeeper.dev/docs/cost)). |

The resource `lanekeeper://status` has the same content as `lanekeeper_status`. Every tool answers in plain text
for the model and as structured data for clients that use it. If the daemon can't be reached the tool returns an
error result; it never crashes the server.

## Cursor

Cursor gets three things from `lk init`:

- the MCP server, started in the project folder (`lanekeeper mcp -C ${workspaceFolder}`);
- hooks in `.cursor/hooks.json` for session start, prompts, writes and session end;
- a rule in `.cursor/rules/lanekeeper.mdc` telling the agent when to call the tools.

In block mode Cursor's write is denied with the clash as the reason. In warn mode the clash is added after the write
(Cursor has no field for context before a write). Cursor's hook payload for writes is not fully documented;
Lanekeeper reads the path and content from the field names Cursor uses and checks nothing when it can't find them.

## Codex

Codex reads the section `lk init` adds to `AGENTS.md`. Register the MCP server once per machine:

```sh
codex mcp add lanekeeper -- lanekeeper mcp --agent codex
```

or in `~/.codex/config.toml`:

```toml
[mcp_servers.lanekeeper]
command = "lanekeeper"
args = ["mcp", "--agent", "codex"]
```

`--agent codex` registers Codex in its lane, so other agents see who is working there and policy rules scoped to
`kinds: [codex]` apply to its checks. Without it, a client that calls itself Codex is still recognized.
