# Machines and agents

> How services, CLIs, MCP clients and AI agents sign in to a project with standard OAuth 2.0, and which credential to use when.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://data.docs.sypnia.com/machines/

For agents: Section index for machine auth: OAuth 2.0 authorization server per project at /auth/v1/oauth (token, authorize, device_authorization, register, revoke, introspect) with metadata at /.well-known/oauth-authorization-server. Credentials: OAuth client with private_key_jwt (recommended) or secret, DPoP sender-constrained tokens, device flow for CLIs/agents, personal access tokens (syp_pat_, optional expiry), project API keys (publishable syp_pk_, secret syp_sk_), one MCP server for every project at https://mcp.data.sypnia.com (the token says the project). Pick: service → client credentials; CLI/agent acting for you → device flow; quick script → PAT; browser app → publishable key + user session; server with full access → secret key. Privileged scopes (sql:*, auth:admin, project:admin): machine clients from their registration; people only via app_metadata.scopes set by an admin, else 403 scope_not_allowed.

Much of what touches a backend today is not a person: services, scheduled jobs, CLIs, MCP clients, AI agents. Sypnia Data treats them as first-class callers, with **standard protocols**, not home-made ones. Each project is an **OAuth 2.0 authorization server** at `/auth/v1/oauth`, described at `/.well-known/oauth-authorization-server`.

## Which credential, when

| Who is calling                         | Use                                                                                            | Why                                           |
| -------------------------------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------- |
| A service of yours, acting as itself   | [Client credentials](https://data.docs.sypnia.com/machines/client-credentials) with a key pair | No shared secret; tokens last minutes         |
| A CLI or an AI agent acting for you    | [The device flow](https://data.docs.sypnia.com/machines/device-flow-and-agents)                | You approve in the browser; nothing is pasted |
| An MCP client (Claude, Cursor)         | [MCP](https://data.docs.sypnia.com/machines/mcp) with OAuth                                    | The protocol MCP specifies                    |
| A quick script or an integration       | A [personal access token](https://data.docs.sypnia.com/machines/tokens-and-api-keys)           | One string, scoped, revocable                 |
| Your app in a browser or a phone       | The publishable key plus the user's session                                                    | Row-level security decides                    |
| A trusted server that needs everything | A secret key                                                                                   | Full access; never in a browser               |

Any token can be made **sender-constrained** with [DPoP](https://data.docs.sypnia.com/machines/dpop): it then works only with a proof signed by the caller's private key.

- [Client credentials](/machines/client-credentials/): A service signs in as itself with a key pair (private_key_jwt) or a secret, and gets a short token with the scopes it needs.
- [DPoP, tokens bound to a key](/machines/dpop/): Make a token useless to anyone who steals it, by binding it to the caller's private key with DPoP (RFC 9449).
- [The device flow, for CLIs and AI agents](/machines/device-flow-and-agents/): How a CLI or an AI agent signs in for you without anyone pasting a secret, keeps a session that can last forever, and how you revoke it.
- [Personal access tokens and API keys](/machines/tokens-and-api-keys/): Long-lived tokens that act as a user, and the publishable and secret keys of a project, with their formats, scopes and how to revoke them.
- [MCP](/machines/mcp/): Connect Claude, Cursor or any MCP client to Sypnia Data with OAuth, at one address for every project, and the tools it can call.

## Scopes

A machine token carries scopes. The built-in ones:

| Scope                     | Allows                                      |
| ------------------------- | ------------------------------------------- |
| `data:read`, `data:write` | the Data API, as the client's database role |
| `sql:read`, `sql:write`   | the SQL endpoint (read-only or not)         |
| `auth:admin`              | the auth admin API (users, sessions)        |
| `project:admin`           | everything, as `service_role`               |

Projects can define their own scopes and check them in policies with `sypnia.scopes()`.

### Who may hold the privileged scopes

`sql:read`, `sql:write`, `auth:admin` and `project:admin` reach the owner role or the admin API, so nobody gets them by signing up:

- A **machine client** (client credentials) gets them from its registration, which only an admin creates with the secret key.
- A **person** gets them only if an admin lists them in the user's `app_metadata.scopes` with the secret key:
  `PUT /auth/v1/admin/users/{id}` with `{"app_metadata": {"scopes": ["sql:read"]}}`.
  Without that, a PAT, a device approval or a consent that asks for one fails with `403 scope_not_allowed`.
  A token issued earlier loses the scope at its next use (within 60 seconds) once the admin takes it back.
- With no `scope` named, the device flow and the authorization code flow ask only for the non-privileged scopes of the client.
- Open dynamic client registration never grants them.

Changes to the account itself (password, e-mail, PATs, sessions, linked identities) need the person's own session. A PAT or an app acting for the person cannot make them.
