phibac developer docs

Developer API and agent tools

Your developer tools talk to the server in two ways: the CLI uses the developer API, a few HTTP routes, and an AI coding tool uses the agent tools, the same operations offered through the Model Context Protocol (MCP), a standard way for AI tools to call tools. Both act for your developer account and manage your apps and their schemas. Neither can reach any user's data. This page lists every route and tool, how to send your developer token and how to connect an AI tool.

Every path below is on the server's address: https://phibac.com for this server, and http://localhost:8787 for the local server that npx phibac dev runs. The examples use the local server.

What a developer token can and cannot do

A developer token is a secret key, starting with pbd_, that acts for your developer account. Create one on the server's account page, in its developer section (https://phibac.com/account/developer on this server). It is shown once. A token works only on the server that made it, and stops working when it is revoked or its account is being deleted.

With a developer token you can:

  • Create apps, and change the name and origins of the apps your account owns.
  • Preview and publish schemas for the collections of the apps your account owns.
  • List your account's apps and the collections each one has published (agent tools only).
  • Read and search published schemas and generate TypeScript types from them. These are public: the HTTP routes need no token.
  • Read these docs (the get_docs tool, or the public pages).

A developer token cannot:

  • Read, write, export or delete any user's records or files. No developer route or agent tool touches user data. The routes an app uses refuse a developer token with unauthorized ("developer tokens cannot call app routes"). User data is reached only by an app running in the user's browser, after the user signs in and approves it.
  • Delete an app, a collection or a published version. There is no route or tool for it.
  • Change an app another account owns, or an app whose owning account was deleted: that fails with forbidden.
  • Publish a collection name another app owns: forbidden.

Keep the token secret, as you would a password: anyone who has it can create apps and publish schemas as you. Give it to tools through an environment variable (PB_TOKEN), never in a file you commit or in a chat with an AI tool.

Sending the token

Send the token in the Authorization header of every request to a developer route and to the agent tools endpoint:

Authorization: Bearer pbd_...

A request without it gets HTTP 401 with unauthorized and the message "a developer token is required"; an unknown or revoked token gets unauthorized and "the developer token is invalid or revoked". Answers to these requests carry Cache-Control: no-store, so browsers and proxies do not keep them.

Errors

A refused request gets an HTTP error status and this body, the same as everywhere on the server:

{"error": {"code": "invalid_request", "message": "origin \"notes.example.com\" is not a web origin", "hint": "use scheme, host and optional port only, e.g. https://journal.example.com or http://localhost:5173"}}

code is one of the codes in Errors and how to fix them, message says what went wrong and hint how to fix it. Some errors add details, such as reasons on schema_incompatible. The agent tools return the same JSON as the text of a tool error.

Routes that need a developer token

POST /v1/apps

Creates an app owned by your account.

  • Body: {"name": "Notes", "origins": ["http://localhost:5173"]}. name is required: 1 to 100 bytes once spaces at the start and end are removed, on one line. origins may be left out, or empty.
  • Origins are bare web origins: scheme, host and optional port, without a path. They must use https, except on localhost, 127.0.0.1 and [::1]. At most 20. They are stored in lower case without a default port, and duplicates are removed.
  • Answer: HTTP 201 with the app: {"id": "app_...", "name": "Notes", "origins": ["http://localhost:5173"], "status": "active"}. status is active, or suspended when the server's operator has suspended the app.
  • Errors: invalid_request for a bad name or origin, payload_too_large for a body over the size limit (see Limits), unauthorized.

npx phibac init calls this route.

GET /v1/apps/{appId}

Returns an app your account owns, as the route above answers it.

  • Errors: not_found for an unknown app, forbidden for an app another account owns or one with no owner, unauthorized.

PATCH /v1/apps/{appId}

Changes an app your account owns.

  • Body: {"name": "...", "origins": [...]}, each optional. A property you leave out is not changed. origins replaces the whole list, so send every origin you still use. The same rules as for creating apply; this route accepts an empty list, which leaves the app usable only from http://localhost pages.
  • Native apps: the body may also carry ios and android, the iOS and Android apps that are this app. Each is a whole list, like origins: a list you leave out is not changed, and an empty list clears it.
    • ios: [{"teamId": "A1B2C3D4E5", "bundleId": "com.example.notes"}]. teamId is your Apple team ID, 10 capital letters and digits. At most 5.
    • android: [{"package": "com.example.notes", "sha256": ["14:6D:..."]}]. sha256 lists the SHA-256 fingerprints of the certificates the app is signed with, as 64 hex digits or as pairs joined by colons; a debug build, an upload key and the store's signing key each have their own. At most 5 apps, each with at most 5 fingerprints.
    • On this server at most 5 of your account's apps may have a native entry. One more is refused with forbidden.
  • Answer: HTTP 200 with the app, as above. An app with a native entry also has ios, android and, on a server set up for mobile apps, nativeReturnUrl: the address a sign-in returns to, which a native app sends as its redirect_uri (see Apps on a phone). An app with no native entry has none of the three.
  • Errors: not_found for an unknown app, forbidden for an app another account owns or one with no owner, invalid_request, unauthorized.
curl -X PATCH http://localhost:8787/v1/apps/app_... \
  -H "Authorization: Bearer $PB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"origins": ["http://localhost:5173", "https://notes.example.com"]}'

An app that npx phibac init made on the local server belongs to that server's built-in account: send its key, $(cat ./.pb/developer-token), in place of $PB_TOKEN (Sign users in explains why).

PUT /v1/apps/{appId}/collections/{collection}

Publishes a collection definition for an app your account owns. Add ?dryRun=true to preview: the answer is the same, and nothing is published.

  • Body: the collection definition as JSON, the form npx phibac deploy builds from pb.config.ts. Its keys are name, version, description and fields; each field's keys are type, description, required, maxLength, min, max, values (for enum), indexed and sensitive. Any other key is refused. name must be the collection in the path.

    {"name": "com.example.notes.note", "version": 1, "description": "A note written by the user",
     "fields": {"text": {"type": "string", "description": "Note text", "maxLength": 20000, "required": true},
                "pinned": {"type": "boolean", "description": "Whether the note is pinned", "indexed": true}}}
    
  • Answer: HTTP 200 with {"collection": "com.example.notes.note", "major": 1, "minor": 0, "kind": "additive", "dryRun": false}. kind is same when nothing changed (nothing is published) and additive when the definition is published, or would be, as the given major and minor version.

  • Errors: schema_incompatible, with reasons, for a breaking change within a major version; invalid_request for a definition that breaks a rule (see pb.config.ts reference), a version that skips ahead or does not start at 1, or a name that differs from the path; forbidden when another app owns the name or another account owns the app; not_found for an unknown app; payload_too_large for a definition over the size limit.

npx phibac deploy calls this route, first with ?dryRun=true for every collection.

Public routes

These need no token, and any web page may call them.

GET /v1/schemas/{collection}

The latest minor version of a published collection's latest major version, or of the major version given with ?major=<n>. The answer is the definition with its version (major) and minor. not_found when the collection or version is not published.

curl http://localhost:8787/v1/schemas/core.profile

GET /v1/schemas?search=

The latest version of each published collection whose name contains the text, as {"collections": [...]}: 50 at most, or up to 500 with &limit=<n>.

GET /v1/types?collections=

TypeScript declarations (as application/typescript) for the collections in the comma-separated list. Each item is a name, for its latest major version, or name@<major>. At most 500 different items. npx phibac generate calls this route with the versions pb.config.ts names; CLI reference describes the file.

Docs

/llms.txt and /llms-full.txt are the reference written for AI coding tools, and /docs is this site.

Routes your app uses

Your app's page reads and writes user data through the SDK, which calls routes for records, the changes feed, files, consent and live updates. Those routes accept only a signed-in user's access from the browser, which only the SDK holds, and refuse a developer token. They are not offered as an API to call yourself: use the SDK. SDK reference lists what it does, and How sign-in works how the browser proves who is asking.

Agent tools

The agent tools endpoint is /mcp on the server (https://phibac.com/mcp on this server). It speaks MCP over HTTP (the "streamable HTTP" transport) and needs your developer token in the Authorization header of every request, as above. Each request stands alone. A request body has a size limit (see Limits).

Every tool goes through the same checks as the developer API. A tool error's text is the standard error JSON. A required argument that is missing or null, an argument the tool does not take, or one of the wrong type is refused with invalid_request. There are ten tools; none reads, writes, exports or deletes user data, and none deletes an app or a collection.

create_app

Arguments: name (required), origins (a list, optional). Creates an app owned by your account, with the same rules as POST /v1/apps, and returns it.

list_apps

No arguments. Returns {"apps": [...]}: the apps your account owns, each with id, name, origins and status. Never another account's apps.

update_app_origins

Arguments: appId and origins (both required). Replaces the origins of an app your account owns with the full list given, and returns the app. Unlike PATCH /v1/apps/{appId}, it refuses an empty list with invalid_request. not_found or forbidden as for that route.

update_app_native

Arguments: appId (required), and ios, android or both, in the shapes PATCH /v1/apps/{appId} takes. Each list given replaces that platform's whole list, an empty list clears it, and a list left out is not changed. Web origins are never touched. Returns the app.

preview_schema

Arguments: appId and schema (the collection definition as a JSON object; both required). Reports what publish_schema would do, with the same answer and errors, including schema_incompatible with its reasons, and publishes nothing.

publish_schema

Arguments: appId and schema (both required). Publishes the collection definition for an app your account owns, as PUT /v1/apps/{appId}/collections/{collection} does. Within a major version only additive changes are accepted; a breaking change must be published as the next major version.

list_schemas

Arguments: appId (required). Returns {"appId": ..., "collections": [...]}: each collection the app owns, with every published major version and its latest minor. Owner only.

get_schema

Arguments: collection (required), major (optional, 1 or more). Returns a published schema, at its latest major version when major is left out. Public data.

search_schemas

Arguments: query (required). Returns {"collections": [...]}: the latest version of each published collection whose name contains the text, at most 50. Public data.

generate_types

Arguments: collections (a list, required), each a name or name@<major>, at most 500 different ones. Returns the TypeScript declarations as text, the same as GET /v1/types.

get_docs

Arguments: topic (required), one of quickstart, config, schemas, errors, consent, limits, sdk, cli and tools. Returns that section of llms-full.txt as text. An unknown topic is not_found.

Connect an AI coding tool

Two ways, depending on what the tool supports:

  • A tool that can call a remote MCP server over HTTP: give it the endpoint, https://phibac.com/mcp, and the header Authorization: Bearer <your token>.
  • A tool that runs its tools as a local command: tell it to run npx phibac mcp in your project folder, with PB_BASE_URL (the server; leave it out for the local server) and PB_TOKEN in the command's environment. The command passes the tool's messages to the server's endpoint and the answers back; see CLI reference. On the local server, a token from your own account does not see the apps npx phibac init made there with the local server's own key (./.pb/developer-token): see Use your own developer token.

How to add a tool server is different in each AI tool; look for its MCP settings. Wherever you can, have the tool read the token from your environment instead of writing it into its settings file, and never paste it into the chat. Ask the AI to start with get_docs and the topic quickstart, which the endpoint also suggests to it.

Because the agent tools cannot reach user data, an AI tool connected this way can set up your app and its schemas, but never sees what your users save. To check its work, run npx phibac deploy yourself: it previews every change and shows any breaking one before anything is published.