@tpsdev-ai/flair 0.58.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +3 -2
  2. package/config.yaml +3 -0
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +42 -98
  5. package/dist/commands/agent.js +160 -2
  6. package/dist/commands/doctor.js +15 -23
  7. package/dist/commands/mcp.js +53 -22
  8. package/dist/lib/daemon-liveness.js +42 -0
  9. package/dist/lib/doctor-run.js +67 -0
  10. package/dist/lib/flair-agent-role.js +116 -0
  11. package/dist/lib/launchd-management.js +3 -2
  12. package/dist/lib/mcp-enable.js +667 -72
  13. package/dist/lib/process-start-time.js +32 -0
  14. package/dist/resources/Agent.js +27 -7
  15. package/dist/resources/AgentSeed.js +9 -0
  16. package/dist/resources/Federation.js +14 -2
  17. package/dist/resources/MemoryBootstrap.js +121 -29
  18. package/dist/resources/OrgSkillAssignment.js +209 -0
  19. package/dist/resources/XAA.js +40 -11
  20. package/dist/resources/agent-status-guard.js +63 -0
  21. package/dist/resources/auth-middleware.js +2 -1
  22. package/dist/resources/federation-classify.js +22 -0
  23. package/dist/resources/flair-agent-role-boot.js +26 -0
  24. package/dist/resources/health.js +10 -2
  25. package/dist/resources/key-lock.js +31 -0
  26. package/dist/resources/mcp-oauth.js +3 -6
  27. package/dist/resources/mcp-tools.js +22 -4
  28. package/dist/resources/multi-worker-guard.js +121 -0
  29. package/dist/resources/oauth-discovery.js +1 -0
  30. package/dist/resources/oauth-wellknown.js +8 -4
  31. package/dist/resources/record-types.js +16 -0
  32. package/dist/resources/replay-store.js +56 -9
  33. package/dist/resources/skill-manifest.js +181 -0
  34. package/dist/resources/skill-provenance.js +15 -10
  35. package/dist/src/lib/flair-agent-role.js +116 -0
  36. package/docs/access-control.md +667 -0
  37. package/docs/api-reference.md +6 -2
  38. package/docs/auth.md +4 -0
  39. package/docs/deepseek-harness.md +1 -1
  40. package/docs/integrations.md +1 -1
  41. package/docs/mcp-clients.md +5 -3
  42. package/docs/releasing.md +24 -24
  43. package/package.json +4 -3
  44. package/schemas/memory.graphql +31 -0
  45. package/schemas/oauth.graphql +8 -4
  46. package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
@@ -0,0 +1,667 @@
1
+ # Who can connect to your Flair
2
+
3
+ Three separate checks decide who can use the native `/mcp` endpoint of a hosted
4
+ Flair. **Which people:** a person signs in at your identity provider, and Flair
5
+ acts as the principal that login is mapped to. A login with no mapping cannot
6
+ call tools, unless you turn on just-in-time provisioning (off by default), which
7
+ creates a principal for it. **Which apps:** new apps identify themselves with a
8
+ Client ID Metadata Document, and the shipped `allowedHosts` list (`claude.ai`
9
+ and `claude.com`) limits which hosts may serve one. Registration of new clients
10
+ is off; clients registered while it was on keep using their stored client IDs
11
+ until their records are removed. **What they can touch:** a connection acts as
12
+ its principal. For a non-admin principal, that means writing its own memories
13
+ and reading them plus other agents' non-private ones. `flair principal disable`
14
+ marks a principal deactivated, which refuses its tool calls and keeps its data.
15
+
16
+ This page covers `/mcp`, where apps such as Claude sign people in with OAuth.
17
+ Agents that sign each request with their own Ed25519 key use a different path,
18
+ described in [auth.md](auth.md#ed25519-agent-auth-default) and in
19
+ [worked example 4](#4-a-bot-on-another-host-signs-with-its-own-key). How `/mcp`
20
+ is turned on is in [mcp-clients.md — Two MCP paths](mcp-clients.md#two-mcp-paths).
21
+
22
+ ## 1. Which people
23
+
24
+ When someone connects an app, the app sends them to Flair's authorization
25
+ server, which has them sign in at the identity provider configured under
26
+ `'@harperfast/oauth'` → `providers` in Flair's `config.yaml`. The shipped file
27
+ configures GitHub. The access token the app receives carries the login as its
28
+ subject; for GitHub, that is the account's username.
29
+
30
+ `/mcp` answers `initialize`, `ping` and `tools/list` for any valid token, and
31
+ refuses a `tools/call` for an unknown tool name, before it looks at the mapping.
32
+ On a `tools/call` for a known tool, Flair looks for a `Credential` of kind `idp`
33
+ whose `idpSubject` is that login, that names a principal, and whose status is
34
+ not `revoked`, and acts as that principal. There is no fallback to an anonymous
35
+ or admin identity:
36
+
37
+ - **No mapping:** the call is refused. `/mcp` answers HTTP 200 with a JSON-RPC
38
+ error:
39
+
40
+ ```json
41
+ {"jsonrpc":"2.0","id":1,"error":{"code":-32001,"message":"forbidden: token subject is not a provisioned flair agent"}}
42
+ ```
43
+
44
+ - **Mapped to a principal that does not exist:** refused with code `-32001` and
45
+ a message naming the principal.
46
+ - **Mapped to a deactivated principal:** refused; see
47
+ [Revoking access](#revoking-access).
48
+ - **The credential or the principal could not be read:** refused with code
49
+ `-32000` and a message starting `unavailable:`.
50
+
51
+ ### Map a person to a principal
52
+
53
+ `flair mcp enable` writes the mapping in its `identity-mapping` step:
54
+
55
+ ```bash
56
+ flair mcp enable \
57
+ --instance https://flair.example.com \
58
+ --idp-subject alice \
59
+ --principal alice \
60
+ --admin-pass "$TARGET_ADMIN_PASS"
61
+ ```
62
+
63
+ - `--idp-subject` is the login the identity provider reports: for GitHub, the
64
+ username.
65
+ - `--principal` is the principal the connector identity maps to. It defaults
66
+ to `self`. If no principal with that id
67
+ exists, the step creates a non-admin one, of kind `human` unless you pass
68
+ `--principal-kind agent`.
69
+ - `--admin-pass` is the target instance's admin password. Outside `--dry-run`,
70
+ this command does not fall back to `FLAIR_ADMIN_PASS` or
71
+ `~/.flair/admin-pass`. It writes the mapping through the target's operations
72
+ API on port 9925 of the `--instance` host. <!-- docs-freshness-allow: hosted operations API port, not the data port -->
73
+ - In a terminal, and outside `--dry-run`, it prompts for the GitHub OAuth app's
74
+ client id and secret when `--idp-client-id` and `--idp-client-secret` are not
75
+ passed.
76
+
77
+ The step's output states the mapping it wrote. The line starts:
78
+
79
+ ```
80
+ connector identity: mapped sub 'alice' (provider 'github') to Agent 'alice'; see docs/access-control.md for how /mcp tool calls use it. principal created; Credential(kind:idp) created (cred_idp_github_<12 hex digits>).
81
+ ```
82
+
83
+ `flair mcp enable` runs the whole enablement flow, not only this step. To add a
84
+ person to an instance that is already enabled, also pass
85
+ `--secrets-mechanism env-file`, so that the secrets it stages go to a local
86
+ `0600` file and are not sent to the instance. Then answer `n` when it asks
87
+ whether the staged secrets are applied. The `identity-mapping` step has run by
88
+ then; a ✓ on it in the printed steps means the write was accepted and the
89
+ read-back described under [One mapping per login](#one-mapping-per-login)
90
+ passed. The command stops before restarting the instance, reports the
91
+ `secrets-provisioning` step as not applied, and exits non-zero.
92
+
93
+ ### One mapping per login
94
+
95
+ `flair mcp enable` and the resolver both count a login's `idp` credential unless
96
+ its status is `revoked` (the resolver also skips one that names no principal).
97
+ `flair mcp enable` keeps one such credential per login, whatever the provider
98
+ name:
99
+
100
+ - Running it again with the same `--idp-subject` and `--idp-provider` and a
101
+ different `--principal` re-points the existing credential, and the output
102
+ says `re-pointed`. Calls from that login then act as the principal the
103
+ credential names. Memories are not moved or merged; each principal keeps its
104
+ own.
105
+ - If the login has a credential that is not `revoked` under a different
106
+ provider name, the run revokes it (the row stays, with status `revoked`) and
107
+ prints its id after `SUPERSEDED:`.
108
+ - After writing, it reads the login's credentials back and fails unless exactly
109
+ one of them is not `revoked` and that one is the credential it wrote. It does
110
+ not compare the principal that credential names: `bootstrap`'s `agentId` (see
111
+ [Check who you are](#check-who-you-are)) shows which principal the login
112
+ resolves to.
113
+
114
+ ### Just-in-time provisioning
115
+
116
+ `FLAIR_MCP_JIT_PROVISION` is off by default; `1`, `true`, `yes` or `on` turns
117
+ it on. It changes the "no mapping" case: instead of refusing, Flair creates a
118
+ principal for the login on its first call to a known tool and maps the login to
119
+ it (if that write fails, the call is refused as in the "no mapping" case). The
120
+ new principal is a non-admin agent with trust tier `unverified`, and its id has
121
+ the form `agt_mcp_<login>_<8 hex digits>`, where characters other than letters
122
+ and digits become `_` and the login part is cut to 24 characters. Its
123
+ credential records the provider as `mcp-oauth`.
124
+
125
+ Flair adds no check of its own in this mode: a login the authorization server
126
+ issued a token for gets a principal on its first call to a known tool. Flair's
127
+ shipped configuration does not restrict which GitHub accounts can sign in. Turn
128
+ it on only when that is what you want, and set it in the instance's process
129
+ environment, like `FLAIR_MCP_OAUTH`.
130
+
131
+ ## 2. Which apps
132
+
133
+ New apps identify themselves with a Client ID Metadata Document (CIMD): the
134
+ `client_id` is an HTTPS URL, and Flair's authorization server fetches the
135
+ document from that URL, and caches it, when a person starts to sign in. Clients
136
+ registered before registration was turned off use their stored client IDs
137
+ instead (see below).
138
+
139
+ - **Registration of new clients is off.** The shipped `config.yaml` sets
140
+ `dynamicClientRegistration.enabled: false`, so `POST /oauth/mcp/register`
141
+ answers `404 {"error":"Not found"}`, and the metadata at
142
+ `/.well-known/oauth-authorization-server` lists no `registration_endpoint`.
143
+ - **Clients registered earlier stay usable.** A `client_id` that is not shaped
144
+ like a metadata-document URL is looked up among stored registrations, in the
145
+ `harper_oauth_mcp_clients` table of Harper's `oauth` database. Turning
146
+ registration off does not remove those records: a client registered while
147
+ registration was on can still sign people in and refresh tokens, and the host
148
+ list below does not apply to it. Flair has no command that lists or removes
149
+ these records; such a client stays usable until its record is deleted.
150
+ - **Listed hosts.** When `clientIdMetadataDocuments.allowedHosts` is non-empty,
151
+ a `client_id` URL is accepted only if its host is on the list. For the
152
+ document of an app that signs people in, an empty list (`[]`) or no
153
+ `allowedHosts` key adds no allowlist restriction. The plugin still resolves
154
+ the host before fetching and refuses one that resolves to an address outside
155
+ the public ranges, such as a private, loopback or link-local address. A
156
+ headless (`client_credentials`) document is refused unless the list is
157
+ non-empty; with the shipped `config.yaml`, Flair's authorization server does
158
+ not take that grant at all (see [example 5](#5-a-bot-reaches-another-oauth-protected-mcp-server-as-itself)).
159
+ The shipped list, `claude.ai` and `claude.com`, is there for Claude. With a
160
+ non-empty list, a `client_id` on any other host gets HTTP 400 from the
161
+ authorization endpoint, with error `invalid_client` and the description
162
+ `Unknown client_id`.
163
+ - **The person sees the app's host.** For an app that uses a metadata document,
164
+ the authorization server shows a page naming the host of the app's
165
+ `client_id` before it sends the person to the identity provider; the person
166
+ continues from there.
167
+ - **Public clients with PKCE.** The document of an app that signs people in
168
+ must declare `token_endpoint_auth_method: none`, or leave the field out. Any
169
+ other value is refused with `invalid_client`. Every authorization request must
170
+ carry a PKCE `code_challenge` with method `S256`. With the shipped
171
+ `config.yaml`, the server's metadata advertises `none`, `client_secret_basic`
172
+ and `client_secret_post` as token endpoint auth methods (the last two apply
173
+ only to registered clients) and does not advertise `private_key_jwt`. Setting
174
+ `mcp.clientCredentials.enabled: true`, which turns on the headless grant,
175
+ changes the metadata: it then also lists `private_key_jwt`, the
176
+ `client_credentials` grant type and `EdDSA` as the assertion signing
177
+ algorithm. The document of an app that signs people in is still refused
178
+ unless it declares `none` or leaves the field out.
179
+
180
+ ### Changing the list
181
+
182
+ The list lives in `config.yaml`:
183
+
184
+ ```yaml
185
+ '@harperfast/oauth':
186
+ mcp:
187
+ clientIdMetadataDocuments:
188
+ allowedHosts:
189
+ - claude.ai
190
+ - claude.com
191
+ - apps.example.com
192
+ ```
193
+
194
+ Edit the `config.yaml` your instance runs (on Fabric, the one you deploy) and
195
+ restart Flair so the component loads the new list. The list is a literal in that
196
+ file, not an environment reference. The package ships the file with the default
197
+ list, and a completed upgrade installs the new version's file, so re-apply your
198
+ edit after upgrading.
199
+
200
+ `flair mcp enable --cimd-allowed-hosts <hosts>` can make this edit to
201
+ `config.yaml` in the current directory, else `~/.flair/config.yaml`, on the
202
+ machine where you run it. Without `--dry-run`, before any step that changes
203
+ anything, it refuses the flag unless a preflight match links the host and
204
+ process ID the instance reports, a readable process on this machine, and that
205
+ file (compared by `realpath`). At its `local-config-update` step, before it
206
+ restarts the instance, it writes the list unless the file already holds that
207
+ exact list, then reads the file back. It also refuses the flag for a Fabric
208
+ instance, an invalid host list, or a `config.yaml` that is missing, unreadable
209
+ or not valid YAML, or has no `@harperfast/oauth` `mcp` mapping; it does not
210
+ check early that the file can be written, and a write failure fails the later
211
+ `local-config-update` step. A refusal changes nothing. With `--dry-run`, it
212
+ skips the match and writes nothing. A run that stops before
213
+ `local-config-update` does not write the list.
214
+ On Fabric, and whenever the command refuses, edit the file by hand as above. If
215
+ an upgrade replaces that file, run the command again or edit the file.
216
+
217
+ ### ChatGPT
218
+
219
+ ChatGPT's published metadata document, `https://chatgpt.com/oauth/client.json`,
220
+ declares `token_endpoint_auth_method: private_key_jwt`. The `@harperfast/oauth`
221
+ version Flair pins, 2.5.0, accepts only `none` in the metadata document of an
222
+ app that signs people in, so ChatGPT's CIMD client is refused on 2.5.0 even with
223
+ `chatgpt.com` on the list. A sign-in that presents that document gets HTTP 400,
224
+ error `invalid_client`, and the description
225
+ `token_endpoint_auth_method 'private_key_jwt' is not supported for interactive CIMD clients; use 'none'`.
226
+ Stored registrations are a separate path (see [2. Which apps](#2-which-apps)),
227
+ and registration of new clients is off.
228
+
229
+ > **Upstream:** verification of `private_key_jwt` for interactive clients is in
230
+ > progress upstream in
231
+ > [HarperFast/oauth#245](https://github.com/HarperFast/oauth/pull/245).
232
+
233
+ ## 3. What they can touch
234
+
235
+ A connection acts as its principal:
236
+
237
+ - **Writes** go under the principal's id. A non-admin principal cannot write a
238
+ memory owned by another agent
239
+ (`forbidden: cannot write memory owned by another agent`). The identity comes
240
+ from the login's mapping, never from tool arguments.
241
+ - **Reads** cover the principal's own memories, of any visibility, and every
242
+ other agent's memories on the instance that are not `private`. A non-admin
243
+ principal does not get other agents' `private` memories. `flair grant` does
244
+ not change this, because reads do not consult memory grants.
245
+ - **Admin** authority applies to a `/mcp` connection only when the principal's
246
+ Agent record has `role: admin`. The principals that `flair mcp enable` and
247
+ just-in-time provisioning create are not admins.
248
+
249
+ ### Tokens
250
+
251
+ - With the shipped `config.yaml` (`accessTokenTtl: 900`), an access token from
252
+ the authorization-code grant, or from refreshing one, lasts 900 seconds. When
253
+ the headless `client_credentials` grant is enabled, its access tokens last
254
+ 300 seconds unless `mcp.clientCredentials.accessTokenTtl` is set. A request
255
+ with an expired or invalid token gets HTTP 401 with
256
+ error `invalid_token` and a `WWW-Authenticate: Bearer resource_metadata="…"`
257
+ header.
258
+ - With the shipped `config.yaml`, which does not set
259
+ `mcp.refreshTokenRequiresOfflineAccess`, the app also gets a refresh token
260
+ unless its metadata lists grant types without `refresh_token`. When that
261
+ option is set to true, the granted scope must also include `offline_access`.
262
+ Refresh tokens are single-use: each refresh returns a
263
+ new one. A refresh token that was already used is refused (`invalid_grant`),
264
+ and the plugin attempts to revoke that sign-in's whole refresh-token family;
265
+ if that revocation write fails, the failure is logged and the token is still
266
+ refused. The family expires 30 days after the sign-in, the
267
+ `@harperfast/oauth` default; the shipped `config.yaml` does not set
268
+ `refreshTokenTtl`.
269
+
270
+ ### Revoking access
271
+
272
+ Deactivate the principal, on the Flair host, with `FLAIR_ADMIN_PASS` set or
273
+ `--admin-pass`:
274
+
275
+ ```bash
276
+ flair principal disable alice
277
+ ```
278
+
279
+ When the operations API accepts the update, it prints
280
+ `✅ Principal 'alice' deactivated`.
281
+
282
+ - It sends an `update` to the operations API at `127.0.0.1` on the machine it
283
+ runs on (port from `--ops-port`, `FLAIR_OPS_PORT` or the local Flair config).
284
+ It has no option for a remote instance.
285
+ - The update sets the principal's `status` to `deactivated`, and its
286
+ `updatedAt`, and nothing else: the principal's memories and its login mapping
287
+ stay. The operations API of Harper 5.2.8, the version Flair pins, also accepts
288
+ an update for an id that has no record, so the ✅ line does not show that the
289
+ principal exists.
290
+ - Flair reads the principal's status on every `tools/call` for a known tool, and
291
+ refuses those calls for a deactivated principal, including calls that carry a
292
+ token issued before the change:
293
+
294
+ ```json
295
+ {"jsonrpc":"2.0","id":1,"error":{"code":-32001,"message":"forbidden: principal 'alice' is deactivated, so this token can no longer call tools. An operator must reactivate the principal (set its status to \"active\") to restore access."}}
296
+ ```
297
+
298
+ - The same status refuses the principal's Ed25519-signed requests with HTTP
299
+ 401 `{"error":"principal_deactivated"}`.
300
+ - Disabling does not revoke OAuth tokens: they stay valid until they expire,
301
+ and their tool calls are refused. Setting the status back to `active`
302
+ restores access for tokens that are still valid. There is no
303
+ `flair principal enable` command.
304
+
305
+ To close `/mcp` for everyone, unset `FLAIR_MCP_OAUTH` in the instance's
306
+ environment (or set it to `0`) and restart the instance; `flair mcp disable`
307
+ asks you to confirm the variable is unset, then sends the restart through the
308
+ instance's operations API.
309
+
310
+ ## Check who you are
311
+
312
+ Call the `bootstrap` tool. Its structured result carries `agentId`, the
313
+ principal Flair resolved you to, and `scope`:
314
+
315
+ ```json
316
+ "agentId": "alice",
317
+ "scope": { "agentId": "alice", "isAdmin": false, "reads": "own-and-org-non-private" }
318
+ ```
319
+
320
+ If `agentId` is not the principal you expected, your login maps to a different
321
+ one (for example, one that just-in-time provisioning created); map it with
322
+ `flair mcp enable`. The stdio adapter's `bootstrap` returns text instead; an
323
+ agent can run `flair bootstrap --agent <id> --json` and read the same two
324
+ fields.
325
+
326
+ ## Worked examples
327
+
328
+ The examples use placeholders: the instance `https://flair.example.com`, the
329
+ GitHub logins `alice`, `carol` and `dave`, the bot `bob-the-bot`, and another
330
+ MCP server at `https://mcp.acme.example`. `$TARGET_ADMIN_PASS` holds the
331
+ instance's admin password.
332
+
333
+ ### People
334
+
335
+ #### 1. One person, one app: alice connects Claude
336
+
337
+ **Goal:** alice uses Claude with her hosted Flair, signs in with GitHub login
338
+ `alice`, and acts as principal `alice`.
339
+
340
+ Create a GitHub OAuth app whose callback URL is
341
+ `https://flair.example.com/oauth/github/callback` (the command prints this URL
342
+ too). Then run:
343
+
344
+ ```bash
345
+ flair mcp enable \
346
+ --instance https://flair.example.com \
347
+ --idp-subject alice \
348
+ --principal alice \
349
+ --admin-pass "$TARGET_ADMIN_PASS"
350
+ ```
351
+
352
+ When it finishes, it prints each step it ran, marked ✓ or ✗. The steps that
353
+ act:
354
+
355
+ - `signing-key` creates `~/.flair/mcp-signing-key.pem` (or the
356
+ `--signing-key-file` path), or reuses the file if it exists.
357
+ - `idp-credentials` checks that the OAuth app's client id and secret are
358
+ present; in a terminal, the command prompts for them before the steps run.
359
+ - `secrets-provisioning` always stages the secrets the instance needs in a local
360
+ `0600` file. Without `--secrets-mechanism`, when the instance reports that it
361
+ supports Harper's env-secrets, the step also attempts to push each secret, then
362
+ reads back the stored row's `name` and `processEnv` flag (not the value). If
363
+ a push fails, or its row cannot be read back or does not show `processEnv` as
364
+ true, the step names the variables that failed and gives the staged-file
365
+ instructions instead.
366
+ - `identity-mapping` writes the credential for `alice` and reads the login's
367
+ credentials back (see [One mapping per login](#one-mapping-per-login)). The
368
+ command then asks you to confirm that the secrets are applied to the instance
369
+ (or takes `--confirm-secrets-applied`).
370
+ - `local-config-update` takes the first `config.yaml` it finds, in the current
371
+ directory and then in `~/.flair/`, on the machine you run it on, and sets
372
+ `mcp.enabled` to `${FLAIR_MCP_OAUTH}` when that file has the
373
+ `'@harperfast/oauth'` → `mcp` block. When there is no such file or block, or
374
+ the write fails, the step is marked failed and the command continues.
375
+ - `restart` sends a restart through the instance's operations API,
376
+ `verify-restart` waits up to 30 seconds for a new process ID, and
377
+ `self-verify` checks the published metadata; any of the three can fail the
378
+ run.
379
+
380
+ On success it ends with:
381
+
382
+ ```
383
+ ✓ The OAuth metadata check passed. The /mcp route itself was not probed.
384
+
385
+ claude.ai → Settings → Connectors → Add custom connector
386
+ URL: https://flair.example.com/mcp
387
+ (no client ID to enter — Claude presents its own Client ID Metadata Document URL automatically)
388
+ ```
389
+
390
+ On a `*.harperfabric.com` instance, the command checks the target's OAuth
391
+ metadata after confirmation. If that check passes, the command
392
+ reaches its `fabric-operator-deploy` step and checks whether the public `/mcp`
393
+ OAuth surface already passes self-verify. If it does, the command
394
+ finishes there and prints the same connector details. If it does not, the run
395
+ stops at that step with instructions: apply the staged secrets, which include
396
+ `FLAIR_MCP_OAUTH=true`, to the instance's environment (when this run already
397
+ pushed them to the instance, the step says so and only asks for the restart),
398
+ restart the instance, then run `flair mcp enable` again with the same options
399
+ plus `--confirm-secrets-applied`. That run checks again and finishes once
400
+ self-verify passes. If the public origin cannot be reached, the step lists
401
+ checks to run instead of the activation instructions. At any point,
402
+ `flair mcp status --instance https://flair.example.com` reports whether the
403
+ surface answers.
404
+
405
+ **Check:** in Claude, `bootstrap` returns `"agentId": "alice"` and
406
+ `"isAdmin": false` in `scope`.
407
+ **Revoke:** `flair principal disable alice` on the Flair host.
408
+
409
+ #### 2. The same person, a second app: shared or separate
410
+
411
+ **Goal:** alice also uses Claude Code on her laptop, and decides whether it
412
+ shares her connector's memories.
413
+
414
+ - **Through `/mcp`: shared, with no command.** Add
415
+ `https://flair.example.com/mcp` to Claude Code as a remote HTTP MCP server.
416
+ Claude Code's `client_id` is on `claude.ai`, which the shipped list allows. The
417
+ mapping is per login, not per app, so when alice signs in with GitHub login
418
+ `alice`, Claude Code acts as `alice`.
419
+ - **Through the stdio adapter: separate unless linked.** Register an agent for
420
+ the laptop (as in [example 4](#4-a-bot-on-another-host-signs-with-its-own-key),
421
+ say `alice-laptop`) and set `FLAIR_URL=https://flair.example.com` and
422
+ `FLAIR_AGENT_ID=alice-laptop` in the adapter's config. `alice-laptop` and
423
+ `alice` are then two principals: each writes its own memories and reads the
424
+ other's non-private ones, and, neither being an admin, neither reads the
425
+ other's `private` memories. To make them one, map the login to the laptop
426
+ agent:
427
+
428
+ ```bash
429
+ flair mcp enable \
430
+ --instance https://flair.example.com \
431
+ --idp-subject alice --principal alice-laptop \
432
+ --secrets-mechanism env-file \
433
+ --admin-pass "$TARGET_ADMIN_PASS"
434
+ ```
435
+
436
+ Answer `n` when asked whether the staged secrets are applied. When the
437
+ `identity-mapping` step shows ✓, its output says `re-pointed`. The
438
+ connector's `bootstrap` then shows which principal it resolves to; it should
439
+ be `"agentId": "alice-laptop"`. Memories already written as `alice` stay with
440
+ `alice`.
441
+
442
+ **How to choose:** use one principal when both apps should see the same private
443
+ memories. Keep two when you want to revoke or audit them separately.
444
+ ChatGPT's CIMD client cannot be the second app yet; see [ChatGPT](#chatgpt).
445
+
446
+ **Check:** `bootstrap` in each app returns the `agentId` you chose.
447
+ **Revoke:** `flair principal disable` for the principal you want to stop.
448
+
449
+ #### 3. A small team, and someone leaves
450
+
451
+ **Goal:** alice, carol and dave each connect as their own principal. Later, dave
452
+ leaves.
453
+
454
+ Map alice as in example 1. Map each of the others on the running instance:
455
+
456
+ ```bash
457
+ flair mcp enable \
458
+ --instance https://flair.example.com \
459
+ --idp-subject carol --principal carol \
460
+ --secrets-mechanism env-file \
461
+ --admin-pass "$TARGET_ADMIN_PASS"
462
+ ```
463
+
464
+ Answer `n` when asked whether the staged secrets are applied; the
465
+ `identity-mapping` step has run by then (see
466
+ [Map a person to a principal](#map-a-person-to-a-principal)).
467
+ Repeat for `dave`. Each of them reads their own memories and the others'
468
+ non-private ones.
469
+
470
+ **Check:** `bootstrap` returns `"agentId": "carol"` for carol and
471
+ `"agentId": "dave"` for dave.
472
+
473
+ **Revoke:** when dave leaves, run `flair principal disable dave` on the Flair
474
+ host. His app may still hold an access token that passes the OAuth check until
475
+ it expires, but his next `tools/call` for a known tool gets:
476
+
477
+ ```json
478
+ {"jsonrpc":"2.0","id":1,"error":{"code":-32001,"message":"forbidden: principal 'dave' is deactivated, so this token can no longer call tools. An operator must reactivate the principal (set its status to \"active\") to restore access."}}
479
+ ```
480
+
481
+ His memories stay, and those that are not `private` stay readable by alice and
482
+ carol.
483
+
484
+ ### Bots
485
+
486
+ #### 4. A bot on another host signs with its own key
487
+
488
+ **Goal:** `bob-the-bot` runs on its own server and uses Flair with an Ed25519
489
+ key, the default for agents.
490
+
491
+ Run this on the bot's host, so that the private key is created where it is used:
492
+
493
+ ```bash
494
+ flair agent add bob-the-bot \
495
+ --target https://flair.example.com \
496
+ --admin-pass-file ./target-admin-pass
497
+ ```
498
+
499
+ The password file must be mode `0600`. For an `https` target on port 443, the
500
+ command sends the Agent record to the operations API on port 9925 of the <!-- docs-freshness-allow: hosted operations API port, not the data port -->
501
+ same host; pass `--ops-target <url>` if yours is elsewhere. It writes a new key
502
+ to `~/.flair/keys/bob-the-bot.key` (mode `0600`), or reuses the key already
503
+ there, sends an `insert` for the Agent record, and prints, among other lines:
504
+
505
+ ```
506
+ ✅ Agent 'bob-the-bot' (bob-the-bot) registered (ops: <operations API URL>)
507
+ ```
508
+
509
+ If a well-formed Agent record with that id already exists, the command stops
510
+ before it writes a key file or an insert. It exits with an error that names
511
+ the id and tells you to run `flair agent rotate-key <id>` on the Flair host
512
+ (that command talks only to the local operations API and writes the
513
+ replacement private key on that host). An unreadable row, including one whose
514
+ `name` is missing or not a string, exits with "could not read" and does not
515
+ name that remedy. For a well-formed row the other remedy is
516
+ `flair agent remove <id>` and then `flair agent add` again.
517
+ `flair agent remove` tries to delete that agent's Memory and Soul rows as
518
+ well as the Agent row. An adapter on another machine still loads the previous
519
+ key until the new private key file is on that signing host. `FLAIR_KEY_PATH`
520
+ only names a path on the host where the adapter runs. Point it at that
521
+ local file when the key is not in the default location, then restart the
522
+ adapter. A new id is inserted, then
523
+ read back. The command prints the line above, and the public key on the
524
+ following line, only when the stored public key matches the key generated or
525
+ reused by this command. A skipped insert, a different stored key, or a row
526
+ with no usable public key is an error. A row that exists without a usable
527
+ public key is not reported as a missing row. Requests signed with a key that
528
+ does not match the stored one still get `invalid_signature` (below).
529
+
530
+ Configure the stdio adapter (`@tpsdev-ai/flair-mcp`) on the bot's host with
531
+ `FLAIR_URL=https://flair.example.com` and `FLAIR_AGENT_ID=bob-the-bot`. With
532
+ `FLAIR_KEY_PATH` and `FLAIR_KEY_DIR` unset, it looks for the key at
533
+ `~/.flair/keys/bob-the-bot.key` and, when it finds it, signs each request it
534
+ sends to Flair with it:
535
+
536
+ ```
537
+ Authorization: TPS-Ed25519 bob-the-bot:<unix-ms>:<nonce>:<base64 signature>
538
+ ```
539
+
540
+ The signature is Ed25519 over `bob-the-bot:<unix-ms>:<nonce>:<METHOD>:<path>`,
541
+ where the path includes any query string. By default the timestamp must be
542
+ within 30 seconds of the server's clock, and a nonce is accepted once. A request
543
+ refused by these checks gets HTTP 401:
544
+
545
+ | Situation | Body |
546
+ |---|---|
547
+ | No Agent record with that id | `{"error":"unknown_agent"}` |
548
+ | Registered id, signed with a key that is not its registered key | `{"error":"invalid_signature"}` |
549
+ | Principal deactivated | `{"error":"principal_deactivated"}` |
550
+ | Timestamp outside the window | `{"error":"timestamp_out_of_window"}` |
551
+
552
+ **Check:** `flair bootstrap --agent bob-the-bot --url https://flair.example.com --json`
553
+ and read `agentId` and `scope`.
554
+ **Revoke:** `flair principal disable bob-the-bot` on the Flair host; its next
555
+ request gets `{"error":"principal_deactivated"}`.
556
+
557
+ `flair agent remove bob-the-bot`, also run on the Flair host, asks you to type
558
+ `yes` (or takes `--force`), then:
559
+
560
+ - searches the agent's `Memory` and `Soul` rows and sends a delete for each one
561
+ it finds, without checking whether each delete succeeded;
562
+ - sends a delete for the `Agent` record, and stops with an error if the
563
+ operations API rejects it;
564
+ - unless you pass `--keep-keys`, attempts to delete the agent's key files
565
+ (private, public and `.bak`) from the keys directory on the machine it runs
566
+ on, ignoring any failure;
567
+ - prints `Key files deleted.` (with `--keep-keys`,
568
+ `Key files preserved (--keep-keys).`) and then
569
+ `✅ Agent 'bob-the-bot' removed successfully`, without checking the Memory,
570
+ Soul and key-file deletions.
571
+
572
+ Rows the agent owns in other tables, such as its workspace state, are left in
573
+ place.
574
+
575
+ #### 5. A bot reaches another OAuth-protected MCP server as itself
576
+
577
+ **Goal:** `bob-the-bot` calls the MCP server at `https://mcp.acme.example`
578
+ without a person signing in, using its Flair key as its client credential
579
+ (`client_credentials` with `private_key_jwt`).
580
+
581
+ When `FLAIR_MCP_ISSUER` or `FLAIR_PUBLIC_URL` is set, Flair publishes a Client
582
+ ID Metadata Document at `/MCPClientMetadata/<agent-id>` for an agent whose record
583
+ holds an Ed25519 public key (64 hex characters, or base64 that decodes to 32
584
+ bytes). With `FLAIR_MCP_ISSUER=https://flair.example.com`, the document for
585
+ `bob-the-bot` is served at
586
+ `https://flair.example.com/MCPClientMetadata/bob-the-bot`:
587
+
588
+ ```json
589
+ {
590
+ "client_id": "https://flair.example.com/MCPClientMetadata/bob-the-bot",
591
+ "client_name": "bob-the-bot",
592
+ "jwks": { "keys": [ { "kty": "OKP", "crv": "Ed25519", "x": "<public key>", "kid": "bob-the-bot" } ] },
593
+ "token_endpoint_auth_method": "private_key_jwt",
594
+ "grant_types": ["client_credentials"]
595
+ }
596
+ ```
597
+
598
+ With neither variable set, the path answers HTTP 501 (`mcp_issuer_not_configured`).
599
+ For an unknown agent, or one with no public key, it answers HTTP 404
600
+ (`agent_not_found_or_no_key`). For a record whose public key does not decode to
601
+ 32 bytes, it answers HTTP 500 (`invalid_agent_key`).
602
+
603
+ The other server's authorization server must allow this. If it runs
604
+ `@harperfast/oauth` 2.5.0, that includes `mcp.clientCredentials.enabled: true`
605
+ and `flair.example.com` in its `clientIdMetadataDocuments.allowedHosts`.
606
+
607
+ On the bot's host, mint a token:
608
+
609
+ ```bash
610
+ flair mcp token --agent-id bob-the-bot \
611
+ --client-id https://flair.example.com/MCPClientMetadata/bob-the-bot \
612
+ --token-endpoint https://mcp.acme.example/oauth/mcp/token \
613
+ --resource https://mcp.acme.example/mcp
614
+ ```
615
+
616
+ It signs an EdDSA assertion with `iss` and `sub` set to the `client_id`, `aud`
617
+ set to the token endpoint, and a lifetime of at most 60 seconds, then sends the
618
+ token request. On success it prints
619
+ `access_token minted (<token type>, expires_in=<seconds>s):` followed by the
620
+ token, which the bot sends as `Authorization: Bearer <token>` to
621
+ `https://mcp.acme.example/mcp`. A `@harperfast/oauth` 2.5.0 server issues these
622
+ tokens for 300 seconds by default and no refresh token; mint another when it
623
+ expires.
624
+
625
+ Flair's own authorization server does not issue these tokens with the shipped
626
+ `config.yaml`, which has no `clientCredentials` block: it answers
627
+ `unsupported_grant_type`. This path is for reaching other servers.
628
+
629
+ **Check:** add `--dry-run` to sign the assertion and print its claims without
630
+ sending it, and fetch the metadata URL to see the published key.
631
+ **Revoke:** the other server's operator can remove `flair.example.com` from its
632
+ list. On Flair, the document remains served for a deactivated agent whose record
633
+ holds a valid Ed25519 public key, so `flair principal disable` does not withdraw
634
+ it. When `flair agent remove bob-the-bot` deletes the `Agent` record, the path
635
+ answers 404. An authorization server that fetched the document earlier can keep
636
+ using its cached copy until that copy expires.
637
+
638
+ #### 6. A bot and a person using the same app
639
+
640
+ **Goal:** alice runs Claude Code herself, and a nightly job runs Claude Code on a
641
+ build server. The job gets its own principal.
642
+
643
+ Register the job's agent as in example 4 and set
644
+ `FLAIR_URL=https://flair.example.com` and `FLAIR_AGENT_ID=bob-the-bot` in the
645
+ build server's MCP config. Do not copy alice's key to the server or set
646
+ `FLAIR_AGENT_ID=alice` there.
647
+
648
+ Why a separate principal:
649
+
650
+ - **Attribution.** The job's writes carry `bob-the-bot`. As a non-admin agent,
651
+ it cannot write a memory owned by `alice`.
652
+ - **Privacy.** alice's `private` memories are not returned to `bob-the-bot`, and
653
+ the bot's `private` memories are not returned to alice (neither is an admin).
654
+ Non-private memories are readable by both. A `memory_store` without a
655
+ `visibility` and with the default `standard` durability is `private`.
656
+ - **Revocation.** `flair principal disable bob-the-bot` gets the job's requests
657
+ refused and leaves alice working. A job that runs as `alice` cannot be cut
658
+ off without cutting off alice too.
659
+
660
+ What the bot reads follows [What they can touch](#3-what-they-can-touch): its
661
+ own memories and other agents' non-private ones. `flair grant` does not narrow
662
+ that, because reads do not consult memory grants.
663
+
664
+ **Check:** `flair bootstrap --agent bob-the-bot --url https://flair.example.com --json`
665
+ on the build server returns `"agentId": "bob-the-bot"` and `"isAdmin": false`
666
+ in `scope`.
667
+ **Revoke:** `flair principal disable bob-the-bot` on the Flair host.