# Connect an agent

> Connect an AI agent to Handline's MCP server with an agent key, or an AI assistant with OAuth, and check which tools it sees.

Connect an agent once per product, after an owner or admin has created its key. The MCP server is at `https://mcp.handline.io`, over Streamable HTTP.

## Connect with an agent key

Use this for an agent that works on its own, such as one a webhook wakes.

1. On **Keys** in the product's settings, an owner or admin creates an agent key with the scopes it needs: `read`, `propose`, `publish` and `report` for an agent that runs campaigns. See [keys and access](/docs/developers/keys).
2. Configure your MCP client with the server's address and the key as a bearer token. For a client that reads a JSON configuration:

```json title="mcp.json"
{
  "mcpServers": {
    "handline": {
      "type": "http",
      "url": "https://mcp.handline.io",
      "headers": { "Authorization": "Bearer hl_agent_…" }
    }
  }
}
```

3. Keep the key out of prompts, logs and repositories. Store it where your agent runner keeps secrets.

The key belongs to one product, so its tools don't need `productId`: leave it out.

## Connect an AI assistant with OAuth

Use this when a person wants their own AI assistant to work in Handline for them.

1. In the assistant, add an MCP server or connector with the address `https://mcp.handline.io`.
2. The assistant opens Handline's sign-in page. Sign in and approve the app.
3. The app now works for you, at most as an editor. Its tools take `productId`; `me_get` lists your workspaces and `products_list` their products.

You can disconnect the app in **Workspace settings** at any time. Its tokens stop working at once.

## Start from a prompt

Handline's MCP server offers prompts for the common jobs. Many AI assistants show them as commands you pick, often as slash commands. Each gives the assistant its steps and the tools to use.

| Prompt | What it does | Asks for |
| --- | --- | --- |
| `start_session` | Reads the briefing, works the queue, and says what needs a person. | The product |
| `weekly_review` | Reviews the last seven days: spend and outcomes against the plan, what the rules rank, stale numbers and experiments reaching a look. It recommends changes without making them. | The product |
| `plan_experiment` | Checks the learning library, registers the experiment, runs the design check, and falls back to the backlog. It doesn't start the experiment. | The product and a hypothesis |
| `launch_concept` | Writes a concept with its copy and page in one change set, checked and published. | The product, the idea and optionally a channel |

A key or app sees only the prompts it can finish with the tools it has. A key with only `read` sees `weekly_review`. With an agent key, leave the product out.

## Check the connection

- The server's instructions, sent when the client connects, link to [the agent guide](/docs/agents/guide).
- List the tools. A key sees only the tools its scopes allow; an AI app sees the tools an editor may use. If a tool you expect is missing, the key lacks its scope.
- Call `briefing_get`, or `setup_checklist` for a product that isn't set up yet.

## The REST API instead

Every MCP tool except a few for AI apps is also a REST route under `https://app.handline.io/api/v1`, with the same key as `Authorization: Bearer …`. See [requests, errors and limits](/docs/reference/rest-api/requests).

## If the connection fails

| What you see | Why | What to do |
| --- | --- | --- |
| `401` with `www-authenticate` | No key or token, or a revoked one | Send `Authorization: Bearer <key>`, or sign in again. |
| `forbidden`: agent keys can't do this | The tool is a person's, in the web app | Ask a person; don't look for a way around it. |
| A tool is missing from the list | The key lacks the scope | Ask an owner or admin for a key with that scope. |
| `429` | Over 600 calls a minute for the key | Wait the seconds in `retryAfterSeconds`, then retry. |
