# Credentials

> Create scoped, expiring bearer credentials for scripts, CI and headless agents that use a workspace's MCP endpoint.

A workspace credential is a bearer token for one workspace. Use it for
scripts, CI jobs and agents that can't sign in through a browser. For
interactive agents, use OAuth on `https://cozy.cloud/mcp` instead. See
[Agents](/docs/agents).

## Create a credential [#create-a-credential]

Open **Agents** in the workspace and choose **+ Create
credential**. In **Give an agent access**:

- **Agent name**: what it's for, such as "Nightly import".
- **Access**: what it may do.
- **Allowed folders (optional)**: comma-separated folder prefixes such as
  `wiki/, skills/`. Blank allows the whole workspace.
- **Expires in days (1–90)**: 30 by default.

Choose **Create credential**. **Save your credential** shows the token once:
copy it and store it as `COZY_MCP_TOKEN` in the agent's environment. Cozy
keeps only a SHA-256 digest, so it can't show it again. If you lose it,
revoke it and create another.

| Access | Scopes |
| --- | --- |
| **Read only** | `wiki:read` |
| **Read and write wiki** | `wiki:read`, `wiki:write` |
| **Read, write, and ingest sources** | `wiki:read`, `wiki:write`, `sources:write` |

These are the same read, wiki-write and source-write scopes OAuth uses. See
[MCP server](/docs/mcp#scopes).

## Limits [#limits]

- A credential reaches only its own workspace. It can't authenticate against
  another one.
- It never gets more access than you have, and its scopes are checked on
  every request.
- Folder prefixes limit every read and write, including search results, the
  graph and prompts.
- A credential can't see connector credentials, create
  another credential, or erase anything for good.

## Revoke [#revoke]

The table in **Agents** lists each credential with its folders, permissions
and expiry. Choose **Revoke**. It stops working at once.

## Use it [#use-it]

The workspace endpoint is shown in **Agents** under **This workspace's URL,
for credentials**:

```text
https://cozy.cloud/wiki-mcp/WORKSPACE_UUID
```

Keep the token in an environment variable or secret manager, never in a file
you commit. **Agents** has copyable versions of the configurations below
with your workspace filled in.

### Codex [#codex]

In Codex's `config.toml`:

```toml
[mcp_servers.cozy]
url = "https://cozy.cloud/wiki-mcp/WORKSPACE_UUID"
bearer_token_env_var = "COZY_MCP_TOKEN"
```

Use another table name, such as `[mcp_servers.cozy_ci]`, if you also keep the
OAuth server.

### Claude Code [#claude-code]

In the project's `.mcp.json`:

```json
{
  "mcpServers": {
    "cozy": {
      "type": "http",
      "url": "https://cozy.cloud/wiki-mcp/WORKSPACE_UUID",
      "headers": { "Authorization": "Bearer ${COZY_MCP_TOKEN}" }
    }
  }
}
```

Claude Code reads the variable when it starts, so the file holds no secret
and can be committed. Start Claude Code from a shell where the variable is
set.

### Cursor [#cursor]

Cursor expands `${env:NAME}` in `mcp.json`:

```json
{
  "mcpServers": {
    "cozy": {
      "url": "https://cozy.cloud/wiki-mcp/WORKSPACE_UUID",
      "headers": { "Authorization": "Bearer ${env:COZY_MCP_TOKEN}" }
    }
  }
}
```

## OAuth on a workspace URL [#oauth-on-a-workspace-url]

A workspace URL without an Authorization header also accepts OAuth. That
grant reaches only that workspace, lasts seven days with no refresh, and is
listed and revocable in **Agents**, under **Your agent access**.

## Troubleshooting [#troubleshooting]

- **401**: the variable isn't set where the client started, or the
  credential expired or was revoked.
- **Reads work, writes fail**: the credential is read only, a folder prefix
  excludes the path.

