0014 · Identity from the person, scope from the token
- Status: implemented (#161 record, #180 code) ·
personal_tokensand a Streamable HTTP MCP server atPOST /api/v1/kbs/{kb_id}/mcpwith five read-only tools,application/jsonresponses rather than SSE · the account-level "Agents & tokens" page at/account/tokens(0016 A2): plaintext shown once beside a per-base client config snippet, the list keeps the prefix, revocation leaves a trace ·can_writeis still hard-codedfalse, so awritescope changes nothing yet - Written: 2026-09-01 · condensed into English 2026-09-03
- Related: migration
0014_data_source_grantsgave data sources a grant layer; this is the same question where a machine knocks. 0004 has the server speak English only, MCP error codes included. 0015 removes the main objection to openingrememberover MCP.
The problem
Exposing Utopia's tools over MCP raises one question before transport: as whom does the
client connect? Neither existing credential fits. The JWT follows a person but is stateless,
expires in seven days and cannot be revoked — a client configured in a file on someone else's
machine would be reconfigured weekly, and a lost laptop waits for expiry.
sources.ingest_token follows a source, is stored in plaintext, never expires and can only
push documents in.
Decisions
The token acts as the person. Effective permission = the person's role ∩ the token's scope. A token can only narrow, never widen: a viewer's token ticked
writestays read-only. Existing guards (require_kb(kb_id, Role::Viewer),access::kb_role) still receive aUser; the audit trail shows a person; deactivating the person kills their tokens; several bases need no extra keys.Scope still narrows separately, because of the confused deputy. An MCP client is someone else's agent under someone else's system prompt, reading untrusted content from the base — a document saying "run this SQL" or "remember X" may be obeyed with the person's full permissions, and Utopia knows nothing about that client's prompt or its other servers. Full permission means read-only SQL against every production database mounted in every base the person can reach (
query_data) and writes to the ledger (remember), all hanging off a string inclaude_desktop_config.json. So the default token is read-only and limited to one base; writing must be ticked.This token is hashed while
ingest_tokenis not.0002_ingest.sqlreasoned that once the database is lost the documents are lost anyway, so hashing buys nothing — true for a token that can only push documents in. A personal token reads production databases outside Utopia throughquery_data, and that warehouse should not fall with Utopia's database. Different blast radius, different storage. SHA-256 rather than argon2: a high-entropy string does not fear brute force, and a per-row salt would defeat theUNIQUEindex ontoken_hash.Shape.
personal_tokens(id, user_id, name, token_prefix, token_hash, scope, kb_ids, expires_at, last_used_at, revoked_at, created_at):scopedefaults toread;kb_idsNULL means every base the person can reach;expires_atNULL means never, but the UI defaults to 90 days and "never" is an explicit choice;last_used_atanswers "is this still in use" before revoking. The prefixutp_pat_…against ingest'sutp_tells the kinds apart in logs and config files.user_idcascades on delete, unlike the bare foreign key onaudit_events.actor_id: the ledger must outlive the user, the keys must not. Revocation writesrevoked_atrather than deleting the row: the revocation is a trace.Every tool call checks scope. The lesson of
0014_data_source_grants: list filtering only guards what is visible, the mount endpoint is called by id, so the guard sits on both sides. Rather than a handshake check followed by trust for the connection's lifetime, every POST re-runs authentication (revocation and expiry in the SQLWHERE),covers()andrequire_kb; a token revoked mid-session fails on its next call. Each call writes an audit row (mcp.tool_called, target = the token), so attribution is real.
Dead ends
- Base-level machine tokens, one per base and unrelated to a person. It would be a third
authorization model beside workspace membership and base roles — "what can this agent see"
needs three tables, and a mistake in any fails towards "gave too much". And attribution
becomes fake:
audit_events.actor_idrecords living people with anactor_labelsnapshot, while a machine token's facts would belong to a synthetic id.
Revisions
- 2026-09-02: an unstated precondition — #175 moved the seven tools out of the
matchinchat.rsintotools.rs, so chat and MCP share one implementation. The JSON schemas stay inchat.rs;search_chunksstill says results can be cited as[n], which MCP clients cannot see. - 2026-09-02: the placeholder crate
utopia-mcpadvertised three tools that never existed; the server lives inutopia-server/src/api/mcp.rs. Deleted withutopia-graphandutopia-connectors(0016 A2).
Open questions
query_dataandrememberover MCP. The first version shipssearch_chunks,search_docs,find_entities,entity_factsandchanges.rememberwaits on the gate of 0015; what evidence an external agent's fact carries and how SQL runs are audited are still unanswered.- Tokens across workspaces.
kb_idsis a base-level whitelist; a workspace-level grant would look much likedata_source_grants, and the two concepts may merge then.