@reclaimprotocol/agent 0.1.38 → 0.1.40

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.
@@ -1,14 +1,17 @@
1
+ import { conflict } from '@hapi/boom';
1
2
  import { deriveFromPrivateKey, generateKeypair } from '@reclaimprotocol/client';
3
+ import { isProblemError } from '@reclaimprotocol/client/api';
2
4
  import assert from 'node:assert';
3
5
  import { isAbsolute, relative, resolve } from 'node:path';
4
6
  import { defineTool } from "../../server.js";
5
- import { normalizeEthHex, readDotenvKey, upsertEnvVar } from "./eth-key.js";
7
+ import { backupEnvVar, normalizeEthHex, readDotenvKey, removeEnvVar, upsertEnvVar, } from "./eth-key.js";
6
8
  /**
7
9
  * Creates the organization's eth key pair for session binding and encrypted
8
10
  * results: writes the private key to the app's server env file and registers
9
11
  * only the public key with Builder, so the private key never passes through
10
12
  * the agent's transcript. Reuses a key the env file already holds, so a
11
- * repeat call (for example, to turn on encryption) keeps the same key.
13
+ * repeat call (for example, to turn on encryption) keeps the same key. With
14
+ * `replace`, always generates a fresh key and rotates the org's key to it.
12
15
  */
13
16
  export function issueOrgKeypairTool(client) {
14
17
  return defineTool({
@@ -20,8 +23,12 @@ export function issueOrgKeypairTool(client) {
20
23
  + 'private key to a server env file in the project (reusing a key '
21
24
  + 'already there) and registers only the public key. Returns the '
22
25
  + 'address, file, and variable; never the key. Returns 409 when the '
23
- + 'org already has a different key: ask the developer for that key '
24
- + 'rather than replacing it.',
26
+ + 'org already has a different key. Set `replace: true` only when '
27
+ + 'the developer asked to rotate or replace the key: it generates '
28
+ + 'a new key and swaps it in one step, and apps holding the old '
29
+ + 'key can no longer decrypt new results. The old key is first '
30
+ + 'appended to `<envFile>.backup` (gitignored); tell the developer '
31
+ + 'its path.',
25
32
  inputSchema: {
26
33
  type: 'object',
27
34
  required: ['orgId', 'projectDir'],
@@ -42,11 +49,17 @@ export function issueOrgKeypairTool(client) {
42
49
  },
43
50
  encryptResults: {
44
51
  type: 'boolean',
45
- description: 'Encrypt delivered results to this key. Default false.',
52
+ description: 'Encrypt delivered results to this key. Default false, or the '
53
+ + 'org\'s current setting with `replace`.',
54
+ },
55
+ replace: {
56
+ type: 'boolean',
57
+ description: 'Rotate: generate a new key and replace the org\'s current '
58
+ + 'one. Default false.',
46
59
  },
47
60
  },
48
61
  },
49
- annotations: { openWorldHint: true, destructiveHint: false },
62
+ annotations: { openWorldHint: true, destructiveHint: true },
50
63
  }, async (args) => {
51
64
  assert(isAbsolute(args.projectDir), new Error('`projectDir` must be an absolute path.'));
52
65
  const envFile = args.envFile || '.env';
@@ -54,22 +67,53 @@ export function issueOrgKeypairTool(client) {
54
67
  const envPath = resolve(args.projectDir, envFile);
55
68
  const inside = relative(args.projectDir, envPath);
56
69
  assert(inside && !inside.startsWith('..') && !isAbsolute(inside), new Error('`envFile` must be inside `projectDir`.'));
57
- const existing = readDotenvKey(envPath, envVar);
70
+ const replace = args.replace ?? false;
71
+ // Rotation always generates a fresh key: the env file's key may or
72
+ // may not be the one the org holds, and reuse would be a no-op.
73
+ const existing = replace ? undefined : readDotenvKey(envPath, envVar);
58
74
  const keypair = existing
59
75
  ? deriveFromPrivateKey(normalizeEthHex(existing))
60
76
  : generateKeypair();
61
- // Register first: a 409 (the org has another key) must not leave a
62
- // key Builder doesn't know in the env file.
63
- const canEncryptResult = args.encryptResults ?? false;
64
- await client.call('SetOrgKeypair', {
65
- params: { orgId: args.orgId },
66
- body: {
67
- publicKey: keypair.publicKey,
68
- canEncryptResult,
69
- replace: false,
70
- },
71
- });
77
+ // A rotation keeps the org's current setting unless the caller sets it.
78
+ const canEncryptResult = args.encryptResults
79
+ ?? (replace && await currentCanEncryptResult());
80
+ // Back up and save the key before the org switches to it, so a
81
+ // failed write can't leave the org on a key no app holds. A failed
82
+ // registration (for example, a 409) puts the env file back.
83
+ const old = readDotenvKey(envPath, envVar);
84
+ const backupFile = old && !existing
85
+ ? backupEnvVar(args.projectDir, envFile, envVar, 'replaced by issue_org_keypair')
86
+ : undefined;
72
87
  const path = upsertEnvVar(args.projectDir, envFile, envVar, keypair.privateKey);
88
+ try {
89
+ await client.call('SetOrgKeypair', {
90
+ params: { orgId: args.orgId },
91
+ body: {
92
+ publicKey: keypair.publicKey,
93
+ canEncryptResult,
94
+ replace,
95
+ },
96
+ });
97
+ }
98
+ catch (err) {
99
+ if (old) {
100
+ upsertEnvVar(args.projectDir, envFile, envVar, old);
101
+ }
102
+ else {
103
+ removeEnvVar(args.projectDir, envFile, envVar);
104
+ }
105
+ if (!replace && isProblemError(err) && err.output.statusCode === 409) {
106
+ throw conflict('The org already has a different key. Ask the developer to '
107
+ + 'choose: (a) reuse it: they paste its private key into '
108
+ + `\`${envFile}\` as \`${envVar}\` themselves, never into the `
109
+ + 'chat; (b) rotate it: call `issue_org_keypair` again with '
110
+ + '`replace: true`, after which apps holding the old key can no '
111
+ + 'longer decrypt new results; (c) turn off result encryption: '
112
+ + 'call `update_org_keypair` with `canEncryptResult: false`, '
113
+ + 'which keeps the key.');
114
+ }
115
+ throw err;
116
+ }
73
117
  return {
74
118
  orgId: args.orgId,
75
119
  address: keypair.address,
@@ -77,6 +121,27 @@ export function issueOrgKeypairTool(client) {
77
121
  envFile: path,
78
122
  envVar,
79
123
  reused: Boolean(existing),
124
+ backupFile: backupFile ?? null,
125
+ ...(replace && !backupFile && !old
126
+ ? {
127
+ note: 'Nothing was backed up: the old private key is not in '
128
+ + 'this file. Another app may hold it.',
129
+ }
130
+ : {}),
80
131
  };
132
+ async function currentCanEncryptResult() {
133
+ try {
134
+ const { data } = await client.call('GetOrgKeypair', {
135
+ params: { orgId: args.orgId },
136
+ });
137
+ return data.canEncryptResult;
138
+ }
139
+ catch (err) {
140
+ if (isProblemError(err) && err.output.statusCode === 404) {
141
+ return false;
142
+ }
143
+ throw err;
144
+ }
145
+ }
81
146
  });
82
147
  }
@@ -1,7 +1,7 @@
1
1
  import assert from 'node:assert';
2
2
  import { isAbsolute, relative, resolve } from 'node:path';
3
3
  import { defineTool } from "../../server.js";
4
- import { upsertEnvVar } from "./eth-key.js";
4
+ import { backupEnvVar, readDotenvKey, upsertEnvVar } from "./eth-key.js";
5
5
  import { saveOrgKey } from "./org-key-store.js";
6
6
  /**
7
7
  * Issues an organization API key and stores it on disk, so the key never
@@ -15,7 +15,9 @@ export function issueOrgTokenTool(client) {
15
15
  + 'server env file in the project, so the app can read it at runtime. '
16
16
  + 'Also saves it on this machine for the org-key tools. Returns the '
17
17
  + 'org, file, variable, and last four characters; never the key. '
18
- + 'Replaces an existing variable of the same name in the file. '
18
+ + 'Replaces an existing variable of the same name in the file, first '
19
+ + 'appending the old value to `<envFile>.backup` (gitignored); tell '
20
+ + 'the developer its path. '
19
21
  + 'Adds the file to .gitignore. Use when the app needs a key, or '
20
22
  + 'before `create_verification_session`.',
21
23
  inputSchema: {
@@ -48,6 +50,10 @@ export function issueOrgTokenTool(client) {
48
50
  const { data } = await client.call('IssueOrgToken', {
49
51
  params: { orgId: args.orgId },
50
52
  });
53
+ const old = readDotenvKey(resolve(args.projectDir, envFile), envVar);
54
+ const backupFile = old && old !== data.orgSecret
55
+ ? backupEnvVar(args.projectDir, envFile, envVar, 'replaced by issue_org_token')
56
+ : undefined;
51
57
  const path = upsertEnvVar(args.projectDir, envFile, envVar, data.orgSecret);
52
58
  saveOrgKey(args.orgId, data.orgSecret);
53
59
  return {
@@ -55,6 +61,7 @@ export function issueOrgTokenTool(client) {
55
61
  envFile: path,
56
62
  envVar,
57
63
  last4: data.last4,
64
+ backupFile: backupFile ?? null,
58
65
  };
59
66
  });
60
67
  }
@@ -80,10 +80,11 @@ export function assertPortableMatches(matches, redactions, targets) {
80
80
  // proving an email's domain substring. Reject it regardless of the declared
81
81
  // targets (the local part is usually not itself a target, so the value scan
82
82
  // below wouldn't catch it). Strip params + named groups + regex escapes
83
- // first, then look for `localpart@` as a surviving literal.
83
+ // first, then look for `localpart@` as a surviving literal. A placeholder
84
+ // never contains a brace, and `[^{}]` keeps the scan linear on `{{{{…`.
84
85
  const EMAIL_LOCAL_BAKED = /[A-Za-z0-9._%+-]{3,}@/;
85
86
  const deregex = (s) => s
86
- .replace(/\{\{[^}]*\}\}/g, '')
87
+ .replace(/\{\{[^{}]*\}\}/g, '')
87
88
  .replace(/\(\?<[^>]*>[^)]*\)/g, '')
88
89
  .replace(/\\(.)/g, '$1');
89
90
  const scanEmail = (text, where) => {
@@ -110,7 +111,7 @@ export function assertPortableMatches(matches, redactions, targets) {
110
111
  if (!guarded.length) {
111
112
  return;
112
113
  }
113
- const stripParams = (s) => s.replace(/\{\{[^}]*\}\}/g, '');
114
+ const stripParams = (s) => s.replace(/\{\{[^{}]*\}\}/g, '');
114
115
  const scan = (text, where, own) => {
115
116
  const bare = stripParams(text);
116
117
  for (const v of guarded) {
@@ -572,7 +572,7 @@ function stableOpeningTail(openTag) {
572
572
  * content (the JSON body the attestor exposes when a jsonPath is paired with
573
573
  * the script's xPath); otherwise undefined. */
574
574
  function scriptJsonContent(markup) {
575
- const match = /^<script\b[^>]*>([\s\S]*)<\/script>\s*$/i.exec(markup);
575
+ const match = /^<script\b[^>]*>([\s\S]*)<\/script\b[^>]*>\s*$/i.exec(markup);
576
576
  if (!match) {
577
577
  return undefined;
578
578
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reclaimprotocol/agent",
3
3
  "title": "Reclaim Agent",
4
- "version": "0.1.38",
4
+ "version": "0.1.40",
5
5
  "description": "Reclaim Protocol tools for AI coding agents. Reclaim lets your app verify data points about its users, such as a follower count, an account balance, or an order history. This package is the Reclaim MCP server: it gives your agent the tools to find, build, test, and fix data verification providers by capturing and replaying browser requests, drafting provider recipes, running zkTLS proofs, and publishing provider versions.",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
@@ -84,7 +84,7 @@
84
84
  "@noble/hashes": "^2.2.0",
85
85
  "@puppeteer/browsers": "3.2.4",
86
86
  "@reclaimprotocol/attestor-core": "^5.1.6",
87
- "@reclaimprotocol/client": "0.1.38",
87
+ "@reclaimprotocol/client": "0.1.40",
88
88
  "@reclaimprotocol/tls": "^0.1.3",
89
89
  "chrome-remote-interface": "^0.33.0",
90
90
  "domhandler": "^6.0.0",
@@ -8,6 +8,7 @@
8
8
  "dependencies": {
9
9
  "@reclaimprotocol/js-sdk": "^5.8.1",
10
10
  "dotenv": "^16.4.5",
11
- "express": "^4.21.2"
11
+ "express": "^4.21.2",
12
+ "express-rate-limit": "^8.7.1"
12
13
  }
13
14
  }
@@ -1,4 +1,5 @@
1
1
  import express from "express";
2
+ import { rateLimit } from "express-rate-limit";
2
3
  import "dotenv/config";
3
4
  import { ReclaimProofRequest, verifyProof } from "@reclaimprotocol/js-sdk";
4
5
  import { randomUUID } from "node:crypto";
@@ -9,8 +10,12 @@ const providerId = __PROVIDER_ID__;
9
10
  // Left unpinned by default — set this if you need to pin a specific version.
10
11
  const providerVersion = __PROVIDER_VERSION__;
11
12
 
12
- app.set("trust proxy", true);
13
+ // One proxy hop (ngrok or a load balancer), so the rate limit below keys on
14
+ // the client's address rather than the proxy's.
15
+ app.set("trust proxy", 1);
13
16
  app.use(express.json({ limit: "2mb" }));
17
+ // Every route verifies or creates something; cap each client's request rate.
18
+ app.use(rateLimit({ windowMs: 60_000, limit: 60 }));
14
19
 
15
20
  app.get("/health", (_req, res) => {
16
21
  res.json({ ok: true });
@@ -68,6 +68,12 @@ immediately with a `code` and `attachUrl` — it does NOT poll.
68
68
  The 2-day token is cached in `~/.reclaim/config.json` and reused on later runs
69
69
  (`RECLAIM_API_TOKEN` in the server env overrides it).
70
70
 
71
+ ### Backend mode
72
+
73
+ `get_devtools_mode` reports the active mode. `set_devtools_mode` persists a
74
+ switch to `~/.reclaim/config.json`, effective on the next server start. An
75
+ explicit `USE_OLD_DEVTOOLS` env var wins.
76
+
71
77
  <!-- topic: devtools-migration -->
72
78
  ## Import providers from devtools
73
79
 
@@ -316,6 +322,14 @@ with no secrets/cookies, as an anonymous visitor.
316
322
  — **show it to the developer as a fenced JSON block at the end**, with the
317
323
  provider JSON. That's the final result.
318
324
 
325
+ **Country.** `run_proof` sends the attestor's request from the developer's own
326
+ IP country, which is what `{{DYNAMIC_GEO}}` becomes when they verify; `egress`
327
+ in the result names the country. If a site that serves one country (for
328
+ example, a US airline) blocks the attestor, retry once with
329
+ `geoLocation: "US"`. If that verifies, pin it with
330
+ `update_draft({ geoLocation: "US" })` so the published version goes out from
331
+ there too.
332
+
319
333
  **`errorKind: "missing-owner-key"`** → no eth proof-owner key yet. Tell the
320
334
  developer what's happening and drive the bootstrap yourself — see topic
321
335
  `credentials`. No restart needed, and the existing `draftId` stays valid.
@@ -396,16 +410,17 @@ in, navigate to `initialUrl`; if a user script is present, run
396
410
  `test_user_script` with that script and `initialUrl`. When the existing capture
397
411
  has enough data, replay and prove every required request. Do not clear
398
412
  cookies or force another sign-in. Treat an unavailable or inconclusive retest as
399
- advisory and do not block publication. Ask whether the developer wants to keep
400
- the session for further edits; call `dispose_browser` only after they confirm.
401
- A `builder` session is quota-accounted, so don't leave it idle.
413
+ advisory and do not block publication. Don't ask whether to close the
414
+ browser. Mention once in the final summary that it stays open for provider
415
+ changes and you can close it on request; call `dispose_browser` only when the
416
+ developer says so. A `builder` session is quota-accounted, so close it as soon
417
+ as they say the work is done.
402
418
 
403
419
  <!-- topic: discover -->
404
420
  ## Discover and resolve existing providers
405
421
 
406
- Use this flow only when the developer asks to reuse existing providers or
407
- doesn't know what a site supports. Otherwise build a new provider (server
408
- instructions, "Choose the provider").
422
+ Use this flow only when the developer asks to reuse existing providers, names
423
+ one, or doesn't know what a site supports. Otherwise build a new provider.
409
424
 
410
425
  1. Ask which website their users prove data from.
411
426
  2. `discover_data_points({ domain })` → what's verifiable there. Confirm the
@@ -415,13 +430,17 @@ instructions, "Choose the provider").
415
430
  any `uncovered` points (author those with the checklist in topic
416
431
  `overview`, then re-resolve).
417
432
  4. Use only the data points the developer confirmed: show and read only those
418
- and ignore the rest. A provider that needs any change gets your own copy
419
- (server instructions, "Choose the provider"). Otherwise it's usable as-is;
420
- don't capture, replay, or prove it unless the developer asks.
433
+ and ignore the rest. A provider that needs any change (a missing data point, extra inputs, a different extraction) gets your own copy
434
+ (`create_provider_version` when your org owns it; otherwise
435
+ `create_provider`, then `create_provider_version` from a copy of its
436
+ config, trimmed to the requested data points). Otherwise it's published and
437
+ usable as-is; don't capture, replay, or prove it unless the developer asks.
438
+ When a requirement (site, account, or value) is ambiguous, ask one concise
439
+ question; don't guess.
421
440
  5. To try them: `create_verification_session({ providers: [{ providerId }, …],
422
441
  context, verificationClientUrl })` with EVERY resolved provider id and the
423
- collected context. The server instructions ("Try a provider without an
424
- app") cover the callback and polling. To integrate: topic `integration`.
442
+ collected context. Topic `integration` ("Try a provider without an app")
443
+ covers the callback and polling, and the integration steps.
425
444
 
426
445
  `merge.mergeable` only signals the set *could* collapse into one provider. Pass
427
446
  them all; the Builder runs them in one session.
@@ -74,6 +74,14 @@ and are NOT interchangeable.
74
74
  `reclaim_authenticate` ran earlier, the old-devtools token has expired — re-run
75
75
  it. Don't assume `authenticate_builder` fixes it.
76
76
 
77
+ ### Backend mode
78
+
79
+ The BUILDER backend (generated API tools, orgs, verification sessions, public
80
+ review) is one switch away. `get_devtools_mode` reports the active mode and
81
+ why; `set_devtools_mode` persists a switch to `~/.reclaim/config.json`,
82
+ effective on the NEXT server start. An explicit `USE_OLD_DEVTOOLS` env var wins
83
+ over the persisted choice.
84
+
77
85
  <!-- topic: browser -->
78
86
  <!-- common: browser -->
79
87
 
@@ -320,8 +328,17 @@ applies them.
320
328
  There's no create-then-version step and no org / public-review workflow here.
321
329
  When done, tell the developer the version is live, then ask once how they want
322
330
  to use it — try it now, integrate it into an existing backend or frontend, or
323
- create a new app — unless they already said (see "Using a provider" in the
324
- server instructions).
331
+ create a new app — unless they already said:
332
+
333
+ > Want to (1) try it right now here, (2) integrate it into an existing backend
334
+ > or frontend (this directory or another path), or (3) create a new app for it?
335
+
336
+ Try it now → `scaffold_reclaim_demo_server` with its `providerId`. Integrate,
337
+ or new app → `get_js_sdk_integration_guide`, then work in the path they named.
338
+
339
+ A provider found with `get_me_providers` or `get_provider_info` is published
340
+ and usable as-is. Don't capture, `replay_request`, or `run_proof` against it
341
+ unless the developer asks you to check or test it.
325
342
 
326
343
  **If the response includes `_notes` for an attached browser, follow them for an
327
344
  optional authenticated-state retest.** Only when its profile is still signed in,
@@ -329,9 +346,10 @@ navigate to `initialUrl`; if `customInjection` is present, run
329
346
  `test_user_script` with that script and `initialUrl`. When the existing capture
330
347
  has enough data, replay and prove every required request. Do not clear
331
348
  cookies or force another sign-in. Treat an unavailable or inconclusive retest as
332
- advisory and do not block the completed provider. Ask whether the developer
333
- wants to keep the session for further edits; call `dispose_browser` only after
334
- they confirm.
349
+ advisory and do not block the completed provider. Don't ask whether to close the
350
+ browser. Mention once in the final summary that it stays open for provider
351
+ changes and you can close it on request; call `dispose_browser` only when the
352
+ developer says so.
335
353
 
336
354
  <!-- topic: never-do -->
337
355
  ## Things to never do
@@ -1,186 +1,51 @@
1
1
  # Builder mode
2
2
 
3
- Reclaim provider-authoring tools run against the Builder backend: generated
4
- Builder API tools, credential and verification helpers, and browser authoring
5
- tools.
3
+ Provider-authoring and verification tools for the Builder backend.
6
4
 
7
- **A provider is a recipe for extracting a data point from a site. A
8
- verification is an end-user session that proves a data point with a provider.
9
- Never call a provider a "verification."**
5
+ **A provider is a recipe for extracting a data point from a site. A verification is an end-user session that proves a data point with a provider. Never call a provider a "verification."**
10
6
 
11
- ## What the developer wants
7
+ ## Routing
12
8
 
13
- - **"Add Reclaim to my app" or similar:** call `start_integration` first and
14
- follow the plan it returns. Don't ask what they want to do with the result.
15
- - **A claim they describe** (for example, "prove the user is over 18 on
16
- example.com"): build a new org-private provider for exactly that claim. See
17
- "Choose the provider".
18
- - **Intent unclear:** ask one short question.
9
+ - "Add Reclaim to my app" or similar: call `start_integration` first and follow its plan. Don't ask what they want to do with the result.
10
+ - A claim they describe (for example, "prove the user is over 18 on example.com"): build a new org-private provider for exactly that claim. Use an existing provider only when they name one or ask to reuse one (topic `discover`).
11
+ - Intent unclear: ask one short question.
19
12
 
20
- ### Work order
13
+ ## Authoring rules
21
14
 
22
- Do the steps that need the developer first: sign in to Builder, attach the
23
- browser, capture, and prove the provider. They show early whether a proof is
24
- possible on the site. Write app code after the proof works, or while you wait
25
- on the developer.
15
+ - Do the steps that need the developer first (sign in, attach the browser, capture, prove). Write app code after the proof works, or while you wait.
16
+ - Call `attach_browser()` with no arguments. Don't ask which browser to use.
17
+ - Propose only the data points the claim needs.
18
+ - Provider versions are immutable: every change creates a new version.
26
19
 
27
- ### Asking the developer
20
+ ## Asking the developer
28
21
 
29
- When you need an answer or an action from the developer before you can
30
- continue, end your turn with the question. Don't ask a blocking question
31
- through a background or asynchronous question tool: the developer may never
32
- see it. Put every link they need, such as a sign-in or verification URL, in
33
- that same message.
22
+ - When you need an answer or an action, end your turn with the question. Don't use a background or asynchronous question tool: the developer may never see it.
23
+ - Put every link they need, such as a sign-in or verification URL, in that same message.
24
+ - Ask each question once. Act on the answer; don't ask again.
34
25
 
35
- ### Choose the provider
26
+ ## Permission blocks
36
27
 
37
- Default: build a new provider for the claim the developer described. Use an
38
- existing provider only when they name one or ask to reuse one.
28
+ When a permission check blocks a tool call or command:
39
29
 
40
- With an existing provider, use only the data points the developer asked for.
41
- Show the developer only those, collect only the inputs they need, and read
42
- only those from results. Ignore the provider's other data points.
43
-
44
- Make your own copy when it needs any change, for example it lacks a requested
45
- data point, requires inputs the developer didn't ask for, or extracts a value
46
- differently:
47
-
48
- - Your org owns it: create a new provider version.
49
- - Another org owns it: `create_provider`, then `create_provider_version` from a
50
- copy of its config, trimmed to the requested data points.
51
-
52
- Requirement ambiguous (site, account, or value): ask one concise question.
53
- Don't guess.
54
-
55
- A provider used as-is is published and ready. Don't capture, `replay_request`,
56
- or `run_proof` against it unless the developer asks.
57
-
58
- ### Try a provider without an app
59
-
60
- Session creation returns 409 while the org has no callback subscription.
61
- `read_callback_events` creates the org's pull listener, which satisfies that
62
- check and holds results for you to read. No tunnel or public URL is needed.
63
-
64
- 1. Call `read_callback_events`.
65
- 2. `create_verification_session`, then give the developer `verificationUrl`.
66
- 3. Poll `get_verification_session` until it is terminal.
67
- `list_verification_events` shows progress. Don't read the hosted
68
- verification page for progress: it streams the site as an image, so text
69
- and DOM checks of it come back empty.
70
- 4. Call `read_callback_events({ sessionId })` for the verified result.
71
-
72
- When you set up a new provider build, call `check_attestor` once. If it fails,
73
- tell the developer before they spend time on the build.
30
+ 1. Don't retry it or work around it.
31
+ 2. In one message, name the blocked tool or command, what it does, and what approving it means.
32
+ 3. Ask for approval in words that name that exact action, for example: "Approve running `npm run dev` to start the example app?" A vague question doesn't cover it.
74
33
 
75
34
  ## Secrets
76
35
 
77
- - Never print, echo, or ask the developer to paste an org key (`rorg_…`) or
78
- private key.
79
- - `issue_org_token` writes the key to the project's env file
80
- (`RECLAIM_ORG_SECRET`) and returns only its last four characters. Session
81
- and org-token tools use that key when you omit `orgToken`.
82
- - `issue_credentials` and `import_credentials({ keyFile })` write the proof
83
- owner key to the env file. Use these tools, not shell commands that read
84
- secret files.
85
-
86
- ## Integrating into an app
87
-
88
- Call `start_integration` and follow its order: prove the provider first, then
89
- write app code. Read `how_it_works({ topic: "integration" })`
90
- for the HTTP session workflow, the `api=2` boundary, result verification, and
91
- TEE binding. Edit the app with your file tools. Use the HTTP API
92
- (`POST /verifications/sessions`, open `verificationUrl`, poll
93
- `GET /verifications/sessions/{sessionId}`, read the callback) rather than
94
- `@reclaimprotocol/client`. The only exception is `results.receive` on the
95
- callback, or when the developer asks for the client package.
96
-
97
- The app's frontend renders every state and every failure, never only a
98
- spinner. Follow "UI states" in `how_it_works({ topic: "integration" })`. The
99
- callback route responds `error.retryable ? 503 : 200` for a thrown
100
- `ResultVerificationError`; a result that failed verification gets 2xx.
101
-
102
- For local development, call `proxy_callback_events({ port, path })` to forward
103
- events to the app's callback route on localhost. The local listener works only
104
- while this MCP server runs. It keeps events in order per session and retries
105
- a session the app rejects with backoff, so other sessions keep flowing. When
106
- its status lists `blocked` sessions, read that session's callback route
107
- response and logs, and fix the app. Production needs a webhook:
108
- `create_org_callback_subscription` with the deployed app's public URL. Without
109
- one, session creation returns 409.
110
-
111
- Management tools (`list_orgs`, `create_org_callback_subscription`,
112
- `issue_org_token`) use the developer's sign-in. Session tools
113
- (`create_verification_session`, `get_verification_session`,
114
- `list_verification_events`, `list_verification_deliveries`,
115
- `retry_verification_callback`, `read_callback_events`,
116
- `proxy_callback_events`) are the production API and use the org key.
117
-
118
- **Existing `@reclaimprotocol/js-sdk` projects.** If `package.json` depends on
119
- `@reclaimprotocol/js-sdk`, ask first:
120
-
121
- > This project uses `@reclaimprotocol/js-sdk`. Keep it (I switch this MCP
122
- > server to legacy devtools mode), or migrate to the Builder HTTP API?
123
-
124
- - **Keep:** `set_devtools_mode({ mode: "old" })`, then tell them to restart or
125
- reconnect the MCP server. An explicit `USE_OLD_DEVTOOLS` env var overrides
126
- it. After the restart, read `get_js_sdk_integration_guide`.
127
- - **Migrate:** stay in Builder mode and follow topic `integration`.
128
-
129
- ## Authoring a provider
130
-
131
- Provider versions are immutable. Every change creates a new semantic version
132
- (default: patch bump; larger only when the developer directs). Never use an
133
- in-place update or archive tool.
134
-
135
- **The flow:** `attach_browser` → `start_capture` ⇒ `captureId` → sign in →
136
- navigation script (`test_user_script` with `keep: true`) → capture through the
137
- script → `find_requests_containing` → `propose_provider` ⇒ `draftId` →
138
- `replay_request` → `run_proof` → `create_provider_version_from_capture` →
139
- `publish_provider_version` (private) or `submit_provider_version_for_review`
140
- (public). Get the checklist from `how_it_works({ topic: "overview" })`.
141
-
142
- - **Data points:** propose only values the claim needs, usually one or two.
143
- Never add identity or profile fields. Name each for what it proves.
144
- - **Browser:** call `attach_browser()` with no arguments. It opens a visible
145
- local browser with the persistent Reclaim profile, and falls back to Chrome
146
- for Testing itself when no installed browser can be attached. Don't ask
147
- which browser or who signs in. Use another `mode` only when that fails too,
148
- or when the developer explicitly asks for it (topic `browser`). Tell the
149
- developer once, as a side note, that a shareable link can be set up if a
150
- volunteer is helping them sign in; don't ask about it or set it up unless
151
- they ask.
152
- - **Public endpoints:** after `replay_request` succeeds, re-run it with
153
- `withoutSecrets: true`. If the value still extracts, the endpoint is public
154
- and the proof binds to nobody. Find an auth-bound request.
155
- - **Country:** `run_proof` sends the attestor's request from the developer's
156
- own IP country, which is what `{{DYNAMIC_GEO}}` becomes when they verify;
157
- `egress` in the result says which country. If a site that serves one
158
- country (for example, a US airline) blocks the attestor, retry once with
159
- `geoLocation: "US"`. If that verifies, pin it with
160
- `update_draft({ geoLocation: "US" })` so the published version goes out
161
- from there too.
162
- - **Drafting limits** (topics `draft`, `params`): never `hash` a value that
163
- also appears in the request URL. A param named with `SECRET` may appear in a
164
- URL only within a small character budget (2 under `key-update`, 12 under
165
- `zk`).
36
+ - Never print, echo, or ask the developer to paste an org key (`rorg_…`) or private key.
37
+ - `issue_org_token` writes the org key to the project's env file (`RECLAIM_ORG_SECRET`) and returns only its last four characters. `issue_credentials` and `import_credentials({ keyFile })` write the proof-owner key there. Use these tools, not shell commands that read secret files.
166
38
 
167
39
  ## Evidence contract
168
40
 
169
- Tool results are the source of truth. Never say a browser attached, a user
170
- signed in, a request was captured, a proof passed, or a version was created or
171
- published unless a tool result says so.
41
+ Tool results are the source of truth. Never say a browser attached, a user signed in, a request was captured, a proof passed, or a version was created or published unless a tool result says so.
172
42
 
173
- Treat every ID, version, URL, and value as opaque: copy it from the latest tool
174
- result. Never invent or reconstruct one. When state is unclear, call the
175
- relevant get/list tool or `how_it_works`. State uncertainty plainly.
43
+ Treat every ID, version, URL, and value as opaque: copy it from the latest tool result. Never invent or reconstruct one. When state is unclear, call the relevant get/list tool or `how_it_works`. State uncertainty plainly.
176
44
 
177
- **Guide:** `how_it_works({})` lists topics. Fetch only the one for your next
178
- step.
45
+ ## Guide
179
46
 
180
- **Authentication:** call `get_me`. On 401, `authenticate({})` returns `code`
181
- and `attachUrl`. Give the developer the URL, then poll `authenticate({ code })`
182
- until LINKED (topic `auth`).
47
+ `how_it_works({})` lists topics. Fetch only the one for your next step:
183
48
 
184
- **Backend mode:** `get_devtools_mode` reports the active mode.
185
- `set_devtools_mode` persists a switch to `~/.reclaim/config.json`, effective on
186
- the next server start. An explicit `USE_OLD_DEVTOOLS` env var wins.
49
+ - `overview`: authoring checklist; `prove`, `publish`, `browser`: the details behind each step.
50
+ - `integration`: app integration, trying a session without an app, existing `@reclaimprotocol/js-sdk` projects.
51
+ - `auth`: sign-in (`get_me`, then `authenticate` on 401) and backend mode.