API v1: design (endpoints, auth, token permissions) #121

Closed
opened 2026-12-03 04:31:06 +00:00 by jfro · 2 comments
Owner

Part of the Ink Lantern rename & API project. Goal: a full JSON API so native clients can do what the web app does.

Write docs/api.md as the design, before the endpoints are built:

  • Base /api/v1, JSON, Authorization: Bearer rma_… using the same API keys as MCP (RmAnalyzer.ApiKeys, Scope.library for item limits).
  • Resource list with method, path, request and response shape, pagination, and the error format: documents, folders, pages (text, image), search, stats, changes feed, suggestions (sorting, tags), todos, quick notes, reports/PDF upload, review loop, sync status/trigger, account and key info.
  • Permission model: how the existing tools list and can_write map onto endpoints, and what has to be added for things MCP doesn't cover (naming, migration, defaults for existing keys so no key gains access silently, settings UI).
  • What a native client needs that polling doesn't give (change feed cursor, ETags, webhooks or SSE).
  • What is out of scope for v1 and why.
  • Whether to describe it with OpenAPI, and how (hand-written file vs a library; check maintenance before proposing a dependency).
Part of the Ink Lantern rename & API project. Goal: a full JSON API so native clients can do what the web app does. Write `docs/api.md` as the design, before the endpoints are built: - Base `/api/v1`, JSON, `Authorization: Bearer rma_…` using the same API keys as MCP (`RmAnalyzer.ApiKeys`, `Scope.library` for item limits). - Resource list with method, path, request and response shape, pagination, and the error format: documents, folders, pages (text, image), search, stats, changes feed, suggestions (sorting, tags), todos, quick notes, reports/PDF upload, review loop, sync status/trigger, account and key info. - Permission model: how the existing `tools` list and `can_write` map onto endpoints, and what has to be added for things MCP doesn't cover (naming, migration, defaults for existing keys so no key gains access silently, settings UI). - What a native client needs that polling doesn't give (change feed cursor, ETags, webhooks or SSE). - What is out of scope for v1 and why. - Whether to describe it with OpenAPI, and how (hand-written file vs a library; check maintenance before proposing a dependency).
Author
Owner

API v1 design draft is ready (full text: docs/api.md, handed to Haystack; on my local branch docs/121-api-design, not pushed).

Shape: JSON at /api/v1, Authorization: Bearer rma_… (same keys as MCP; chat answer tokens not accepted). Cursor pagination (limit ≤ 200, next_cursor), one error body {"error": {"code", "message", "permission"}}, 404 for anything a limited key doesn't reach, ETags from the document hash + transcription time, Idempotency-Key on writes.

Permissions

  1. Every library endpoint maps to an MCP tool and is allowed exactly when MCP allows that tool. A new ApiKeys.allowed?/2 is used by both NotesMCP and the API, so there's one permission path.
  2. Features MCP doesn't have get a new grants field (default [], never nil), so existing keys gain nothing: suggestions, quick_notes, todos, sync. Grants that write also need can_write. They can't be new tool names, because tools: nil keys would get them silently.
  3. Scope.library isn't honoured by Sorting, Tagging, Todos or QuickNotes, so the API filters per item the way AgentTools.suggestions/1 does. Limited-key tests are required for each.

Endpoints (perm in brackets; † needs can_write)

  • Meta: GET /me [any], GET /openapi.json [public]
  • Reads: GET /documents, /documents/:id, /folders, /tags [list_documents]; /documents/:id/pages, /pages/:n [read_pages]; /pages/:n/image [view_page]; /search [search_notes]; /stats [get_stats]; /suggestions [list_suggestions]; /changes, /events [list_changes]; GET /sync [any]
  • Writes †: POST /documents/:id/pages [add_page / draw_page], POST /notebooks [create_notebook], POST /folders [create_folder], PATCH /documents/:id [move_document], POST /reports [make_pdf], POST /pdfs [upload_pdf], POST /reviews [send_for_review]
  • App features: POST /suggestions/moves/:id/{approve,reject,undo,retry}, /suggestions/tags/:id/{approve,dismiss} [suggestions †]; GET|POST /quick-notes [quick_notes, † to add]; GET /todos/pages, POST /todos/pages/:id/sync [todos, † to sync]; POST /sync [sync]

Change feed: /changes?since= returns the same objects and integer cursor as webhooks and list_changes, plus an SSE /events stream of refetch hints. Gaps to close: add a transcribed change kind (OCR finishing isn't a change today), and tell clients in mcp.md to ignore change kinds they don't know.

Out of v1: backups/restore, settings, key management, chat, issue filing, transcription edits, rename/delete, raw file downloads, and APNs push. The design says why for each.

Choices for Jeremy (my pick first)

  • A: permissions MCP doesn't have → a) new grants list ✔ / b) new tool names / c) one all-or-nothing switch
  • B: existing keys reach REST for what they can already do over MCP → a) yes ✔ / b) needs an api grant first
  • C: folder-limited keys and grants → a) allowed, filtered per item ✔ / b) unlimited keys only
  • D: live updates → a) poll + SSE /events ✔ / b) poll only / c) + APNs
  • E: OpenAPI → a) hand-written openapi.json + route-match test, no new dep ✔ / b) open_api_spex / c) none
  • F: PDF upload → a) multipart + JSON parity ✔ / b) JSON base64 only
  • G: chat answer tokens on REST → a) no ✔ / b) yes
  • H: Settings → a) rename the page "API keys" (route unchanged), QR code for new tokens ✔ / b) keep "MCP"
**API v1 design draft is ready** (full text: `docs/api.md`, handed to Haystack; on my local branch `docs/121-api-design`, not pushed). **Shape:** JSON at `/api/v1`, `Authorization: Bearer rma_…` (same keys as MCP; chat answer tokens not accepted). Cursor pagination (`limit` ≤ 200, `next_cursor`), one error body `{"error": {"code", "message", "permission"}}`, 404 for anything a limited key doesn't reach, ETags from the document hash + transcription time, `Idempotency-Key` on writes. **Permissions** 1. Every library endpoint maps to an MCP tool and is allowed exactly when MCP allows that tool. A new `ApiKeys.allowed?/2` is used by both NotesMCP and the API, so there's one permission path. 2. Features MCP doesn't have get a new `grants` field (default `[]`, never nil), so existing keys gain nothing: `suggestions`, `quick_notes`, `todos`, `sync`. Grants that write also need `can_write`. They can't be new tool names, because `tools: nil` keys would get them silently. 3. `Scope.library` isn't honoured by Sorting, Tagging, Todos or QuickNotes, so the API filters per item the way `AgentTools.suggestions/1` does. Limited-key tests are required for each. **Endpoints** (perm in brackets; † needs can_write) - Meta: `GET /me` [any], `GET /openapi.json` [public] - Reads: `GET /documents`, `/documents/:id`, `/folders`, `/tags` [list_documents]; `/documents/:id/pages`, `/pages/:n` [read_pages]; `/pages/:n/image` [view_page]; `/search` [search_notes]; `/stats` [get_stats]; `/suggestions` [list_suggestions]; `/changes`, `/events` [list_changes]; `GET /sync` [any] - Writes †: `POST /documents/:id/pages` [add_page / draw_page], `POST /notebooks` [create_notebook], `POST /folders` [create_folder], `PATCH /documents/:id` [move_document], `POST /reports` [make_pdf], `POST /pdfs` [upload_pdf], `POST /reviews` [send_for_review] - App features: `POST /suggestions/moves/:id/{approve,reject,undo,retry}`, `/suggestions/tags/:id/{approve,dismiss}` [suggestions †]; `GET|POST /quick-notes` [quick_notes, † to add]; `GET /todos/pages`, `POST /todos/pages/:id/sync` [todos, † to sync]; `POST /sync` [sync] **Change feed:** `/changes?since=` returns the same objects and integer cursor as webhooks and `list_changes`, plus an SSE `/events` stream of refetch hints. Gaps to close: add a `transcribed` change kind (OCR finishing isn't a change today), and tell clients in mcp.md to ignore change kinds they don't know. **Out of v1:** backups/restore, settings, key management, chat, issue filing, transcription edits, rename/delete, raw file downloads, and APNs push. The design says why for each. **Choices for Jeremy** (my pick first) - A: permissions MCP doesn't have → a) new `grants` list ✔ / b) new tool names / c) one all-or-nothing switch - B: existing keys reach REST for what they can already do over MCP → a) yes ✔ / b) needs an `api` grant first - C: folder-limited keys and grants → a) allowed, filtered per item ✔ / b) unlimited keys only - D: live updates → a) poll + SSE `/events` ✔ / b) poll only / c) + APNs - E: OpenAPI → a) hand-written `openapi.json` + route-match test, no new dep ✔ / b) open_api_spex / c) none - F: PDF upload → a) multipart + JSON parity ✔ / b) JSON base64 only - G: chat answer tokens on REST → a) no ✔ / b) yes - H: Settings → a) rename the page "API keys" (route unchanged), QR code for new tokens ✔ / b) keep "MCP"
Author
Owner

The design landed on main in docs/api.md with PR #125 (merge d588049), status agreed: Jeremy took all eight picks (A to H) on Dec 3. Closing; the writes and grants follow in #123 / PR #126.

The design landed on main in docs/api.md with PR #125 (merge d588049), status agreed: Jeremy took all eight picks (A to H) on Dec 3. Closing; the writes and grants follow in #123 / PR #126.
jfro closed this issue 2026-12-03 05:33:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/rm-analyzer#121
No description provided.