# 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.

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

For agents: One MCP server (Streamable HTTP, JSON responses, stateless) for every project: https://mcp.data.sypnia.com in Sypnia Cloud (self-hosted: SYPNIA_DATA_MCP_URL, default <public URL>/mcp). The token decides the project and the rights. Project token (user JWT under RLS, OAuth client token, PAT syp_pat_<ref>_…, secret key syp_sk_<ref>_…): works on that project only; a project argument must match. Sypnia account token (auth.sypnia.com session, device-flow agent session, Sypnia PAT): works on every project of the person's organizations by role (viewer reads; developer/admin/owner write; data:read-only tokens read), tools take project (ref or name), extra tools list_projects, get_project, create_project. OAuth: 401 + WWW-Authenticate resource_metadata → RFC 9728 (resource https://mcp.data.sypnia.com, authorization server auth.sypnia.com; ?project=<ref> on the MCP URL shows that project's auth instead) → RFC 8414 → DCR (public PKCE clients, scopes data:read data:write offline_access) → authorization code + PKCE with resource indicator (RFC 8707). Tools: list_tables, describe_table, select, insert, update*, delete*, query (sql:read), execute* (sql:write), list_migrations, apply_migration*, list_users, invite_user*, revoke_sessions* (auth:admin), list_use_cases; * needs confirm: true. Annotations readOnlyHint/destructiveHint; audit row per call (mcp_tool); 120 calls/min; 500 rows per page with next_cursor. Resources sypnia://<ref>/schema and sypnia://<ref>/use-cases; prompt explore_project.

Sypnia Data has **one MCP server for every project**. In Sypnia Cloud it is `https://mcp.data.sypnia.com`. Your token tells it who you are and which project you work on, so the address never changes.

## Connect

With your Sypnia account (you reach every project of your organizations):

```bash
claude mcp add --transport http sypnia https://mcp.data.sypnia.com
```

`.cursor/mcp.json`

```json
{ "mcpServers": { "sypnia": { "url": "https://mcp.data.sypnia.com" } } }
```

The first call opens your browser to sign in at `auth.sypnia.com` and approve the client. The client then calls the tools with your token.

To sign in as a **user of one project** (that project's own auth, its row-level security), add `?project=<ref>` to the address:

```bash
claude mcp add --transport http bakery https://mcp.data.sypnia.com/?project=<ref>
```

`?project=` only chooses which sign-in page the client is sent to. It never grants anything: the token still decides.

Clients that cannot do OAuth send a token as a header instead:

```bash
claude mcp add --transport http sypnia https://mcp.data.sypnia.com --header "Authorization: Bearer syp_pat_…"
```

## Which token, which project

| Token                                                                                                                    | Works on                                                                                                 | With the rights of                                                                      |
| ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| A **Sypnia account** token: your console session, the agent session of `npx @sypnia/data login`, or a Sypnia PAT         | every project of your organizations; tools take `project` (ref or name), optional when you have just one | your organization role                                                                  |
| A **project** token: a user's sign-in, an OAuth client's token, a PAT `syp_pat_<ref>_…` or a secret key `syp_sk_<ref>_…` | only the project that issued it; a `project` argument must name it                                       | the token, as over the API: users under row-level security, scopes for PATs and clients |

With a Sypnia account token, the organization role decides:

- `viewer` reads: tables, rows, read-only SQL, migrations, users and use cases.
- `developer`, `admin` and `owner` also write.
- A token with only `data:read` reads, whatever the role.

Account tools see the whole project, as the console does. Project user tokens see what row-level security lets them see.

## How it signs in

It follows the [MCP authorization specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization), with nothing of our own:

1. **The challenge.** The first call without a token gets `401` with `WWW-Authenticate: Bearer resource_metadata="https://mcp.data.sypnia.com/.well-known/oauth-protected-resource"`.
2. **Protected-resource metadata** (RFC 9728). It names the resource, `https://mcp.data.sypnia.com`, and the authorization server, `https://auth.sypnia.com/auth/v1`. With `?project=<ref>`, the metadata names that project's auth instead.
3. **Registration.** The client reads the authorization server's metadata (RFC 8414) and registers itself with **dynamic client registration** (RFC 7591), as a public client with the scopes `data:read data:write offline_access`.
4. **Approval.** It opens your browser for **authorization code with PKCE**, with the MCP server as the `resource` (RFC 8707). You see who asks and for which scopes, and you approve.
5. **Calls.** It receives tokens for `https://mcp.data.sypnia.com` and calls the tools.

A project's own users sign in this way only if the project turned dynamic registration on (Machines → OAuth clients), or if the MCP client was created there in advance. SQL and auth admin scopes are never part of an open registration ([who may hold them](https://data.docs.sypnia.com/machines#who-may-hold-the-privileged-scopes)).

## Tools

| Tool                                               | Does                                                                                                                                                                           | Needs                    |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| `list_tables`, `describe_table`                    | tables and views the Data API exposes; columns, keys and relations of one                                                                                                      | `data:read`              |
| `select`                                           | reads rows with PostgREST filters, `select` and `order`; up to 500 per call                                                                                                    | `data:read`              |
| `insert`                                           | inserts one row or a list                                                                                                                                                      | `data:write`             |
| `update`, `delete` ✱                               | changes or deletes the rows the filters match (filters are required)                                                                                                           | `data:write`             |
| `query`                                            | read-only SQL on the owner role; up to 500 rows per result                                                                                                                     | `sql:read`               |
| `execute` ✱                                        | SQL that changes data or schema, recorded in the SQL audit                                                                                                                     | `sql:write`              |
| `list_migrations`, `apply_migration` ✱             | the applied migrations; applies a named one once, with its checksum                                                                                                            | `sql:read` / `sql:write` |
| `list_users`, `invite_user` ✱, `revoke_sessions` ✱ | the project's users; invites one by e-mail; signs one out everywhere                                                                                                           | `auth:admin`             |
| `list_use_cases`                                   | the use-case map uploaded to the project with `npx @sypnia/cases map --upload`; the map in Sypnia Cases is read through [Cases' MCP](https://cases.docs.sypnia.com/tools/mcp/) | `data:read`              |
| `list_projects`, `get_project`, `create_project` ✱ | your organizations' projects; one project with its API URL and publishable key; a new managed project (owners and admins)                                                      | a Sypnia account token   |

✱ These tools **change things** and need `confirm: true`. Without it the call returns `confirmation_required`, so the agent shows you what will change before it runs.

The tools carry `readOnlyHint` and `destructiveHint` annotations. A client lists only the tools its project token may call; an account sees them all, because its rights depend on the project.

## Tool reference

Every tool takes `project` (the project's ref or name): needed with a Sypnia account token that reaches several projects; with a project token, leave it out, or it must name that project. Every tool's input allows no other fields. Tools that change things also take `confirm`.

### `list_tables`\[Engine, Cloud]The tables and views the Data API exposes, each with its schema, kind, number of columns and primary key.

**Input:**

None.

### `describe_table`\[Engine, Cloud]One table as `GET /sql/v1/schema` describes it: columns (type, nullable, default), primary key, foreign keys, `rls_enabled` and its policies.

**Input:**

None.

### `select`\[Engine, Cloud]Rows of a table through the Data API, as the caller: row-level security applies to user tokens.

**Input:**

None.

### `insert`\[Engine, Cloud]Inserts one row or a list of rows and returns them. Needs `data:write`.

**Input:**

None.

### `update`\[Engine, Cloud]Sets values on the rows the filters match and returns the changed rows. Needs `data:write` and `confirm`.

**Input:**

None.

### `delete`\[Engine, Cloud]Deletes the rows the filters match and returns them. Needs `data:write` and `confirm`.

**Input:**

None.

### `query`\[Engine, Cloud]Runs SQL in a read-only transaction on the project's owner role. Needs `sql:read`, or an account with access.

**Input:**

None.

### `execute`\[Engine, Cloud]Runs SQL that may change data or schema, on the owner role, recorded in the SQL audit. Needs `sql:write` and `confirm`; prefer `apply_migration` for schema changes.

**Input:**

None.

### `list_migrations`\[Engine, Cloud]The migrations applied to the project, with their checksums. Needs `sql:read`.

### `apply_migration`\[Engine, Cloud]Applies a named migration once; the same name with other contents is refused. Needs `sql:write` and `confirm`.

**Input:**

None.

### `list_users`\[Engine, Cloud]The project's users, without secrets: `{ users, total, next_cursor }`. Needs `auth:admin`.

**Input:**

None.

### `invite_user`\[Engine, Cloud]Creates the user and e-mails an invitation link. Needs `auth:admin` and `confirm`, because it sends an e-mail.

**Input:**

None.

### `revoke_sessions`\[Engine, Cloud]Ends every session of a user; their apps sign in again. Needs `auth:admin` and `confirm`.

**Input:**

None.

### `list_use_cases`\[Engine, Cloud]The use-case map uploaded to this project with `npx @sypnia/cases map --upload --project <ref>`: the use cases, the tables each reads and writes, and when it was uploaded. Needs `data:read`. A self-hosted engine keeps no maps, so there the list is empty. To read or change the map in Sypnia Cases, use [Cases' MCP](https://cases.docs.sypnia.com/tools/mcp/).

### `list_projects`\[Cloud]The projects of your organizations, each with `ref`, `name`, `org`, `org_name`, your `role`, `kind`, `status`, `region`, `created_at` and `api_url`. Needs a Sypnia account token.

### `get_project`\[Cloud]One project, as in `list_projects`, plus its `publishable_key`. Needs a Sypnia account token.

**Input:**

None.

### `create_project`\[Cloud]Creates a managed project, with its own database, in one of your organizations. Owners and admins only; needs `data:write` and `confirm`.

**Input:**

None.

Each tool's `_meta` says `sypnia/requiresConfirmation` and `sypnia/accountOnly`, so a client can tell them apart before calling. A refusal comes back as a result with `isError: true` and its code ([every code](https://data.docs.sypnia.com/api/errors-and-limits#mcp)).

## The protocol

- **Transport.** Streamable HTTP with JSON answers: every answer comes in the response to the `POST`; there is no event stream and no session to keep.
- **Versions.** `2025-11-25`, `2025-06-18`, `2025-03-26` and `2024-11-05`; the server answers in the version the client asks for, or the newest.
- **Size.** A message is at most 1 MB.
- **Instructions.** On `initialize`, the server tells the agent how tokens and projects work and that tools which change data or send e-mail need `confirm: true`.

## Resources and prompt

- **Resources.** `sypnia://<ref>/schema` (tables, columns, keys, functions) and `sypnia://<ref>/use-cases` (the summary of `list_use_cases`), listed for each project you reach; the templates `sypnia://{project}/schema` and `sypnia://{project}/use-cases` read any of them.
- **Prompt.** `explore_project` (argument `project`, needed with an account token that reaches several projects) reads the schema and the use cases and explains the data model, without changing anything.

## Limits and audit

- **Pages.** At most 500 rows per call. A longer answer comes back with `next_cursor`; pass it as `cursor` to get the next page. A single `SELECT` in `query` pages the same way. An answer is at most 200 kB of text; past it, fewer rows come back, with `next_cursor`.
- **Rate.** 120 tool calls per minute per caller and project.
- **Audit.** Every tool call writes a row to the project's audit log (`mcp_tool`) with the caller, the tool and the result. With an account token the actor is `account:<id>`.

## Self-hosting

The engine serves MCP at `SYPNIA_DATA_MCP_URL`, by default `<SYPNIA_DATA_PUBLIC_URL>/mcp`. The metadata then lives at `/.well-known/oauth-protected-resource/mcp`, and the authorization server is your project's own. Account tokens and `create_project` exist only where the engine has an account project with organizations (`SYPNIA_DATA_ACCOUNT_PROJECT`), as in Sypnia Cloud.
