---
title: "Connect an agent"
description: "Give an AI agent the forge's tools through the Model Context Protocol, as you or as an agent with its own identity, its own limits and its own record."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.forge.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect an agent

`af mcp` is a [Model Context Protocol](https://modelcontextprotocol.io) server. An agent that speaks MCP runs it, and gets the forge's [tools](https://docs.forge.workreef.dev/reference/agent-tools/): a workspace of its own, changes, history, search, keys and the rest, each answering with structured data rather than text to parse. The agent never needs a shell to drive `af`.

## As yourself

The quickest start runs `af mcp` with your own sign-in, so the agent acts as you. Add it to your agent's MCP configuration; most clients take a server as a command and its arguments:

```json
{
  "mcpServers": {
    "atoll-forge": {
      "command": "af",
      "args": ["mcp", "/home/you/agent-workspace"]
    }
  }
}
```

The directory is the agent's workspace: `af mcp` creates it if it is missing, and keeps the files the agent works on in its `files` subdirectory. Every change the agent writes is then yours, as if you had typed it.

## As an agent of its own

An agent that acts as you is hard to tell apart from you in the record. Give it an identity of its own instead: it is **born** from you, with no more roles, folders or keys than you have, and every change it writes names it and its line back to you. See [People and agents](https://docs.forge.workreef.dev/concepts/agents/).

The agent makes its own key, which never leaves its machine:

```console server
$ af-server --dev
...
```

```console check
$ source ~/af-dev/dev/env
$ af --credential ~/agent.key key
1f5c3ca8c34002fee37f6db5f392b7dca3e0811df82d0d4a55be3f7a24065b70
```

Its parent, you or another agent, starts it with the `start_agent` tool, giving that public key, what the agent is, and any limits: fewer folders, fewer roles, fewer keys. To start it as one of the organization's [agent kinds](https://docs.forge.workreef.dev/concepts/agent-kinds/), name the `kind`: what you leave out is taken from the kind, and the forge refuses what is outside it. The tool answers with the agent's ID. The agent then runs `af mcp` with its own key and that ID:

```json
{
  "mcpServers": {
    "atoll-forge": {
      "command": "af",
      "args": ["--credential", "/home/you/agent.key", "--actor", "<AGENT_ID>", "mcp", "/home/you/agent-workspace"]
    }
  }
}
```

A birth expires with its parent, and stopping an agent with `af stop` stops every agent born from it.

## How an agent works

A typical session uses a handful of tools:

1. [`open_workspace`](https://docs.forge.workreef.dev/reference/agent-tools/#openworkspace) with the paths the agent needs, such as `["src/**"]`. The files are written to disk, where the agent edits them with its own file tools.
2. [`start_change`](https://docs.forge.workreef.dev/reference/agent-tools/#startchange) with a description. Every edit from then on belongs to the change; there is nothing to stage.
3. [`status`](https://docs.forge.workreef.dev/reference/agent-tools/#status) and [`diff`](https://docs.forge.workreef.dev/reference/agent-tools/#diff) to see the change, and [`log`](https://docs.forge.workreef.dev/reference/agent-tools/#log), [`search`](https://docs.forge.workreef.dev/reference/agent-tools/#search) and [`read`](https://docs.forge.workreef.dev/reference/agent-tools/#read) to look around the repository, including files outside its workspace.
4. [`submit`](https://docs.forge.workreef.dev/reference/agent-tools/#submit), then [`wait`](https://docs.forge.workreef.dev/reference/agent-tools/#wait), which returns when something needs the agent: the change landed, a check failed, it met a conflict, the scan flagged it, or a person approved it. Its answer says what to do next.
5. [`undo`](https://docs.forge.workreef.dev/reference/agent-tools/#undo) when a step went wrong: it takes back the agent's last operation, and the workspace's files follow; [`redo`](https://docs.forge.workreef.dev/reference/agent-tools/#redo) puts it forward again. An agent that may retry a call passes its own `request_key`, the same on every retry, so a retry is answered as the first call was and never takes back a second operation. An undo never overwrites anyone's later work: see [Undo a mistake](https://docs.forge.workreef.dev/af/undo/).

Every tool reads and writes only what the agent may: a folder it may not read is as if it were not there, and a write to one is refused.

## Next

- [Agent tools](https://docs.forge.workreef.dev/reference/agent-tools/): every tool, its parameters and what it returns.
- [`af mcp`](https://docs.forge.workreef.dev/reference/af/mcp/) and [`af key`](https://docs.forge.workreef.dev/reference/af/key/) in the reference.

Source: https://docs.forge.workreef.dev/agents/connect/index.mdx
