Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 4.18 KB

CMS-INTEGRATION.md

File metadata and controls

60 lines (39 loc) · 4.18 KB

CMS integration: Headless API (headless-api)

Catalog row #1 (mode) · README · starters/catalog.json

Summary

A backend-only package. It registers one schema and serves it through createCmsApiHandler() on a plain Node HTTP server. Callers reach that schema three ways: the versioned HTTP API, the typed client, and MCP. Every caller authenticates with an API key.

CMS features it relies on: one collection, API keys with built-in roles, the versioned ops endpoint, the /api/mcp endpoint, @tanstack/cms-client, and the review queue for agent-tool writes.

Files

Features used

Collections and fields

  • contentItem has these fields: title (text, required), slug (slug from title), channel (select: web/ios/android/agent), priority (number), and body (richtext).
  • blockTypes: []. Storage is the default SQLite store at <dataDir>/cms.db.

Writes, review, and revisions

  • Writes made through the agent tool save_document (with create: true), whether from the typed client or from MCP, are always staged with stageWrite. The test asserts that both writes sit in listPending(), that getAs(ctx, { …, staged: false }) returns null for them, and that they become visible only after approve().

Auth, roles, and access

  • auth.getUser maps an x-cms-role request header to a session. That header exists only to bootstrap keys: the test mints editor and viewer keys through the built-in createApiKey op.
  • Real callers send Authorization: Bearer <key>. The CMS resolves the key's role itself, so getUser returns null for those requests.
  • The viewer key gets 403 on save_document, because the built-in viewer role has no content.write.

Transports

  • HTTP: POST /api/cms/v1/ops/:name through createCmsApiHandler().
  • Typed client: createCmsClient({ baseUrl, fetch, getAuthHeader }) with client.call('save_document', …), where fetch is wired straight to the handler.
  • MCP: JSON-RPC tools/call posted to /api/mcp on the same handler, with the same bearer key.

Not used, or left to the app

  • No admin UI (@tanstack/cms-ui-react isn't a dependency) and no public rendering. Both are out of scope in the catalog.
  • No custom defineOp operations, hooks, events, blocks, relations, media, search, import/export, or createDbAuth.
  • @tanstack/ai and @tanstack/ai-mcp are dev dependencies but nothing imports them.
  • The x-cms-role header stub grants any role to any caller who sends it. Replace it before deploying, for example by bootstrapping the first admin key from a CLI or seed script.
  • The catalog's "TanStack DB companion" is examples/db-sqlite. This package doesn't import it.

Where the README and code disagree

  • The README's "Agent contracts used: none (external MCP callers)" and "per-agent actors" both describe API-key roles. The code has no per-agent actor mapping beyond the key's name and role.

Docs