# Install workerfuse with an agent

This guide is for an AI agent that sets up workerfuse for a user. workerfuse checks Cloudflare spend every five minutes and pauses a Worker script that passes its limit. This guide sets up **managed guarding**: workerfuse runs the guard for the user with a scoped Cloudflare API token.

The user does two steps in the browser: sign in and approve, and create a Cloudflare token. The agent does the rest.

## 1. Add the MCP server, then sign in (browser)

Add the server with no key. The client opens workerfuse in the browser. The user signs up, or signs in, and approves the client. For Claude Code:

```sh
claude mcp add --transport http workerfuse https://workerfuse.com/mcp
```

Then run `/mcp` in Claude Code and choose **Authenticate**.

Other MCP clients use the same URL and find OAuth by themselves:

- Codex: `codex mcp add workerfuse --url https://workerfuse.com/mcp`
- Cursor, in `~/.cursor/mcp.json`: `{ "mcpServers": { "workerfuse": { "url": "https://workerfuse.com/mcp" } } }`
- OpenCode, in `opencode.json`: `{ "mcp": { "workerfuse": { "type": "remote", "url": "https://workerfuse.com/mcp" } } }`

The approval page asks for `spend:read`, `guard:write` and `offline_access`. This guide needs `guard:write` for step 4.

If a client cannot do OAuth, the user can sign up at https://workerfuse.com/signup and send the `wf_` API key as `Authorization: Bearer <key>`. See [auth.md](https://workerfuse.com/auth.md).

## 2. Find the Cloudflare account ID

If `wrangler` is logged in, run:

```sh
npx wrangler whoami
```

Use the 32-character account ID of the account to protect. If there are several accounts, ask the user which one.

## 3. The user creates a scoped token (browser)

Ask the user to open this link, select the same account, create the token, and copy it:

https://dash.cloudflare.com/?to=/:account/api-tokens&permissionGroupKeys=%5B%7B%22key%22%3A%22account_analytics%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22workers_scripts%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22queues%22%2C%22type%22%3A%22read%22%7D%5D&name=workerfuse

The link asks for Account Analytics Read, Workers Scripts Edit and Queues Read. If the account uses Containers, the user also adds Containers Read. Scope the token to that one account.

Tell the user: the token can edit their Workers, and it goes through this chat to workerfuse. workerfuse stores it encrypted. If the user does not want the token in the chat, they paste it in the workerfuse dashboard instead (**Dashboard → Set up or replace a managed token**). Then skip step 4.

## 4. Connect the account (agent)

Call the MCP tool:

```json
{"name": "connect_cloudflare_account", "arguments": {"accountId": "<32-hex account ID>", "token": "<token>"}}
```

The tool checks the token's permissions, stores it encrypted, and starts the 14-day free trial. No card is needed. If it returns an error, show it to the user. "Missing permissions" names the permission to add.

## 5. Confirm (agent)

Wait 5 minutes, then call `get_spend` with the same `accountId`. A result with `receivedAt` means the guard ran. Show the user the per-script estimates.

The default limits are $0.25 per hour and $2 per day for each script, and $1 per month of stored data. Ask the user if they want other limits. Then call `set_limits`. It replaces every setting, so send all fields.

## After the trial

The trial is 14 days. Then the plan is $5 per month for every connected Cloudflare account. The user subscribes at https://workerfuse.com/billing. Managed guarding stops if the plan lapses. See [pricing.md](https://workerfuse.com/pricing.md).

## Do not

- Do not run a self-hosted guard and managed guarding on the same account.
- Do not call `pause_script`, `resume_script` or `set_limits` without the user's approval.
- Do not write the API key or the Cloudflare token to files, logs or commits.

Support: support@workerfuse.com
