> The index of all pages is at https://docs.afffast.com/llms.txt.

# Claude Code

Add the MCP server to Claude Code, and check that it works.

Claude Code connects to the MCP server over Streamable HTTP. The key goes in a header. Claude Code reads the key from an environment variable.

## Install

1. Make a test key in the dashboard. A test key starts with `sk_test_`.
2. Put the key in an environment variable. Add this line to your shell profile:

   ```bash
   export AFFFAST_API_KEY="sk_test_..."
   ```

3. Add the server. Use single quotes. They keep your shell from reading `${AFFFAST_API_KEY}`. Claude Code reads it when it connects.

   ```bash
   claude mcp add --transport http afffast https://api.afffast.com/mcp \
     --header 'Authorization: Bearer ${AFFFAST_API_KEY}'
   ```

By default, the server is local to the current project (`--scope local`). Use `--scope user` for all your projects. Use `--scope project` to write the server to `.mcp.json`, which your team can share. The file stores only the name of the variable, not the key.

```json
{
  "mcpServers": {
    "afffast": {
      "type": "http",
      "url": "https://api.afffast.com/mcp",
      "headers": { "Authorization": "Bearer ${AFFFAST_API_KEY}" }
    }
  }
}
```

## Check that it works

Run this command. The server must show `Connected`:

```bash
claude mcp list
```

The `add` command does not check the key. A wrong key shows `Failed to connect` here. Inside Claude Code, type `/mcp` to see the server and its tools.

## Example prompts

- "Query the revenue by network for this month. Show the result as a table."
- "List the 10 newest conversions that have the status pending."
- "Make a test link for the program `prog_...` that goes to `https://shop.example/products/boots`."

## Troubleshooting

- **`Failed to connect` or a 401 error.** The key is wrong, or the variable is not set in the shell that started Claude Code. If a variable is not set, Claude Code warns in `claude mcp list` and sends the text `${AFFFAST_API_KEY}` as the key. Export the variable. Start Claude Code again.
- **The tools are missing.** The key decides the tools. A read-only key has no write tools. Make a key with the scope that you need.
- **A key in the URL.** Do not do this. The API refuses a key in the query string.
- **A 429 error.** The tool call hit a rate limit. Wait for the time in `Retry-After`. See [Rate limits](https://docs.afffast.com/docs/rate-limits.md).
- **You use a project scope.** Claude Code asks you to approve the servers of `.mcp.json` before it uses them.

## Security

- Never paste a key into a chat. Use the environment variable.
- Start with a test key. A test key reads and writes test data only.
- Use a read-only key if the tool must only read.
- Do not commit a key. The `.mcp.json` file must have `${AFFFAST_API_KEY}`, not the key.
- Each tool call is in the request logs of the dashboard. Look there to see what the tool did.
