@totalreclaw/mcp-server 1.1.0 → 1.3.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.
- package/README.md +57 -33
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +26 -10
- package/dist/cli/setup.js.map +1 -1
- package/dist/index.js +133 -63
- package/dist/index.js.map +1 -1
- package/dist/prompts.d.ts +3 -3
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +2 -2
- package/dist/subgraph/crypto.d.ts +1 -1
- package/dist/subgraph/crypto.js +1 -1
- package/dist/subgraph/embedding.d.ts +17 -18
- package/dist/subgraph/embedding.d.ts.map +1 -1
- package/dist/subgraph/embedding.js +25 -31
- package/dist/subgraph/embedding.js.map +1 -1
- package/dist/subgraph/lsh.d.ts +1 -1
- package/dist/subgraph/lsh.js +1 -1
- package/dist/subgraph/store.d.ts +16 -1
- package/dist/subgraph/store.d.ts.map +1 -1
- package/dist/subgraph/store.js +92 -3
- package/dist/subgraph/store.js.map +1 -1
- package/dist/tools/import-from.d.ts +1 -1
- package/dist/tools/import-from.d.ts.map +1 -1
- package/dist/tools/remember.d.ts +1 -1
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +2 -2
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/status.d.ts +11 -0
- package/dist/tools/status.d.ts.map +1 -1
- package/dist/tools/status.js +10 -1
- package/dist/tools/status.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="../docs/assets/logo.png" alt="TotalReclaw" width="80" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">@totalreclaw/mcp-server</h1>
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Encrypted memory for Claude Desktop, Cursor, Windsurf, and any MCP-compatible agent</strong>
|
|
9
|
+
</p>
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://totalreclaw.xyz">Website</a> ·
|
|
13
|
+
<a href="https://www.npmjs.com/package/@totalreclaw/mcp-server">npm</a> ·
|
|
14
|
+
<a href="../docs/guides/beta-tester-guide.md">Getting Started</a>
|
|
15
|
+
</p>
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://www.npmjs.com/package/@totalreclaw/mcp-server"><img src="https://img.shields.io/npm/v/@totalreclaw/mcp-server?color=7B5CFF" alt="npm version"></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@totalreclaw/mcp-server"><img src="https://img.shields.io/npm/dm/@totalreclaw/mcp-server" alt="npm downloads"></a>
|
|
20
|
+
<a href="../LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="License"></a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
End-to-end encrypted memory vault as an MCP server. Your memories are encrypted on your device before leaving -- no one can read them, not even us.
|
|
10
26
|
|
|
11
|
-
|
|
27
|
+
## Quick Start
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
### 1. Run the setup wizard
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npx @totalreclaw/mcp-server setup
|
|
33
|
+
```
|
|
16
34
|
|
|
17
|
-
|
|
35
|
+
The wizard generates your 12-word recovery phrase, registers you, and prints a config snippet for your MCP client.
|
|
18
36
|
|
|
19
37
|
> **Save your recovery phrase somewhere safe.** It's the only way to recover your encrypted memories.
|
|
20
38
|
|
|
39
|
+
> **Note:** The first run downloads a ~600MB embedding model for local inference. This is cached locally and only happens once.
|
|
40
|
+
|
|
21
41
|
### 2. Add to your MCP client
|
|
22
42
|
|
|
23
43
|
#### Claude Desktop
|
|
@@ -32,7 +52,7 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
|
32
52
|
"args": ["-y", "@totalreclaw/mcp-server"],
|
|
33
53
|
"env": {
|
|
34
54
|
"TOTALRECLAW_SERVER_URL": "https://api.totalreclaw.xyz",
|
|
35
|
-
"
|
|
55
|
+
"TOTALRECLAW_RECOVERY_PHRASE": "your twelve word recovery phrase goes here"
|
|
36
56
|
}
|
|
37
57
|
}
|
|
38
58
|
}
|
|
@@ -50,7 +70,7 @@ Add to your MCP settings (Settings > MCP Servers):
|
|
|
50
70
|
"args": ["-y", "@totalreclaw/mcp-server"],
|
|
51
71
|
"env": {
|
|
52
72
|
"TOTALRECLAW_SERVER_URL": "https://api.totalreclaw.xyz",
|
|
53
|
-
"
|
|
73
|
+
"TOTALRECLAW_RECOVERY_PHRASE": "your twelve word recovery phrase goes here"
|
|
54
74
|
}
|
|
55
75
|
}
|
|
56
76
|
}
|
|
@@ -58,30 +78,19 @@ Add to your MCP settings (Settings > MCP Servers):
|
|
|
58
78
|
|
|
59
79
|
### 3. Verify
|
|
60
80
|
|
|
61
|
-
Ask your
|
|
62
|
-
|
|
63
|
-
It should confirm access to `totalreclaw_remember`, `totalreclaw_recall`, `totalreclaw_forget`, and `totalreclaw_export`.
|
|
81
|
+
Ask your agent: *"Do you have access to TotalReclaw memory tools?"*
|
|
64
82
|
|
|
65
83
|
## How It Works
|
|
66
84
|
|
|
67
85
|
All encryption happens **client-side** inside the MCP server process on your machine:
|
|
68
86
|
|
|
69
87
|
1. Facts are encrypted with AES-256-GCM before leaving your device
|
|
70
|
-
2. Search uses blind indices (SHA-256 hashes)
|
|
71
|
-
3. Your recovery phrase derives all keys via Argon2id + HKDF
|
|
88
|
+
2. Search uses blind indices (SHA-256 hashes) -- the server never sees your queries
|
|
89
|
+
3. Your recovery phrase derives all keys via Argon2id + HKDF
|
|
72
90
|
4. Encrypted facts are stored on-chain (Gnosis Chain) and indexed by The Graph
|
|
73
91
|
|
|
74
92
|
The server only ever sees ciphertext and hashed tokens.
|
|
75
93
|
|
|
76
|
-
## Environment Variables
|
|
77
|
-
|
|
78
|
-
| Variable | Description | Default |
|
|
79
|
-
|----------|-------------|---------|
|
|
80
|
-
| `TOTALRECLAW_SERVER_URL` | TotalReclaw server URL | `https://api.totalreclaw.xyz` |
|
|
81
|
-
| `TOTALRECLAW_MASTER_PASSWORD` | 12-word BIP-39 recovery phrase | Required |
|
|
82
|
-
| `TOTALRECLAW_SELF_HOSTED` | Set to `true` to use a self-hosted server instead of the managed service. | `false` |
|
|
83
|
-
| `TOTALRECLAW_CHAIN_ID` | Chain ID (100=Gnosis mainnet, 10200=Chiado testnet). Managed service only. | `100` |
|
|
84
|
-
|
|
85
94
|
## Available Tools
|
|
86
95
|
|
|
87
96
|
| Tool | Description |
|
|
@@ -91,28 +100,43 @@ The server only ever sees ciphertext and hashed tokens.
|
|
|
91
100
|
| `totalreclaw_forget` | Delete a specific memory by ID |
|
|
92
101
|
| `totalreclaw_export` | Export all memories decrypted as Markdown or JSON |
|
|
93
102
|
| `totalreclaw_status` | Check billing status and quota usage |
|
|
94
|
-
| `totalreclaw_import` | Re-import previously exported memories
|
|
103
|
+
| `totalreclaw_import` | Re-import previously exported memories |
|
|
95
104
|
| `totalreclaw_import_from` | Import from Mem0 or MCP Memory Server |
|
|
96
105
|
| `totalreclaw_consolidate` | Merge duplicate and related memories |
|
|
97
106
|
| `totalreclaw_upgrade` | Get a link to upgrade to Pro |
|
|
98
107
|
|
|
108
|
+
## Environment Variables
|
|
109
|
+
|
|
110
|
+
| Variable | Description | Default |
|
|
111
|
+
|----------|-------------|---------|
|
|
112
|
+
| `TOTALRECLAW_SERVER_URL` | TotalReclaw server URL | `https://api.totalreclaw.xyz` |
|
|
113
|
+
| `TOTALRECLAW_RECOVERY_PHRASE` | 12-word BIP-39 recovery phrase | Required |
|
|
114
|
+
| `TOTALRECLAW_SELF_HOSTED` | Use a self-hosted server instead of the managed service | `false` |
|
|
115
|
+
| `TOTALRECLAW_CHAIN_ID` | Chain ID (100=Gnosis mainnet, 84532=Base Sepolia staging) | `100` |
|
|
116
|
+
|
|
99
117
|
## Free Tier & Pricing
|
|
100
118
|
|
|
101
|
-
| Tier |
|
|
102
|
-
|
|
103
|
-
| **Free** |
|
|
104
|
-
| **Pro** |
|
|
119
|
+
| Tier | Memories | Reads | Storage | Price |
|
|
120
|
+
|------|----------|-------|---------|-------|
|
|
121
|
+
| **Free** | 500/month | Unlimited | Testnet (trial) | $0 |
|
|
122
|
+
| **Pro** | Unlimited | Unlimited | Permanent on-chain (Gnosis) | $5/month |
|
|
105
123
|
|
|
106
|
-
Pay with card
|
|
124
|
+
Pay with card via Stripe. Counter resets monthly.
|
|
107
125
|
|
|
108
126
|
## Development
|
|
109
127
|
|
|
110
128
|
```bash
|
|
111
|
-
npm run build # Build
|
|
129
|
+
npm run build # Build
|
|
112
130
|
npm test # Run tests
|
|
113
|
-
npm run lint # Lint
|
|
131
|
+
npm run lint # Lint
|
|
114
132
|
```
|
|
115
133
|
|
|
134
|
+
## Learn More
|
|
135
|
+
|
|
136
|
+
- [Getting Started Guide](../docs/guides/beta-tester-guide.md)
|
|
137
|
+
- [totalreclaw.xyz](https://totalreclaw.xyz)
|
|
138
|
+
- [Main Repository](https://github.com/p-diogo/totalreclaw)
|
|
139
|
+
|
|
116
140
|
## License
|
|
117
141
|
|
|
118
142
|
MIT
|
package/dist/cli/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0BH;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAWzF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAG9D;AAgED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAYtF;AAED,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAInE;AAiCD,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0BH;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAWzF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAG9D;AAgED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAYtF;AAED,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAInE;AAiCD,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAwH9C"}
|
package/dist/cli/setup.js
CHANGED
|
@@ -160,7 +160,7 @@ function printConfigSnippet(serverUrl) {
|
|
|
160
160
|
command: 'npx',
|
|
161
161
|
args: ['@totalreclaw/mcp-server'],
|
|
162
162
|
env: {
|
|
163
|
-
|
|
163
|
+
TOTALRECLAW_RECOVERY_PHRASE: '<your-12-word-recovery-phrase>',
|
|
164
164
|
TOTALRECLAW_SERVER_URL: serverUrl,
|
|
165
165
|
},
|
|
166
166
|
},
|
|
@@ -171,7 +171,7 @@ function printConfigSnippet(serverUrl) {
|
|
|
171
171
|
console.log('(Claude Desktop / Cursor / VS Code):');
|
|
172
172
|
console.log('========================================\n');
|
|
173
173
|
console.log(JSON.stringify(snippet, null, 2));
|
|
174
|
-
console.log('\nReplace <your-12-word-
|
|
174
|
+
console.log('\nReplace <your-12-word-recovery-phrase> with your actual recovery phrase.');
|
|
175
175
|
console.log('');
|
|
176
176
|
}
|
|
177
177
|
// ---------------------------------------------------------------------------
|
|
@@ -181,29 +181,29 @@ async function runSetup() {
|
|
|
181
181
|
const rl = createInterface();
|
|
182
182
|
console.log('');
|
|
183
183
|
console.log('=== TotalReclaw Setup ===');
|
|
184
|
-
console.log('
|
|
184
|
+
console.log('End-to-end encrypted memory for AI agents.');
|
|
185
185
|
console.log('');
|
|
186
186
|
try {
|
|
187
187
|
// ── Step 1: Mnemonic ──────────────────────────────────────────────────
|
|
188
188
|
let mnemonic;
|
|
189
|
-
const hasExisting = await ask(rl, 'Do you have an existing
|
|
189
|
+
const hasExisting = await ask(rl, 'Do you have an existing recovery phrase? (y/n): ');
|
|
190
190
|
if (hasExisting.toLowerCase() === 'y' || hasExisting.toLowerCase() === 'yes') {
|
|
191
191
|
// Import existing mnemonic
|
|
192
192
|
console.log('');
|
|
193
|
-
console.log('Enter your 12-word
|
|
193
|
+
console.log('Enter your 12-word recovery phrase (space-separated):');
|
|
194
194
|
mnemonic = await ask(rl, '> ');
|
|
195
195
|
if (!(0, bip39_1.validateMnemonic)(mnemonic, english_js_1.wordlist)) {
|
|
196
196
|
console.error('\nError: Invalid mnemonic. Please check your words and try again.');
|
|
197
197
|
rl.close();
|
|
198
198
|
process.exit(1);
|
|
199
199
|
}
|
|
200
|
-
console.log('\
|
|
200
|
+
console.log('\nRecovery phrase validated successfully.');
|
|
201
201
|
}
|
|
202
202
|
else {
|
|
203
203
|
// Generate new mnemonic
|
|
204
204
|
mnemonic = (0, bip39_1.generateMnemonic)(english_js_1.wordlist, 128); // 128 bits = 12 words
|
|
205
205
|
console.log('');
|
|
206
|
-
console.log('Your new
|
|
206
|
+
console.log('Your new recovery phrase (WRITE THIS DOWN AND KEEP IT SAFE):');
|
|
207
207
|
console.log('');
|
|
208
208
|
console.log(` ${mnemonic}`);
|
|
209
209
|
console.log('');
|
|
@@ -211,9 +211,9 @@ async function runSetup() {
|
|
|
211
211
|
console.log(' Anyone with this phrase can access your data.');
|
|
212
212
|
console.log(' Store it in a password manager or write it down securely.');
|
|
213
213
|
console.log('');
|
|
214
|
-
const confirmed = await ask(rl, 'Have you saved your
|
|
214
|
+
const confirmed = await ask(rl, 'Have you saved your recovery phrase? (yes to continue): ');
|
|
215
215
|
if (confirmed.toLowerCase() !== 'yes' && confirmed.toLowerCase() !== 'y') {
|
|
216
|
-
console.log('\nSetup cancelled. Please save your
|
|
216
|
+
console.log('\nSetup cancelled. Please save your recovery phrase and try again.');
|
|
217
217
|
rl.close();
|
|
218
218
|
process.exit(1);
|
|
219
219
|
}
|
|
@@ -249,7 +249,23 @@ async function runSetup() {
|
|
|
249
249
|
saveCredentials(credentials);
|
|
250
250
|
console.log(`\nCredentials saved to ${CREDENTIALS_PATH}`);
|
|
251
251
|
console.log('(Mnemonic and keys are NOT stored -- only userId, salt, and serverUrl.)');
|
|
252
|
-
// ── Step 6:
|
|
252
|
+
// ── Step 6: Pre-download Embedding Model ────────────────────────────
|
|
253
|
+
console.log('\nDownloading embedding model (one-time, ~600MB)...');
|
|
254
|
+
console.log('This enables local, private semantic search — no API calls needed.\n');
|
|
255
|
+
try {
|
|
256
|
+
const { pipeline } = await import('@huggingface/transformers');
|
|
257
|
+
await pipeline('feature-extraction', 'onnx-community/Qwen3-Embedding-0.6B-ONNX', {
|
|
258
|
+
// @ts-ignore - quantized option exists at runtime but not in type defs
|
|
259
|
+
quantized: true,
|
|
260
|
+
});
|
|
261
|
+
console.log('Embedding model downloaded and cached.');
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
265
|
+
console.warn(`\nWarning: Could not pre-download embedding model: ${message}`);
|
|
266
|
+
console.warn('The model will be downloaded automatically on first use.');
|
|
267
|
+
}
|
|
268
|
+
// ── Step 7: Print Config Snippet ──────────────────────────────────────
|
|
253
269
|
printConfigSnippet(serverUrl);
|
|
254
270
|
console.log('Setup complete! You can now use TotalReclaw with any MCP-compatible AI agent.');
|
|
255
271
|
console.log('');
|
package/dist/cli/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCH,sCAWC;AAMD,gDAGC;AAsED,0CAYC;AAED,0CAIC;AAiCD,
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCH,sCAWC;AAMD,gDAGC;AAsED,0CAYC;AAED,0CAIC;AAiCD,4BAwHC;AAtSD,wDAA0C;AAC1C,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAE9B,wCAAsF;AACtF,kEAA6D;AAC7D,mDAA6C;AAC7C,mDAA+C;AAE/C,8EAA8E;AAC9E,2CAA2C;AAC3C,8EAA8E;AAE9E,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAEhD,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AACzD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;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AC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,CAAC,IAAI,CAAC,sDAAsD,OAAO,EAAE,CAAC,CAAC;YAC9E,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;QAC3E,CAAC;QAED,yEAAyE;QAEzE,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAE9B,OAAO,CAAC,GAAG,CAAC,+EAA+E,CAAC,CAAC;QAC7F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,6DAA6D;AAC7D,MAAM,WAAW,GACf,OAAO,OAAO,KAAK,WAAW;IAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACf,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;AAE1C,IAAI,WAAW,EAAE,CAAC;IAChB,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
9
9
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
10
10
|
const client_1 = require("@totalreclaw/client");
|
|
11
11
|
const index_js_2 = require("./tools/index.js");
|
|
12
|
+
const status_js_1 = require("./tools/status.js");
|
|
12
13
|
const remember_js_1 = require("./tools/remember.js");
|
|
13
14
|
const consolidation_js_1 = require("./consolidation.js");
|
|
14
15
|
const prompts_js_1 = require("./prompts.js");
|
|
@@ -30,15 +31,65 @@ const account_abstraction_1 = require("viem/account-abstraction");
|
|
|
30
31
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
31
32
|
// ── Configuration ───────────────────────────────────────────────────────────
|
|
32
33
|
const SERVER_URL = process.env.TOTALRECLAW_SERVER_URL || 'http://127.0.0.1:8080';
|
|
33
|
-
const MASTER_PASSWORD = process.env.
|
|
34
|
+
const MASTER_PASSWORD = process.env.TOTALRECLAW_RECOVERY_PHRASE;
|
|
34
35
|
// Store-time near-duplicate detection (consolidation module)
|
|
35
36
|
const STORE_DEDUP_ENABLED = process.env.TOTALRECLAW_STORE_DEDUP !== 'false';
|
|
37
|
+
const BILLING_CACHE_TTL = 2 * 60 * 60 * 1000; // 2 hours
|
|
38
|
+
let billingCache = null;
|
|
39
|
+
/** Whether a background billing fetch is already in progress. */
|
|
40
|
+
let billingFetchInProgress = false;
|
|
41
|
+
/**
|
|
42
|
+
* Proactively fetch billing status to populate the candidate pool cache.
|
|
43
|
+
* Fire-and-forget — does not block the caller.
|
|
44
|
+
*/
|
|
45
|
+
function proactiveBillingFetch(state) {
|
|
46
|
+
if (billingFetchInProgress)
|
|
47
|
+
return;
|
|
48
|
+
billingFetchInProgress = true;
|
|
49
|
+
const authKeyHex = Buffer.from(state.authKey).toString('hex');
|
|
50
|
+
const url = `${state.serverUrl.replace(/\/+$/, '')}/v1/billing/status?wallet_address=${encodeURIComponent(state.smartAccountAddress)}`;
|
|
51
|
+
fetch(url, {
|
|
52
|
+
method: 'GET',
|
|
53
|
+
headers: {
|
|
54
|
+
'Authorization': `Bearer ${authKeyHex}`,
|
|
55
|
+
'X-TotalReclaw-Client': 'mcp-server',
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
.then(async (resp) => {
|
|
59
|
+
if (resp.ok) {
|
|
60
|
+
const raw = (await resp.json());
|
|
61
|
+
const features = raw.features;
|
|
62
|
+
billingCache = {
|
|
63
|
+
max_candidate_pool: features?.max_candidate_pool,
|
|
64
|
+
checked_at: Date.now(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
.catch(() => { })
|
|
69
|
+
.finally(() => { billingFetchInProgress = false; });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the server-configured max candidate pool size.
|
|
73
|
+
* Falls back to a local formula if no cached billing response.
|
|
74
|
+
*/
|
|
75
|
+
function getMaxCandidatePool(k) {
|
|
76
|
+
if (billingCache && Date.now() - billingCache.checked_at < BILLING_CACHE_TTL) {
|
|
77
|
+
if (billingCache.max_candidate_pool != null)
|
|
78
|
+
return billingCache.max_candidate_pool;
|
|
79
|
+
}
|
|
80
|
+
// Trigger a background fetch if we have subgraph state but no cache
|
|
81
|
+
if (!billingCache && subgraphState) {
|
|
82
|
+
proactiveBillingFetch(subgraphState);
|
|
83
|
+
}
|
|
84
|
+
// Fallback to local formula
|
|
85
|
+
return Math.max(k * 50, 400);
|
|
86
|
+
}
|
|
36
87
|
let subgraphState = null;
|
|
37
88
|
/**
|
|
38
89
|
* Detect server mode based on environment configuration.
|
|
39
90
|
*
|
|
40
91
|
* Managed service (subgraph) mode is the default when a valid BIP-39 mnemonic
|
|
41
|
-
* is provided as
|
|
92
|
+
* is provided as TOTALRECLAW_RECOVERY_PHRASE.
|
|
42
93
|
*
|
|
43
94
|
* Self-hosted mode (HTTP) requires TOTALRECLAW_SELF_HOSTED=true.
|
|
44
95
|
* Defaults to managed service otherwise.
|
|
@@ -65,12 +116,12 @@ async function initSubgraphState() {
|
|
|
65
116
|
const { authKey, encryptionKey, dedupKey, salt } = (0, crypto_js_1.deriveKeys)(mnemonic);
|
|
66
117
|
// Derive LSH seed and create hasher
|
|
67
118
|
const lshSeed = (0, crypto_js_1.deriveLshSeed)(mnemonic, salt);
|
|
68
|
-
const dims = (0, embedding_js_1.getEmbeddingDims)(); //
|
|
119
|
+
const dims = (0, embedding_js_1.getEmbeddingDims)(); // 1024 for Qwen3-Embedding-0.6B
|
|
69
120
|
const lshHasher = new lsh_js_1.LSHHasher(lshSeed, dims);
|
|
70
121
|
// Derive Smart Account address via relay bundler proxy (same chain view as Pimlico).
|
|
71
122
|
// This does an eth_call to the EntryPoint to compute the counterfactual CREATE2 address.
|
|
72
123
|
const chainId = parseInt(process.env.TOTALRECLAW_CHAIN_ID || '100');
|
|
73
|
-
const chain = chainId === 100 ? chains_1.gnosis : chains_1.gnosisChiado;
|
|
124
|
+
const chain = chainId === 100 ? chains_1.gnosis : chainId === 84532 ? chains_1.baseSepolia : chains_1.gnosisChiado;
|
|
74
125
|
const bundlerRpcUrl = `${SERVER_URL}/v1/bundler`;
|
|
75
126
|
const ownerAccount = (0, accounts_1.mnemonicToAccount)(mnemonic);
|
|
76
127
|
const entryPointAddr = (process.env.TOTALRECLAW_ENTRYPOINT_ADDRESS || account_abstraction_1.entryPoint07Address);
|
|
@@ -228,7 +279,11 @@ async function handleRememberSubgraph(state, args) {
|
|
|
228
279
|
const results = [];
|
|
229
280
|
let dedupSkipped = 0;
|
|
230
281
|
let dedupSuperseded = 0;
|
|
282
|
+
// Collect protobuf payloads for batch submission (tombstones + facts)
|
|
283
|
+
const pendingPayloads = [];
|
|
284
|
+
const pendingFactMeta = [];
|
|
231
285
|
for (const item of textsToStore) {
|
|
286
|
+
let itemSuperseded = false; // Per-fact flag for action tracking
|
|
232
287
|
try {
|
|
233
288
|
// 1. Generate blind indices (word-based)
|
|
234
289
|
const wordIndices = (0, crypto_js_1.generateBlindIndices)(item.text);
|
|
@@ -272,34 +327,23 @@ async function handleRememberSubgraph(state, args) {
|
|
|
272
327
|
const dupMatch = (0, consolidation_js_1.findNearDuplicate)(embedding, decryptedCandidates, (0, consolidation_js_1.getStoreDedupThreshold)());
|
|
273
328
|
if (dupMatch) {
|
|
274
329
|
if (isExplicitRemember) {
|
|
275
|
-
// Explicit remember: always supersede —
|
|
330
|
+
// Explicit remember: always supersede — queue tombstone for old fact
|
|
276
331
|
effectiveImportance = Math.max(item.importance, dupMatch.existingFact.importance);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const tombConfig = (0, store_js_1.getSubgraphConfig)({
|
|
291
|
-
relayUrl: state.serverUrl,
|
|
292
|
-
mnemonic: state.mnemonic,
|
|
293
|
-
authKeyHex: Buffer.from(state.authKey).toString('hex'),
|
|
294
|
-
walletAddress: state.smartAccountAddress,
|
|
295
|
-
});
|
|
296
|
-
await (0, store_js_1.submitFactOnChain)(tombProtobuf, tombConfig);
|
|
297
|
-
console.error(`Store-time dedup: superseded ${dupMatch.existingFact.id} (sim=${dupMatch.similarity.toFixed(3)})`);
|
|
298
|
-
}
|
|
299
|
-
catch {
|
|
300
|
-
console.error(`Store-time dedup: failed to tombstone superseded fact ${dupMatch.existingFact.id}`);
|
|
301
|
-
}
|
|
332
|
+
const tombstonePayload = {
|
|
333
|
+
id: dupMatch.existingFact.id,
|
|
334
|
+
timestamp: new Date().toISOString(),
|
|
335
|
+
owner: state.smartAccountAddress,
|
|
336
|
+
encryptedBlob: Buffer.from('tombstone').toString('hex'),
|
|
337
|
+
blindIndices: [],
|
|
338
|
+
decayScore: 0,
|
|
339
|
+
source: 'mcp_dedup',
|
|
340
|
+
contentFp: '',
|
|
341
|
+
agentId: 'mcp-server',
|
|
342
|
+
};
|
|
343
|
+
pendingPayloads.push((0, store_js_1.encodeFactProtobuf)(tombstonePayload));
|
|
344
|
+
console.error(`Store-time dedup: queued supersede for ${dupMatch.existingFact.id} (sim=${dupMatch.similarity.toFixed(3)})`);
|
|
302
345
|
dedupSuperseded++;
|
|
346
|
+
itemSuperseded = true;
|
|
303
347
|
}
|
|
304
348
|
else {
|
|
305
349
|
// Batch mode: apply shouldSupersede logic
|
|
@@ -312,32 +356,21 @@ async function handleRememberSubgraph(state, args) {
|
|
|
312
356
|
}
|
|
313
357
|
// action === 'supersede'
|
|
314
358
|
effectiveImportance = Math.max(item.importance, dupMatch.existingFact.importance);
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const tombConfig = (0, store_js_1.getSubgraphConfig)({
|
|
329
|
-
relayUrl: state.serverUrl,
|
|
330
|
-
mnemonic: state.mnemonic,
|
|
331
|
-
authKeyHex: Buffer.from(state.authKey).toString('hex'),
|
|
332
|
-
walletAddress: state.smartAccountAddress,
|
|
333
|
-
});
|
|
334
|
-
await (0, store_js_1.submitFactOnChain)(tombProtobuf, tombConfig);
|
|
335
|
-
console.error(`Store-time dedup: superseded ${dupMatch.existingFact.id} (sim=${dupMatch.similarity.toFixed(3)})`);
|
|
336
|
-
}
|
|
337
|
-
catch {
|
|
338
|
-
console.error(`Store-time dedup: failed to tombstone superseded fact ${dupMatch.existingFact.id}`);
|
|
339
|
-
}
|
|
359
|
+
const tombstonePayload = {
|
|
360
|
+
id: dupMatch.existingFact.id,
|
|
361
|
+
timestamp: new Date().toISOString(),
|
|
362
|
+
owner: state.smartAccountAddress,
|
|
363
|
+
encryptedBlob: Buffer.from('tombstone').toString('hex'),
|
|
364
|
+
blindIndices: [],
|
|
365
|
+
decayScore: 0,
|
|
366
|
+
source: 'mcp_dedup',
|
|
367
|
+
contentFp: '',
|
|
368
|
+
agentId: 'mcp-server',
|
|
369
|
+
};
|
|
370
|
+
pendingPayloads.push((0, store_js_1.encodeFactProtobuf)(tombstonePayload));
|
|
371
|
+
console.error(`Store-time dedup: queued supersede for ${dupMatch.existingFact.id} (sim=${dupMatch.similarity.toFixed(3)})`);
|
|
340
372
|
dedupSuperseded++;
|
|
373
|
+
itemSuperseded = true;
|
|
341
374
|
}
|
|
342
375
|
}
|
|
343
376
|
}
|
|
@@ -367,21 +400,43 @@ async function handleRememberSubgraph(state, args) {
|
|
|
367
400
|
agentId: 'mcp-server',
|
|
368
401
|
encryptedEmbedding: encryptedEmb,
|
|
369
402
|
};
|
|
370
|
-
// 8. Encode as protobuf and
|
|
403
|
+
// 8. Encode as protobuf and queue for batch submission
|
|
371
404
|
const protobuf = (0, store_js_1.encodeFactProtobuf)(factPayload);
|
|
372
|
-
|
|
405
|
+
pendingPayloads.push(protobuf);
|
|
406
|
+
pendingFactMeta.push({ factId, action: itemSuperseded ? 'superseded' : 'created' });
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
410
|
+
results.push({ success: false, fact_id: '', tx_hash: undefined });
|
|
411
|
+
console.error(`Failed to prepare fact for on-chain storage: ${message}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Batch-submit all payloads (tombstones + facts) in a single UserOp
|
|
415
|
+
if (pendingPayloads.length > 0) {
|
|
416
|
+
try {
|
|
417
|
+
const batchConfig = (0, store_js_1.getSubgraphConfig)({
|
|
373
418
|
relayUrl: state.serverUrl,
|
|
374
419
|
mnemonic: state.mnemonic,
|
|
375
420
|
authKeyHex: Buffer.from(state.authKey).toString('hex'),
|
|
376
421
|
walletAddress: state.smartAccountAddress,
|
|
377
422
|
});
|
|
378
|
-
const
|
|
379
|
-
|
|
423
|
+
const batchResult = await (0, store_js_1.submitFactBatchOnChain)(pendingPayloads, batchConfig);
|
|
424
|
+
for (const meta of pendingFactMeta) {
|
|
425
|
+
results.push({
|
|
426
|
+
success: batchResult.success,
|
|
427
|
+
fact_id: meta.factId,
|
|
428
|
+
tx_hash: batchResult.txHash,
|
|
429
|
+
action: meta.action,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
console.error(`Batch submitted ${batchResult.batchSize} payloads in 1 UserOp (tx=${batchResult.txHash.slice(0, 10)}...)`);
|
|
380
433
|
}
|
|
381
434
|
catch (error) {
|
|
382
435
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
383
|
-
|
|
384
|
-
|
|
436
|
+
for (const meta of pendingFactMeta) {
|
|
437
|
+
results.push({ success: false, fact_id: meta.factId, tx_hash: undefined });
|
|
438
|
+
}
|
|
439
|
+
console.error(`Batch submission failed: ${message}`);
|
|
385
440
|
}
|
|
386
441
|
}
|
|
387
442
|
const created = results.filter(r => r.success && r.action !== 'skipped_dedup').length;
|
|
@@ -434,7 +489,7 @@ async function handleRecallSubgraph(state, args) {
|
|
|
434
489
|
// 3. Combine trapdoors
|
|
435
490
|
const allTrapdoors = [...wordTrapdoors, ...lshTrapdoors];
|
|
436
491
|
// 4. Search the subgraph
|
|
437
|
-
const maxCandidates =
|
|
492
|
+
const maxCandidates = getMaxCandidatePool(k);
|
|
438
493
|
const candidates = await (0, search_js_1.searchSubgraph)(state.smartAccountAddress, allTrapdoors, maxCandidates, state.serverUrl, Buffer.from(state.authKey).toString('hex'));
|
|
439
494
|
if (candidates.length === 0) {
|
|
440
495
|
return {
|
|
@@ -673,7 +728,22 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
673
728
|
const authKeyHex = subgraphState
|
|
674
729
|
? Buffer.from(subgraphState.authKey).toString('hex')
|
|
675
730
|
: '';
|
|
676
|
-
|
|
731
|
+
const statusResult = await (0, index_js_2.handleStatus)(SERVER_URL, authKeyHex, args);
|
|
732
|
+
// Cache billing features for candidate pool sizing.
|
|
733
|
+
// handleStatus stores the raw response; extract max_candidate_pool from it.
|
|
734
|
+
try {
|
|
735
|
+
const raw = (0, status_js_1.getLastBillingResponse)();
|
|
736
|
+
if (raw?.features) {
|
|
737
|
+
billingCache = {
|
|
738
|
+
max_candidate_pool: raw.features.max_candidate_pool,
|
|
739
|
+
checked_at: Date.now(),
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
catch {
|
|
744
|
+
// Best-effort cache — don't fail the status call
|
|
745
|
+
}
|
|
746
|
+
return statusResult;
|
|
677
747
|
}
|
|
678
748
|
if (name === 'totalreclaw_upgrade') {
|
|
679
749
|
const authKeyHex = subgraphState
|