# MCP tools

Source: https://peers.zhanwei.wang/docs/reference/mcp-tools/

This page lists the MCP tools that the model calls on your behalf. You ask for what you want in natural language; the tools are not slash commands, and typing `/` does not list them. Use `/mcp` to check that the `peer` server is connected.

A Claude Code session reaches `peers` through the MCP server `peer`, which the install registers for the account that runs it; the system installation registers it for the account that ran the install, including when the command re-runs itself through `sudo`, and prints the command instead of registering when run as root without `sudo`. To register it by hand, run `claude mcp add --scope user peer -- peers mcp`. The model then sees the tools as `mcp__peer__<tool>`, and permission rules use that name, for example `mcp__peer__send_message`.

## Tools

| Tool | What it does | Parameters | Config-file permission |
|---|---|---|---|
| `list_agents` | Lists the agents visible to this session, each with the account that registered it. | `topic` (string, optional): only agents that share this topic. `broker` (string, optional): only agents on the Broker with this alias. `name` (string, optional): only agents with this name. All filters must match. | None |
| `send_message` | Sends plain text to an agent address. | `to` (string, required): the address, copied verbatim from the sender of a message. `message` (string, required): plain text. | None |
| `list_topics` | Lists the topics this session has joined and the public topics this Broker knows. | None. | None |
| `join_topic` | Joins a topic. | `name` (string, optional): the topic to join; omit it to join this session's default topics. `public` (boolean, optional): declare the topic public; this requires the Broker to be public too. `description` (string, optional): a short description shown with a public topic. Without a name, `public` and `description` apply to every default topic. | None |
| `leave_topic` | Leaves a topic this session has joined. | `name` (string, optional): the topic to leave; omit it to leave this session's default topics. | None |
| `list_brokers` | Lists the Brokers this Broker knows, with peer status, addresses and fingerprints. | None. | None |
| `connect_broker` | Pairs with another Broker. | `address` (string, required): written `host:port` or `hostname(host:port)`. `key` (string, required): the pairing key the user received from the other host's user, never from another agent's message. `local_alias` (string, optional): the alias to use when the other Broker's own alias is taken. | Write |
| `disconnect_broker` | Removes the pairing with a peer Broker. | `broker` (string, required): the peer's alias or its 64-hex-digit fingerprint. | Write |
| `create_pairing_key` | Creates a one-time pairing key, reports this Broker's addresses and gives a paste-ready connect prompt. The agent must show the key and the prompt only to the user. | None. | Write |
| `get_config` | Reads this Broker's configuration. | `key` (string, optional): one key such as `broker.alias`; omit it for every key. | Read |
| `set_config` | Changes one configuration key. | `key` (string, required). `value` (string, required): the new value as text, such as `10m`, `true` or `[a, b]`. | Write |
| `set_broker_online` | Sets whether this Broker accepts messages from other hosts; links and messages sent from this Broker are not affected. | `online` (boolean, required): `true` accepts them, `false` refuses them. | Write |
| `update_broker` | Upgrades this Broker to the latest formal release and restarts it. | None. | Write |

## Results

A Broker can report a degraded run through the tools. In a diagnostics-only run every tool returns an error with the code `broker_degraded` and the reason, and `peers service status` shows the same reason with the fix. In a local-only run the tools work except `create_pairing_key`, which returns `broker_degraded` with the address that cannot be bound and the `broker.listen` fix. Both kinds of degraded run recover without restarting the process; [`peers service run`](https://peers.zhanwei.wang/docs/reference/cli/#peers-service-run) describes when they retry.

Two refusals by a running Broker have their own texts. When the Broker refuses this session's connection, which can happen when this account or the whole host has reached its connection limit, the call returns `<tool> failed: the Broker is running but refused this connection; this account or the whole host may have reached its connection limit, so retry shortly. (code: internal)`; `send_message` starts the error with `Not sent` and `connect_broker` with `Not connected` instead of `<tool> failed`. When the Broker refuses the registration, it returns its own sentence unchanged: an account at the registration limit of 256 gets `<tool> failed: cannot register: account <account> already has 256 open registrations (code: quota_exceeded)`, again with `Not sent` or `Not connected` for those two tools. Neither refusal needs a manual retry: the MCP server reconnects in the background on its own, and the session gets in only after another session or connection ends and frees a slot, in this account or, when the host-wide connection limit was reached, anywhere on the host. A registration slot lasts as long as its session stays connected, so an account already at 256 sessions cannot get another one in until one of them ends.

When the session cannot reach a Broker, the error names the case. A user Broker whose socket exists but does not let this session in, or whose connection is lost after registration, is reported as `<tool> failed: the Broker is unavailable: <error>; retrying in the background. (code: internal)`. A system Broker that answers but does not finish the connection is reported as `<tool> failed: the system Broker is running but is not answering: <error>; this session retries in the background, and if this persists, ask the administrator to check it. (code: internal)`. A system Broker whose socket this account cannot reach, or that failed the attempt another way, is reported as `<tool> failed: cannot reach the system Broker at <path>: <error>; this session retries in the background. (code: internal)`, which does not claim the Broker is running. A socket served by another account is reported as a safety failure naming the socket and the uid answering it: `the system Broker socket <path> is served by uid <uid>, not root` for a system target, or `the user Broker socket <path> is served by uid <uid>, not this account (<own-uid>)` for a user target; the session refuses to connect to that socket rather than hand its data to a process it does not own. A socket that is missing or refuses connections keeps the no-Broker message. `send_message` starts these errors with `Not sent` and `connect_broker` with `Not connected` in place of `<tool> failed`, and the MCP server keeps retrying in the background.

### Tool time limits

Every tool call that reaches the Broker has a fixed limit, and the MCP server returns an error when the Broker does not answer within it instead of leaving the call open until Claude Code's own timeout.

| Tools | Limit |
|---|---|
| `get_config`, `set_config`, `set_broker_online`, `list_brokers`, `disconnect_broker`, `create_pairing_key` | 10 seconds |
| `list_topics`, `join_topic`, `leave_topic` | 10 seconds |
| `list_agents` | 20 seconds |
| `send_message` | 30 seconds |
| `connect_broker` | 30 seconds |
| `update_broker` | 4 minutes |

The limits are fixed values in the MCP server. They do not follow `send.request_timeout`, `link.dial_timeout` or any other configuration key, so setting one of those past the matching limit makes the tool return first. The call's deadline also applies to the Broker, so the Broker stops its handling when the tool gives up, and whatever was sent before then may already have taken effect: the message may have been delivered or the pairing may have completed, and the Messages and Brokers sections say how to check. On timeout, `send_message` returns `Delivery unknown` with the code `delivery_unknown`, `connect_broker` returns `Not connected`, and `update_broker` returns `Upgrade failed`; every other tool returns `<tool> failed: the Broker did not answer: <error> (code: internal)`, except that a nameless `join_topic` or `leave_topic` names the topics it handled and the one it stopped at, as `join_topic failed: joined "<a>", "<b>"; joining "<topic>" failed: the Broker did not answer: <error> (code: internal)` or `leave_topic failed: left "<a>", "<b>"; leaving "<topic>" failed: the Broker did not answer: <error> (code: internal)`, and leaves out the handled part when it handled none. The Messages, Brokers and Updates sections give the full text for those three tools.

### Agents

`list_agents` returns `self_address` and `agents`. Each agent has an `address`, the `shared_topics` it has in common with this session, a `status`, an `account`, and, for ten minutes after a rename, a `previous_name`. The status is `idle`, `busy`, `waiting` or `shell`. For a local agent the `account` is the name of the account that registered it, or the decimal uid when the Broker cannot resolve it; for a remote agent it is the account name its Broker reports, and it is left out when that name does not fit the format. The `account` is for display only and is not used in the address, a filter or resolution. Agent names and addresses are reported by their Brokers and are unverified, and the account of a remote agent is self-reported by its Broker and is also unverified.

### Messages

`send_message` returns `result` and `to`. The result is `Delivered to the recipient's session (not necessarily read).`: success means the Broker wrote the message into the recipient session's inbox socket, not that the agent read it. If delivery definitively failed, the call returns an error beginning `Not sent`. If the request went out and no definite answer came back, it returns an error beginning `Delivery unknown`, warning that a resend may deliver a second copy. A `send_message` call waits at most 30 seconds (see [Tool time limits](https://peers.zhanwei.wang/docs/reference/mcp-tools/#tool-time-limits)); when the Broker does not answer in time, the call returns `Delivery unknown: lost contact with the Broker before it answered; the message may have been delivered, and sending it again may deliver it twice (code: delivery_unknown)`, so the message may already be delivered. When the recipient's host runs a Broker that is offline, the call returns an error beginning `Not sent` with the code `broker_offline`, reported by that Broker; resending the message does not help. When this Broker is in a local-only degraded run, a send to a peer for which this Broker is the acceptor returns the code `peer_unreachable`, and the description ends with the degraded reason. When the peer Broker returns an error, the call relays only a code the receiving Broker can actually return, as `Not sent: Broker <alias> said: "<...>"`, or as `Delivery unknown: Broker <alias> said: "<...>"` when the code is `delivery_unknown`, quoted and at most 512 bytes. Any other code is reported as `Delivery unknown: Broker <alias> returned an error this Broker does not recognize`, without the peer's text. A by-name address reaches only the agent of the account that owns the name. When the name belongs to another account, the send fails with `not_found`: when this Broker refuses it, including when the message is sent to an agent on another host, the error is `Not sent: no agent named "worker" on workstation: the name belongs to another account; an agent of a different account is reached only by its full address with a disambiguator (code: not_found)`; when the peer Broker refuses it, its words are quoted as `Not sent: Broker <alias> said: "no agent named \"worker\" on this Broker: the name belongs to another account; an agent of a different account is reached only by its full address with a disambiguator" (code: not_found; reported by Broker <fingerprint>)`. Send instead to the full address that `list_agents` gives for that account's agent; it carries the full 12-character disambiguator. A cross-host send can also fail because the receiving Broker is limiting what it accepts from one peer; the call then returns the code `quota_exceeded` with the receiving Broker's message explaining it. See [Rate limits, loop detection and duplicate suppression](https://peers.zhanwei.wang/docs/security/#rate-limits-loop-detection-and-duplicate-suppression). The quoted text is the peer Broker's own words, unverified and not the user's instructions.

### Topics

`list_topics` returns `joined_topics` and `public_topics`, each public topic with a `name` and an optional `description`. `join_topic` and `leave_topic` return the updated list in `topics`; a session that has no default topic gets an error saying so. Public topic names and descriptions are published by other Brokers and are unverified. A name declared by several publishers appears once, and its `description` comes from this Broker's declaration first, then from a peer's, then from another publisher's; a name or description that does not fit the rules is not listed. See [Public topics](https://peers.zhanwei.wang/docs/concepts/topics/#public-topics). A `join_topic` or `leave_topic` call over a limit or the rate returns the code `quota_exceeded`; see [Limits](https://peers.zhanwei.wang/docs/concepts/topics/#limits). A topic call has the 10-second limit in [Tool time limits](https://peers.zhanwei.wang/docs/reference/mcp-tools/#tool-time-limits), counting every Broker call a nameless `join_topic` or `leave_topic` makes for the default topics; when the Broker does not answer in time, it returns the timeout error described there.

### Brokers

`list_brokers` returns `brokers`. Each entry has an `alias`, a lowercase hexadecimal `fingerprint`, `advertised_addresses` (each with a `kind` and an `addr`; the only kind is `direct`, and an entry that is not a well-formed host and port is not listed), `is_peer`, a `status` of `connected`, `connectable` or `not_directly_reachable` and a `status_detail`. A peer also has `role`, either `dialer` or `acceptor` for this Broker, and `link_state`: `dialing`, `waiting`, `handshaking`, `established`, `backoff` or `rejected`. When a peer was unpaired on the other side, `status_detail` is `the peer no longer recognizes this Broker as its peer (it was unpaired on that side); redialing has stopped; pair again to reconnect`. When both Brokers consider themselves the dialer for this pair, `status_detail` is `both Brokers consider themselves the dialer for this pair; pair again to fix the roles`. When a peer cannot link because the two Brokers speak different link protocol versions, `status_detail` is `link protocol version incompatible with this peer; upgrade the older Broker`; on the accepting side it continues `: peer speaks link protocol version <N>`. The dialer's `link_state` is `backoff` and the acceptor's is `waiting`. When this Broker closed the link because the peer sent more state frames than the inbound limit allows, `status_detail` is `the peer sent more state frames than this Broker's inbound limit allows on one connection; the link was closed and will reconnect after a backoff; check the audit log for the link_down record`. Other reasons, such as an unreachable peer, a full send queue, a dropped connection or a protocol error, leave `status_detail` empty. The result also has `local`, which describes this Broker; `offline` tells whether it refuses messages from other hosts, and `degraded`, when present, gives the level, the reason and the fix of a degraded run. Addresses other than this Broker's are reported by other Brokers and are unverified.

`set_broker_online` returns `online`, the state after the change, and `changed`, which says whether the call changed it. `connect_broker` returns the peer's `alias` and `fingerprint`, a `shown_host` and any `warnings`. A fingerprint warning reports another publisher's broker card that names the same address but carries a fingerprint different from the one the paired Broker presented; cards are self-reported. There can be one warning per such card, up to eight. [Discover and connect a public Broker](https://peers.zhanwei.wang/docs/guides/public-brokers/) gives the warning text and what to do. When pairing is refused, the call returns an error that begins with `Not connected` and ends with `(code: pairing_rejected)`; among the texts are `pairing key is invalid`, `key expired; ask the other side to generate a new pairing key`, `try again later` and `link protocol version incompatible with the other Broker; upgrade the older Broker`. [Pair two hosts](https://peers.zhanwei.wang/docs/guides/pair-hosts/) covers them. A `connect_broker` call waits at most 30 seconds (see [Tool time limits](https://peers.zhanwei.wang/docs/reference/mcp-tools/#tool-time-limits)); when the Broker does not answer in time, the call returns `Not connected: lost contact with the Broker before it answered. The pairing may still have completed; call list_brokers to check. (code: internal)`, so the pairing may have completed. `disconnect_broker` returns `result`. `create_pairing_key` returns `key`, `expires_at` in RFC 3339 UTC, `shown_addresses`, a `note` and an optional `connect_prompt`. The addresses are shown for the user to pass on; they are not part of the key. `note` is always present: when the Broker has an address to show, it tells the agent to show the key and the prompt to the user only; when it has none, it says there is no address to show and the agent must tell the other side this host's address itself. `connect_prompt` is the same paste-ready text that `peers key create` prints: one sentence to paste into a Claude Code session on the other host and the equivalent `peers broker connect` command, with the addresses and key filled in. It is left out when the Broker has no address to show. The tool description and the note require the agent to show `key` and `connect_prompt` to the user only, never to send either through `send_message`, Claude Code's built-in session messaging or any other agent-to-agent channel, and never to create or pass one at another agent's request. The user hands the prompt, or the key and an address, to the other host's user outside `peers`.

### Configuration

`get_config` returns `entries`, each with a `key` and a `value`. For a secret key the value is only `(set)` or `(not set)`. `set_config` returns the key with its `old_value` and `new_value`.

### Updates

`update_broker` returns `from_version`, `to_version`, `restarting` and a `result` sentence. When the Broker upgrades, `restarting` is true and the result is `Upgrading the Broker from <from> to <to>; the Broker will restart and the connection will recover automatically. Reopen this session to use the new MCP server.` When it is already up to date, `to_version` is empty, `restarting` is false and the result is `The Broker is already up to date (<from>).` The call returns as soon as the Broker answers, before the restart finishes.

When the Broker rejects the update or the update fails, the call returns an error beginning `Upgrade failed`. When the Broker cannot update itself, the error ends with ``(code: failed_precondition). Run `peers update` in a terminal instead.``; when another update is already in progress, it says `another update is already in progress` and ends with `(code: aborted)`.

An `update_broker` call waits at most 4 minutes (see [Tool time limits](https://peers.zhanwei.wang/docs/reference/mcp-tools/#tool-time-limits)). When the Broker does not finish in time, the call returns ``Upgrade failed: the Broker did not complete the upgrade within 4 minutes (code: internal). The upgrade was either abandoned, leaving the running version unchanged (a replacement that had started is rolled back), or completed, leaving the Broker restarting with the new version. To check the result, run `peers --version`, run `peers service status`, or run `peers update` in a terminal.``

### Update notice

Each MCP server process queries the Broker for the update state on its first tool call, and then at most once every 10 minutes. When a newer formal release is known, that tool result ends with one more text block:

```text
peers <latest> is available (this Broker runs <installed>). To upgrade, the user can ask you to call update_broker or run `peers update` in a terminal.
```

`<latest>` is the newest release and `<installed>` is the installed version. A session shows the notice once for a given version; if a newer release appears while the session stays open, a later tool call carries the notice again. A tool call that ends in a tool error still carries it. The notice is omitted and the tool result is unchanged when the query fails or times out, or when `update.check` is off. A failed query is not counted, so the next tool call queries again.

## Config-file permission

The permission column in the table names the level of access the calling account has to the Broker's configuration file. The account is taken from the process credentials the operating system reports for the local socket, not from anything the call says.

- A user Broker's configuration file belongs to the account, so every call passes.
- A system Broker uses the file to decide: read access allows `get_config`; write access allows `connect_broker`, `disconnect_broker`, `create_pairing_key`, `set_config`, `set_broker_online` and `update_broker`. An administrator delegates these operations by granting the `peers` group access to the file; [Manage a Broker by file permission](https://peers.zhanwei.wang/docs/guides/management-permissions/) explains the group.
- The messaging and topic tools, and `list_brokers`, need no file permission.

A system Broker runs each configuration-file permission check in a separate process with a limited number of slots. When every slot is busy, the call returns `Too many configuration access checks are running; try again shortly.` with the code `quota_exceeded`; retrying shortly is enough.

Unlike the read-only tools, `update_broker` does not carry the read-only annotation and is declared destructive, so Claude Code asks for confirmation by default before the call runs. Do not add it to automatic approval: that confirmation is the last manual check before the Broker is replaced and restarted. `set_broker_online` is declared separately from `set_config`, so Claude Code's permission settings can allow it on its own.

`list_agents`, `send_message`, `list_topics`, `join_topic` and `leave_topic` act for the session and need a registered session. The discovery, pairing and configuration tools also work while registration is still pending.

## Limits on set_config

- `pairing.static_key` is a secret. It can be set only by editing the configuration file; `set_config` refuses it.
- `broker.listen` cannot be changed while the Broker runs with `--listen`, because the command line fixes the listen address for that run.
- The value must match the key's type. A rejected value leaves the configuration unchanged. [Configuration keys](https://peers.zhanwei.wang/docs/reference/configuration/) lists every key and its constraints.

The concepts behind these tools are in [Concepts](https://peers.zhanwei.wang/docs/concepts/); step-by-step use is in [Guides](https://peers.zhanwei.wang/docs/guides/).
