MCP (for AI agents)

Every tenant is also an MCP server, at /t/<slug>/mcp. An agent (Claude Code, Claude Desktop, Cursor, anything that speaks the Model Context Protocol over HTTP) connects to it and reads and writes the tenant's data through a few tools. Each tool runs a GraphQL request on /graphql as the connection's user, so everything the API pages say applies unchanged: the schema's rules, validation, createdBy and history, idempotency, and the cost limits and rate limit (from the same bucket as that user's GraphQL).

Connecting#

The connection carries an app user's access token as its bearer, exactly as /graphql takes it (Sign in). Without one, the agent is anonymous: it sees what anonymous callers may see and can't write what needs a user. Get a token by signing in with an email code:

Lang
Text
curl -s https://<server>/t/<slug>/runtime/auth/send_magic_code \
  -H 'Content-Type: application/json' -d '{"email":"you@example.com"}'
curl -s https://<server>/t/<slug>/runtime/auth/verify_magic_code \
  -H 'Content-Type: application/json' -d '{"email":"you@example.com","code":"123456"}'

The second answers access_token. In demo mode the first answers the code as demo_code. Then, in Claude Code:

Lang
Text
claude mcp add --transport http shop https://<server>/t/<slug>/mcp \
  --header "Authorization: Bearer <access token>"

Other clients take the same two things, the url and the header, in their config. Most read a file like this one:

Lang
JSON
{"mcpServers": {"shop": {"type": "http", "url": "https://<server>/t/<slug>/mcp",
                         "headers": {"Authorization": "Bearer <access token>"}}}}
  • An access token lasts 15 minutes. After that every call is 401 token-expired, and the client needs a fresh token in its header (refresh it, step 4, or sign in again). Long-lived tokens for agents are not there yet.
  • The token is the tenant's: another tenant's token, or an admin token, is refused with 401, never read as anonymous.
  • The transport is MCP's streamable HTTP, protocol versions 2025-06-18 and 2025-03-26: JSON-RPC 2.0 POSTed to the url, answered with application/json. The server keeps no session (no Mcp-Session-Id) and opens no event stream (GET gives 405).

Tools#

The tools are the same eleven for every tenant, however big its schema. The type is an argument: the GraphQL type name (Note), which the tool's input schema lists from your schema.

Tool What
schema the types, one line each (fields, enum values, refs, what may be done), and how calls are authorised. Start here
describe one type: each field's type, constraints, enum values, refs and reverse refs; list filters, order fields and default order; the create and update inputs; its rules as written and in words
list a page of a type, as its list root: filter (the root's: {"status": {"in": ["DRAFT", "OPEN"]}, "amount": {"gte": 100}}), orderBy, first, after
get one entity by id, or NOT_FOUND; asOf reads it at a past revision
count how many match filter, optionally per value of a field (groupBy)
history an entity's revisions, newest first, as History shows them
create a new entity from input (the create input's fields)
update changes input's fields; add and remove change many-refs ({"members": [ids]})
delete one entity (id), or several of one type, all or nothing (ids)
whoami the user (null when anonymous), what they may create, their roles
query any GraphQL document, as the user: for what the others don't cover

Reads return every scalar and enum field, and refs as their id. Pass fields (["title", "author", "can"]) to choose: a ref named there returns its target's fields, a reverse ref its first 20, and can what the user may do to it now.

create, update, delete and query take an idempotencyKey, sent as the request's Idempotency-Key (Retrying safely): pass a fresh UUID with each write, and the same one when you retry it.

A call and its answer, as Claude Code sends and gets them:

Lang
JSON
{"jsonrpc": "2.0", "id": 2, "method": "tools/call",
 "params": {"name": "create",
            "arguments": {"type": "Note", "input": {"title": "Buy plums", "status": "DRAFT"},
                          "idempotencyKey": "6f1c9a52-3d2e-4b8e-9a0f-1c2d3e4f5a6b"}}}
Lang
JSON
{"jsonrpc": "2.0", "id": 2, "result": {
  "content": [{"type": "text", "text": "{\"item\":{\"id\":\"7060c354-...\", ...}"}],
  "structuredContent": {
    "item": {"id": "7060c354-7eaf-49b0-a24a-3f668b1fbd3e", "title": "Buy plums", "status": "DRAFT",
             "body": null, "author": {"id": "29e53d19-cafa-4fb9-9556-50cd2b162566"},
             "createdAt": "2026-11-26T20:48:46.119Z",
             "createdBy": {"id": "29e53d19-cafa-4fb9-9556-50cd2b162566"}},
    "cost": {"requested": 20, "actual": 20, "budget": 20000, "remaining": 19980},
    "basisT": 1037}}}

Tool errors#

A call that fails is a result with "isError": true, and its structuredContent.errors are GraphQL's (Errors), so the agent reads the code and corrects itself:

Lang
JSON
{"isError": true,
 "structuredContent": {"item": null,
   "errors": [{"message": "Validation failed", "path": ["item"],
               "extensions": {"code": "VALIDATION_FAILED",
                              "errors": {"title": ["should be at least 1 character"]}}}],
   "cost": {"requested": 20, "actual": 11, "budget": 20000, "remaining": 19994}}}

A bad argument (an unknown type, field or filter, a missing id) is BAD_USER_INPUT, with a message that says what the tool takes. Only a tool that doesn't exist, or a message that isn't JSON-RPC, is a JSON-RPC error.