# Connect an agent (MCP)

> Connect Claude Code, Claude.ai, ChatGPT, Cursor or Codex to Prefera over MCP, with a browser sign-in or an API key.

Source: https://prefera.si/docs/agents
Docs index for agents: https://prefera.si/llms.txt

Prefera runs an MCP server. Connect your own AI agent to it and the agent can read your answers, losses and facts, write fixes with its own model, and record what went live. The API and MCP server come with every paid plan.

## The server URL

The MCP server lives at:

```text
https://prefera.si/api/mcp
```

It speaks Streamable HTTP and takes POST requests only. A browser or a GET request gets a `405`. You can copy the same URL, with a copy button, from **API & MCP** in the app.

## Two ways to sign in

| Way | Use it for | What you do |
|---|---|---|
| Sign in with Prefera (OAuth) | Claude Code, Claude.ai, Claude Desktop, ChatGPT, Cursor, Codex | Approve in your browser. No key to copy. |
| API key | Scripts, servers, automations (n8n, Zapier, CI) and the [REST API](/docs/api) | Create a key, send it as a Bearer token. |

Sign in with Prefera is the main path. On the approval screen you pick the workspaces, the access level and, under **Advanced: limit to areas**, which areas the app may use. You can tick several workspaces. See [Permissions, approvals and limits](/docs/agents/permissions).

## Claude Code

Run this once in a terminal. It adds the server for every folder.

```bash
claude mcp add --transport http --scope user prefera https://prefera.si/api/mcp
```

Then in Claude Code type `/mcp`, pick `prefera`, choose **Authenticate** and approve in the browser.

## Claude.ai and Claude Desktop

Both use the same connector list.

1. Open **Customize**, then **Connectors**.
2. Click **+ Add**, then **Add custom connector**.
3. Name it Prefera and paste `https://prefera.si/api/mcp`, then **Continue**.
4. Under OAuth client choose **Register automatically**, then **Add** and sign in with Prefera.

## ChatGPT

1. Open ChatGPT Plugins (`chatgpt.com/plugins`), click the **+** button, then **Add custom MCP server**.
2. Name it Prefera and paste `https://prefera.si/api/mcp`.
3. Under Authentication choose **OAuth**, accept the warning, then click **Create**.
4. Sign in with Prefera and approve.

> [!NOTE]
> ChatGPT cannot use a static API key as a connector. Use the sign-in above.

## Cursor

On **API & MCP**, choose the Cursor tab and click **Add to Cursor**. Cursor opens, adds Prefera and asks you to sign in.

## Codex

Run two commands in a terminal. The second opens the browser to sign in.

```bash
codex mcp add prefera --url https://prefera.si/api/mcp
codex mcp login prefera
```

## Use an API key instead

Use a key when a client has no browser sign-in, or for a script.

1. Open **API & MCP** in the app.
2. Under **API keys, for scripts and automations**, click **Create key**. Only an owner or editor can.
3. Name it after the tool that will use it, and copy the key. It is shown once.
4. Save the key as the environment variable `PREFERA_API_KEY`, so it never sits in a config file.

Then connect your client. For Claude Code, save this as `.mcp.json` in your project, restart Claude Code and check it with `/mcp`:

```json
{
  "mcpServers": {
    "prefera": {
      "type": "http",
      "url": "https://prefera.si/api/mcp",
      "headers": { "Authorization": "Bearer ${PREFERA_API_KEY}" }
    }
  }
}
```

For Cursor, add this to `.cursor/mcp.json` (this project) or `~/.cursor/mcp.json` (everywhere), then reload Cursor:

```json
{
  "mcpServers": {
    "prefera": {
      "url": "https://prefera.si/api/mcp",
      "headers": { "Authorization": "Bearer ${env:PREFERA_API_KEY}" }
    }
  }
}
```

For Codex, add this to `~/.codex/config.toml`:

```toml
[mcp_servers.prefera]
url = "https://prefera.si/api/mcp"
bearer_token_env_var = "PREFERA_API_KEY"
```

> [!TIP]
> Do not want to edit files by hand? On **API & MCP** click **Create a setup code** and paste the setup prompt into your agent. It carries a one-time code, not your key. The code works once and expires after 10 minutes. The agent trades it for a new key named "Agent setup", saves it as `PREFERA_API_KEY` and writes the config.

A key belongs to one workspace and acts as the person who made it. Each workspace can have 10 active keys. Revoke a key any time from the same list.

## Choose a workspace and brand

A key reaches one workspace. A Sign in with Prefera connection can reach every workspace you ticked.

1. Ask the agent to call `list_brands`. It returns each brand with its id, its domain and, for a connection to several workspaces, its workspace.
2. Pass `brand` (the brand id or its domain) to every other tool.

With a single brand you can leave `brand` out. If a connection reaches several workspaces and you leave it out, the tool answers `brand_required` and lists the brands.

## Check the connection

Ask your agent: "Call list_brands and tell me the brand names." If it answers, you are connected. Then try `losing_questions` to see where AI answers do not name you.

Connected apps appear under **API & MCP** in **Connected apps**. **Revoke** there cuts the app off at once.

## Next

- [Permissions, approvals and limits](/docs/agents/permissions)
- [Agent examples](/docs/agents/examples)
- [MCP tool reference](/docs/agents/tools)
