# MCP tools for your agents

Every session the node starts gets Fleetlayer's own tools as an MCP server, named `fleetlayer`: messages, sessions,
transcripts, watches, leases and starting sessions, called as tools instead of shell commands. A message is a typed
argument, so there's no shell quoting to get wrong, and each result is JSON.

The tools do what the `fleetlayer` commands of the same name do, as the session that calls them, under the same access
rules, approvals and audit. They add no new kind of access: anything a tool can do, that session could already do with
the CLI. The CLI stays for scripts and for everything that isn't a tool.

## The tools

| Tool | What it does | The command it comes from |
|---|---|---|
| `msg_send` | Message another session (`<tab>@<node>`); reply to a message the same way | `fleetlayer msg send` |
| `sessions` | The sessions on this node | `fleetlayer sessions` |
| `fleet` | Every node and session in the fleet, with what each is doing | `fleetlayer fleet` |
| `me` | What this session may use: sessions to message, shared tools, pages spaces, nodes to start sessions on | `fleetlayer me` |
| `transcript` | Read part of another session's transcript, 40 KB at a time | `fleetlayer transcript` |
| `watch` | Be told once when something happens: another session stops working, a CI result, an alert | `fleetlayer watch` |
| `session_start` | Start a session in a new tab, here or on another node | `fleetlayer session start` |
| `session_resume` | Resume a stored session in a new tab | `fleetlayer session resume` |
| `lease_acquire` | Take a lease (a build server's slot) that follows this session | `fleetlayer lease acquire` |
| `lease_release` | End a lease | `fleetlayer lease release` |
| `lease_list` | Every kind of lease, who holds and who waits | `fleetlayer lease list` |
| `pages_reply` | Answer in a page's chat | `fleetlayer pages reply` |

Each tool's arguments are its command's flags, with the same names (`line_max` for `--line-max`) and the same help
text: the definitions are generated from the CLI's own, and a test fails when they drift apart.

A cancelled call stops: a lease still waiting in line gives up its place. So does every call when the session ends.
A refusal comes back as a tool error, in the words the CLI would print. A call that waits for the person's approval
says so, and the answer arrives as a message, as it does for the CLI.

The set stays small on purpose: every tool's name and description sits in each session's context. Claude Code defers
MCP tools by default, so a session sees their names and the server's short instructions until it looks one up.

## How a session gets them

The node adds the server when it starts or resumes a session, for the agents that take an MCP server for one session
on the command line: Claude Code (`--mcp-config`), Codex (through its daemon with its plugin, else `-c
mcp_servers.fleetlayer…`) and pi (`-e` with a small
extension the node writes, which calls `registerMcpServer`). It's added beside the
person's own servers, and nothing is written into their config. [Harnesses](https://fleetlayer.ai/docs/harnesses.md#fleetlayers-tools-as-mcp-tools)
lists which agents can take it and how.

A session started some other way doesn't get it: one you start in a terminal, one herdr brings back by itself after a
restart, or `claude --resume` by hand (Claude Code doesn't keep `--mcp-config` across a resume). Resume through
Fleetlayer (`fleetlayer session resume`, the `session_resume` tool) to keep the tools, or add the server once to the
agent's own config:

```sh
claude mcp add fleetlayer -- fleetlayer mcp serve
codex mcp add fleetlayer -- fleetlayer mcp serve
```

To stop the node adding it, set `mcp_server: false` in `node.yaml`.

## How it works

`fleetlayer mcp serve` is a small relay. It runs inside the session's process tree, connects to the node's tools socket,
and names the session it runs in from the environment, exactly as every `fleetlayer` command does (by its address in
the session manager when there is one, which stays right after a `/clear` changes Claude Code's session ID). The node serves the
tools, and turns each call into the request the CLI command would make. So a tool call is attributed, checked and
audited exactly like the same command typed in that session's shell.

The relay outlives the node restarting (for an upgrade, say): calls in flight get an error, and the next call
reconnects. A session that starts while the node is down still loads the tools, from what the node answered before.

[The protocol](https://fleetlayer.ai/docs/protocol.md#13-the-nodes-own-mcp-server) has the details for anyone writing another client.

## Messages that arrive as MCP notifications

Not yet. Claude Code can take a message from an MCP server into a running session (its "channels"), but only for
servers on Anthropic's allowlist or behind a flag that asks for confirmation each time a session starts, so messages
keep arriving the way they do now ([Harnesses](https://fleetlayer.ai/docs/harnesses.md)). Codex, Gemini CLI and OpenCode don't show an MCP
server's notifications to the model.

## Cloud agents

Agents that run in someone else's cloud (ChatGPT, Grok and the like) can't run `fleetlayer mcp serve`. A public MCP
server with sign-in for them, serving the same tools, is planned.
