@cachly-dev/mcp-server 0.10.13 โ†’ 0.10.15

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 (44) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +50 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
  4. package/.github/workflows/publish.yml +72 -0
  5. package/CHANGELOG.md +28 -0
  6. package/LAUNCH_TEXTS.md +182 -0
  7. package/LICENSE +202 -0
  8. package/README.md +106 -53
  9. package/dist/__tests__/auth.test.d.ts +1 -0
  10. package/dist/__tests__/auth.test.js +107 -0
  11. package/dist/__tests__/auth.test.js.map +1 -0
  12. package/dist/handlers/brain.js +7 -67
  13. package/dist/handlers/brain.js.map +1 -1
  14. package/dist/handlers/fedbrain.js +93 -44
  15. package/dist/handlers/fedbrain.js.map +1 -1
  16. package/dist/handlers/roadmap.js +8 -2
  17. package/dist/handlers/roadmap.js.map +1 -1
  18. package/dist/handlers/syndicate.js +15 -7
  19. package/dist/handlers/syndicate.js.map +1 -1
  20. package/dist/handlers/team.js +62 -50
  21. package/dist/handlers/team.js.map +1 -1
  22. package/dist/index.js +555 -93
  23. package/dist/index.js.map +1 -1
  24. package/dist/tools.d.ts +3 -54
  25. package/dist/tools.js +8 -62
  26. package/dist/tools.js.map +1 -1
  27. package/glama.json +29 -0
  28. package/llms.txt +155 -0
  29. package/package.json +29 -13
  30. package/scripts/postinstall.js +12 -12
  31. package/server.json +3 -9
  32. package/smithery.yaml +6 -8
  33. package/src/__tests__/auth.test.ts +147 -0
  34. package/src/handlers/brain.ts +7 -64
  35. package/src/handlers/fedbrain.ts +88 -38
  36. package/src/handlers/roadmap.ts +7 -2
  37. package/src/handlers/syndicate.ts +13 -7
  38. package/src/handlers/team.ts +57 -33
  39. package/src/index.ts +599 -106
  40. package/src/tools.ts +8 -66
  41. package/dist/__tests__/brain-predict-failures.test.d.ts +0 -17
  42. package/dist/__tests__/brain-predict-failures.test.js +0 -339
  43. package/dist/__tests__/brain-predict-failures.test.js.map +0 -1
  44. package/src/__tests__/brain-predict-failures.test.ts +0 -430
package/README.md CHANGED
@@ -1,21 +1,15 @@
1
1
  # ๐Ÿง  cachly AI Brain โ€” MCP Server
2
2
 
3
- > **Your AI forgot that 3-hour fix. Again. This permanently fixes that.**
4
- > Persistent memory for Claude Code, Cursor, GitHub Copilot, Windsurf, Cline & Zed.
5
-
6
- <p align="center">
7
- <a href="https://cachly.dev">
8
- <img src="https://img.shields.io/badge/โ–ถ_Interactive_Demo-cachly.dev-7c3aed?style=for-the-badge" alt="Interactive Demo" />
9
- </a>
10
- </p>
3
+ > **Persistent memory for Claude Code, Cursor, GitHub Copilot, Windsurf, Cline & Zed.**
4
+ > Your AI remembers every lesson, every fix, every architecture decision โ€” forever.
11
5
 
12
6
  <p align="center">
13
7
  <a href="https://www.npmjs.com/package/@cachly-dev/mcp-server">
14
- <img src="https://img.shields.io/npm/v/@cachly-dev/mcp-server?color=red&logo=npm" alt="npm version" />
8
+ <img src="https://img.shields.io/npm/v/@cachly-dev/mcp-server?color=violet&logo=npm" alt="npm version" />
15
9
  </a>
16
10
  &nbsp;
17
11
  <a href="https://www.npmjs.com/package/@cachly-dev/mcp-server">
18
- <img src="https://img.shields.io/npm/dt/@cachly-dev/mcp-server?color=blue&label=total%20installs" alt="total installs" />
12
+ <img src="https://img.shields.io/npm/dw/@cachly-dev/mcp-server?color=blue&label=weekly%20installs" alt="npm downloads" />
19
13
  </a>
20
14
  &nbsp;
21
15
  <a href="https://cachly.dev">
@@ -23,28 +17,73 @@
23
17
  </a>
24
18
  &nbsp;
25
19
  <a href="https://cachly.dev/legal">
26
- <img src="https://img.shields.io/badge/GDPR-EU%20only-green" alt="GDPR: EU only" />
20
+ <img src="https://img.shields.io/badge/GDPR-EU%20servers-green" alt="GDPR: EU servers" />
27
21
  </a>
28
22
  &nbsp;
23
+ <img src="https://img.shields.io/badge/89%20MCP%20tools-violet" alt="89 MCP tools" />
24
+ &nbsp;
29
25
  <img src="https://img.shields.io/badge/License-Apache--2.0-yellow" alt="License: Apache-2.0" />
30
26
  </p>
31
27
 
32
28
  ---
33
29
 
30
+ ## Try it right now โ€” no account needed
31
+
32
+ ```bash
33
+ npx @cachly-dev/mcp-server@latest demo
34
+ ```
35
+
36
+ Run this in any project directory. It reads your git history and shows exactly what your AI would know:
37
+
38
+ ```
39
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
40
+ โ”‚ ๐Ÿง  Brain Preview โ€” What your AI would know โ”‚
41
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
42
+ โ”‚ Commits analysed : 847 Date range: 2024-01-12 โ†’ 2026-05-14 โ”‚
43
+ โ”‚ Lessons extracted: 634 Contributors: 7 โ”‚
44
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
45
+ โ”‚ Category breakdown: โ”‚
46
+ โ”‚ ๐Ÿ”ง fix โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 312 โ”‚
47
+ โ”‚ โœจ feat โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 189 โ”‚
48
+ โ”‚ ๐Ÿ”’ security โ–ˆโ–ˆ 18 โ”‚
49
+ โ”‚ ๐Ÿš€ deploy โ–ˆโ–ˆ 15 โ”‚
50
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
51
+ โ”‚ ๐Ÿ”’ Security fixes your AI would know: โ”‚
52
+ โ”‚ โ€ข fix(auth): JWT expiry check before signature validation โ”‚
53
+ โ”‚ โ€ข security: sanitize webhook payload before JSON.parse โ”‚
54
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
55
+ โ”‚ ๐Ÿ”ง Bug fixes your AI would remember: โ”‚
56
+ โ”‚ โ€ข fix: Redis pub/sub race condition under high concurrency โ”‚
57
+ โ”‚ โ€ข fix: k8s readinessProbe threshold too low for cold start โ”‚
58
+ โ”‚ โ€ข fix: Stripe idempotency_key missing on retry path โ”‚
59
+ โ”‚ โ€ข fix: tRPC context not forwarded to background jobs โ”‚
60
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
61
+ โ”‚ ๐Ÿ’ก With cachly, your AI arrives pre-briefed every session. โ”‚
62
+ โ”‚ No more re-explaining. No more repeated mistakes. โ”‚
63
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
64
+
65
+ Make this permanent (free, 30 seconds):
66
+ $ npx @cachly-dev/mcp-server@latest setup
67
+
68
+ Works with: Claude Code ยท Cursor ยท Windsurf ยท Copilot ยท Cline ยท Zed
69
+ Free forever ยท GDPR ยท German servers ยท No credit card
70
+ ```
71
+
72
+ ---
73
+
34
74
  ## The Problem
35
75
 
36
76
  Every morning, you open your AI coding assistant. It doesn't remember yesterday.
37
77
  You explain your architecture. You explain the deployment process. You explain the bug you fixed last week.
38
78
 
39
- **The average developer wastes 45 minutes/day re-establishing context.**
40
- That's ~$18,000/year per developer โ€” before you even count the re-discovered bugs.
79
+ **The average developer wastes 45 minutes/day re-establishing context.**
41
80
 
42
81
  ---
43
82
 
44
83
  ## One Command. Fully Automatic.
45
84
 
46
85
  ```bash
47
- npx @cachly-dev/init
86
+ npx @cachly-dev/mcp-server@latest setup
48
87
  ```
49
88
 
50
89
  Run it once. It handles everything:
@@ -53,7 +92,8 @@ Run it once. It handles everything:
53
92
  2. **Detects your editors** โ€” Claude Code, Cursor, Windsurf, VS Code, Copilot, Cline & Zed
54
93
  3. **Writes the MCP config** for every detected editor automatically
55
94
  4. **Creates `CLAUDE.md`** with Brain rules so your AI acts autonomously
56
- 5. **Installs a git hook** that learns from every commit automatically
95
+ 5. **Reads your git history** โ€” extracts lessons from years of commits before your first session
96
+ 6. **Installs a git hook** โ€” learns from every future commit automatically
57
97
 
58
98
  **Restart your editor.** From now on your AI arrives pre-briefed โ€” every session.
59
99
 
@@ -61,8 +101,6 @@ Run it once. It handles everything:
61
101
 
62
102
  ## What happens after setup โ€” everything is automatic
63
103
 
64
- You never type another command. The Brain runs entirely in the background:
65
-
66
104
  | Trigger | What the Brain does automatically |
67
105
  |---------|----------------------------------|
68
106
  | First tool call | Session starts, project gets indexed in background |
@@ -87,31 +125,42 @@ You never type another command. The Brain runs entirely in the background:
87
125
 
88
126
  ---
89
127
 
128
+ ## CLI Commands
129
+
130
+ ```bash
131
+ npx @cachly-dev/mcp-server@latest demo # Preview your Brain (no account needed)
132
+ npx @cachly-dev/mcp-server@latest setup # Wire up all your AI editors (30 seconds)
133
+ npx @cachly-dev/mcp-server@latest health # Check token, API, editors, git hook
134
+ npx @cachly-dev/mcp-server@latest digest # Weekly Brain summary โ€” shareable
135
+ npx @cachly-dev/mcp-server@latest share # Generate a shareable stats card + tweet
136
+ npx @cachly-dev/mcp-server@latest invite # Invite a teammate to share your Brain
137
+ ```
138
+
139
+ ---
140
+
90
141
  ## What makes cachly different
91
142
 
92
143
  | Feature | What it does |
93
144
  |---------|-------------|
94
145
  | **`causal_trace`** | Root Cause Analysis through memory: problem โ†’ chain โ†’ solution. **No other system does this.** |
146
+ | **`brain_from_git`** | Reads your entire git history and loads every lesson before your first session. Incremental on repeat runs. |
147
+ | **`brain_predict`** | Predicts failures before they happen based on past incident patterns |
95
148
  | **`memory_consolidate`** | Weekly garbage collector โ€” detects contradictions, merges duplicates, expires stale lessons |
96
- | **`brain_predict`** | Predicts failures before they happen based on past patterns |
97
149
  | **Team Brain** | Shared lessons across your whole team with author attribution |
98
150
  | **Ambient Git** | git hook auto-extracts lessons from every commit. Zero extra calls. |
99
151
  | **Memory Crystals** | Distills all lessons into a compact snapshot for instant session briefing |
100
152
  | **11 languages** | BM25+ search in EN, DE, FR, ES, IT, PT, ZH, JA, KO, AR, HE โ€” no config |
101
153
 
102
- **The `causal_trace` moment:**
154
+ **`causal_trace` in action:**
103
155
  ```
104
156
  causal_trace(problem="auth breaks after restart")
105
157
 
106
158
  โ†’ Root: k8s:namespace-terminating
107
- โ†’ Via: keycloak:jwks-race
159
+ โ†’ Via: keycloak:jwks-race
108
160
  โ†’ Fix: PollUntilContextTimeout 3min โ† used this March 12, worked
109
161
  ```
110
162
  *30 minutes of git blame in one call.*
111
163
 
112
- **The `autopilot` command:**
113
- Run `autopilot` once and it generates a fully self-managing `CLAUDE.md` or `copilot-instructions.md` โ€” tailored to your actual Brain content. Every AI (Claude, Cursor, Copilot, Windsurf, Gemini) gets the full ruleset for your project. No copy-paste, no manual writing. As the Brain learns more, re-run `autopilot` to upgrade the file.
114
-
115
164
  ---
116
165
 
117
166
  ## cachly vs. alternatives
@@ -142,10 +191,10 @@ Run `autopilot` once and it generates a fully self-managing `CLAUDE.md` or `copi
142
191
  | **`learn_from_attempts`** | Store structured lessons after any fix, deploy, or discovery |
143
192
  | **`recall_best_solution`** | Best known solution for a topic โ€” with success/failure history |
144
193
  | **`remember_context`** | Cache architecture findings, decisions, file summaries |
145
- | **`recall_context`** | Get exact context by key (supports glob) |
146
194
  | **`smart_recall`** | BM25+ full-text search across all brain data โ€” 11 languages |
147
195
  | **`causal_trace`** | Root cause analysis through memory |
148
196
  | **`brain_predict`** | Predict likely failures before they happen |
197
+ | **`brain_from_git`** | Bootstrap from git history โ€” incremental, only new commits each run |
149
198
  | **`memory_consolidate`** | Deduplicate and expire stale lessons |
150
199
  | **`compact_recover`** | Full context recovery after hitting context window limit |
151
200
 
@@ -158,26 +207,22 @@ Run `autopilot` once and it generates a fully self-managing `CLAUDE.md` or `copi
158
207
  | `madc_deliberate` | 6 specialist AI agents vote to resolve contradictory lessons |
159
208
  | `memory_crystalize` | Distill all lessons into a Crystal for instant team context |
160
209
  | `brain_doctor` | Health check: lesson count, IQ boost %, open failures |
161
- | `autopilot` | Generate a self-managing `CLAUDE.md` / `copilot-instructions.md` from Brain content |
210
+ | `autopilot` | Generate a self-managing `CLAUDE.md` from Brain content |
162
211
  | `global_learn` / `global_recall` | Cross-project universal lessons |
163
- | `publish_lesson` / `import_public_brain` | Share/import community knowledge |
164
212
 
165
- ### ๐ŸŒ Knowledge Commons (Global)
213
+ ### ๐ŸŒ Knowledge Commons
166
214
 
167
215
  | Tool | What it does |
168
216
  |------|-------------|
169
217
  | `syndicate` | Contribute verified lesson to global Knowledge Commons |
170
- | `syndicate_search` | Search community solutions by tech stack |
171
- | `fedbrain_contribute` | Contribute with cryptographic provenance certificate |
172
218
  | `fedbrain_search` | Context-weighted global search |
173
219
 
174
- ### โš™๏ธ Cache & Infrastructure
220
+ ### โš™๏ธ Infrastructure
175
221
 
176
222
  | Tool | What it does |
177
223
  |------|-------------|
178
224
  | `list_instances` / `create_instance` / `delete_instance` | Manage Brain instances |
179
225
  | `cache_get` / `cache_set` / `cache_delete` | Standard cache operations |
180
- | `cache_mget` / `cache_mset` | Bulk pipeline (single round-trip) |
181
226
  | `semantic_search` | Find cached entries by meaning |
182
227
  | `index_project` | Index source files for semantic retrieval |
183
228
 
@@ -195,33 +240,27 @@ Run `autopilot` once and it generates a fully self-managing `CLAUDE.md` or `copi
195
240
  **Does my AI need to call `session_start` manually?**
196
241
  No. Sessions start and end automatically on the first tool call and when the editor closes.
197
242
 
198
- **What happens to memory if I switch projects?**
199
- Memory is scoped per Brain instance. You can have one instance per project, or one shared instance across projects.
243
+ **What is incremental `brain_from_git`?**
244
+ After the first run, only new commits since the last scan are processed. Repeated calls are instant.
200
245
 
201
246
  **Can my whole team share the same Brain?**
202
- Yes. `team_learn` / `team_recall` share lessons with author attribution. `memory_crystalize` gives any new team member instant full context.
247
+ Yes. Use `team_learn` / `team_recall` or run `npx @cachly-dev/mcp-server@latest invite teammate@example.com`.
203
248
 
204
249
  **What is a Memory Crystal?**
205
- A compressed snapshot of all lessons distilled into a compact briefing. Injected at every session start so the AI arrives pre-briefed even with a cold context window.
250
+ A compressed snapshot of all lessons injected at every session start. The AI arrives pre-briefed even with a cold context window.
206
251
 
207
- **What is causal_trace and why is it unique?**
208
- Given any error or problem, `causal_trace` walks the Causal Knowledge Graph (CKG) to find: the root cause, intermediate causes, and the exact fix that worked โ€” including the date and commands used. No other memory system builds or queries a causal graph.
209
-
210
- **How does cachly learn from git commits?**
211
- The `setup` wizard installs a git post-commit hook. After each commit, the hook calls `cls_ingest` with the commit message and changed files. The Brain extracts lessons automatically โ€” no `session_end` required.
212
-
213
- **What happens if I hit the context window limit mid-session?**
214
- Call `compact_recover`. It reconstructs full context from the Memory Crystal + recent sessions + WIP registry entries โ€” typically restoring full context in one tool call.
252
+ **What is `causal_trace` and why is it unique?**
253
+ Given any error, `causal_trace` walks the Causal Knowledge Graph to find: root cause, intermediate causes, and the exact fix that worked โ€” including the date and commands used. No other memory system builds or queries a causal graph.
215
254
 
216
255
  **Is my code sent to cachly servers?**
217
- No code content is stored. cachly stores: lesson text, commit messages, session summaries, and key-value context entries. All data is on German servers, GDPR-compliant.
256
+ No code content is stored. cachly stores: lesson text, commit messages, session summaries, key-value context entries. All data on German servers, GDPR-compliant.
218
257
 
219
- **Does cachly work without an internet connection?**
220
- No โ€” cachly is a managed cloud service. The MCP server is a thin client; the Brain runs on cachly's infrastructure.
258
+ **What if I hit the context window limit mid-session?**
259
+ Call `compact_recover`. It reconstructs full context from Memory Crystal + recent sessions + WIP registry โ€” typically one tool call.
221
260
 
222
261
  ---
223
262
 
224
- ## Manual Setup (alternative to the wizard)
263
+ ## Manual Setup
225
264
 
226
265
  <details>
227
266
  <summary><b>Claude Code</b> (<code>~/.claude/mcp.json</code> or <code>.mcp.json</code>)</summary>
@@ -240,7 +279,7 @@ On the first tool call your AI will prompt you to sign in โ€” takes 10 seconds.
240
279
  </details>
241
280
 
242
281
  <details>
243
- <summary><b>Cursor / Windsurf / VS Code / Copilot / Cline</b> (<code>.cursor/mcp.json</code> / <code>.mcp.json</code>)</summary>
282
+ <summary><b>Cursor / Windsurf / VS Code / Copilot / Cline</b></summary>
244
283
 
245
284
  ```json
246
285
  {
@@ -255,6 +294,23 @@ On the first tool call your AI will prompt you to sign in โ€” takes 10 seconds.
255
294
  ```
256
295
  </details>
257
296
 
297
+ <details>
298
+ <summary><b>Zed</b> (<code>.zed/settings.json</code>)</summary>
299
+
300
+ ```json
301
+ {
302
+ "context_servers": {
303
+ "cachly": {
304
+ "command": {
305
+ "path": "npx",
306
+ "args": ["-y", "@cachly-dev/mcp-server@latest"]
307
+ }
308
+ }
309
+ }
310
+ }
311
+ ```
312
+ </details>
313
+
258
314
  ---
259
315
 
260
316
  ## Pricing
@@ -273,12 +329,10 @@ On the first tool call your AI will prompt you to sign in โ€” takes 10 seconds.
273
329
 
274
330
  ## Environment Variables
275
331
 
276
- Set automatically by the setup wizard โ€” only needed for manual configuration.
277
-
278
332
  | Variable | Default | Description |
279
333
  |----------|---------|-------------|
280
- | `CACHLY_JWT` | โ€” | API token (set by wizard, or get from cachly.dev) |
281
- | `CACHLY_BRAIN_INSTANCE_ID` | โ€” | Default instance UUID (optional if passed per-call) |
334
+ | `CACHLY_JWT` | โ€” | API token (set by wizard automatically) |
335
+ | `CACHLY_BRAIN_INSTANCE_ID` | โ€” | Default instance UUID (optional โ€” auto-resolved) |
282
336
  | `CACHLY_API_URL` | `https://api.cachly.dev` | Override for self-hosted |
283
337
  | `CACHLY_NO_TELEMETRY` | unset | Set to `1` to disable anonymous usage pings |
284
338
 
@@ -290,7 +344,6 @@ Set automatically by the setup wizard โ€” only needed for manual configuration.
290
344
  |---------|-------------|
291
345
  | **[`@cachly-dev/mcp-server`](https://www.npmjs.com/package/@cachly-dev/mcp-server)** | โ† you are here |
292
346
  | **[`@cachly-dev/openclaw`](https://www.npmjs.com/package/@cachly-dev/openclaw)** | Cut LLM costs 60โ€“90% in JS/TS apps |
293
- | **[`@cachly-dev/cli`](https://www.npmjs.com/package/@cachly-dev/cli)** | Terminal CLI โ€” manage instances and brain |
294
347
 
295
348
  ---
296
349
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,107 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
+ import { jwtExpiryMs, checkJwt, handleApiError } from '../auth.js';
4
+ function makeJwt(payload) {
5
+ const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
6
+ const body = Buffer.from(JSON.stringify(payload)).toString('base64url');
7
+ return `${header}.${body}.fakesig`;
8
+ }
9
+ const nowSec = () => Math.floor(Date.now() / 1000);
10
+ describe('jwtExpiryMs', () => {
11
+ it('returns null for an empty string', () => {
12
+ expect(jwtExpiryMs('')).toBeNull();
13
+ });
14
+ it('returns null for a plain (non-JWT) string', () => {
15
+ expect(jwtExpiryMs('not-a-token')).toBeNull();
16
+ });
17
+ it('returns null when the JWT has only two parts', () => {
18
+ expect(jwtExpiryMs('header.payload')).toBeNull();
19
+ });
20
+ it('returns null when the JWT has four parts', () => {
21
+ expect(jwtExpiryMs('a.b.c.d')).toBeNull();
22
+ });
23
+ it('returns null when the payload base64 is invalid', () => {
24
+ expect(jwtExpiryMs('header.!!!.sig')).toBeNull();
25
+ });
26
+ it('returns null when the payload has no exp field', () => {
27
+ expect(jwtExpiryMs(makeJwt({ sub: 'user-123', iat: nowSec() }))).toBeNull();
28
+ });
29
+ it('returns null when exp is 0', () => {
30
+ expect(jwtExpiryMs(makeJwt({ exp: 0 }))).toBeNull();
31
+ });
32
+ it('converts exp (seconds) to milliseconds', () => {
33
+ const expSec = nowSec() + 3600;
34
+ expect(jwtExpiryMs(makeJwt({ exp: expSec }))).toBe(expSec * 1000);
35
+ });
36
+ it('returns a past timestamp for an expired token', () => {
37
+ expect(jwtExpiryMs(makeJwt({ exp: nowSec() - 300 }))).toBeLessThan(Date.now());
38
+ });
39
+ it('returns a future timestamp for a valid token', () => {
40
+ expect(jwtExpiryMs(makeJwt({ exp: nowSec() + 86400 }))).toBeGreaterThan(Date.now());
41
+ });
42
+ it('handles a token expiring in less than 60 minutes', () => {
43
+ const expSec = nowSec() + 30 * 60;
44
+ const result = jwtExpiryMs(makeJwt({ exp: expSec }));
45
+ const minsLeft = Math.floor((result - Date.now()) / 60_000);
46
+ expect(minsLeft).toBeGreaterThanOrEqual(29);
47
+ expect(minsLeft).toBeLessThanOrEqual(30);
48
+ });
49
+ it('ignores extra claims', () => {
50
+ const expSec = nowSec() + 3600;
51
+ expect(jwtExpiryMs(makeJwt({ sub: 'u', iat: nowSec(), exp: expSec, plan: 'free' }))).toBe(expSec * 1000);
52
+ });
53
+ it('handles padding-free base64url payloads', () => {
54
+ // base64url (no =) โ€” Buffer.from handles this natively
55
+ const expSec = nowSec() + 7200;
56
+ expect(jwtExpiryMs(makeJwt({ exp: expSec, x: 'a' }))).toBe(expSec * 1000);
57
+ });
58
+ });
59
+ describe('checkJwt', () => {
60
+ it('throws InvalidRequest when jwt is empty', () => {
61
+ expect(() => checkJwt('')).toThrowError(expect.objectContaining({ code: ErrorCode.InvalidRequest, message: expect.stringContaining('CACHLY_JWT env var not set') }));
62
+ });
63
+ it('throws with setup URL when jwt is missing', () => {
64
+ expect(() => checkJwt('')).toThrowError(expect.objectContaining({ message: expect.stringContaining('cachly.dev/setup-ai') }));
65
+ });
66
+ it('throws InvalidRequest with expiry timestamp for an expired token', () => {
67
+ const expSec = nowSec() - 60;
68
+ const token = makeJwt({ exp: expSec });
69
+ expect(() => checkJwt(token)).toThrowError(expect.objectContaining({
70
+ code: ErrorCode.InvalidRequest,
71
+ message: expect.stringContaining('expired at'),
72
+ }));
73
+ });
74
+ it('does not throw for a valid non-expired token', () => {
75
+ expect(() => checkJwt(makeJwt({ exp: nowSec() + 3600 }))).not.toThrow();
76
+ });
77
+ it('does not throw for a token with no exp claim', () => {
78
+ expect(() => checkJwt(makeJwt({ sub: 'user' }))).not.toThrow();
79
+ });
80
+ });
81
+ describe('handleApiError', () => {
82
+ it('throws InvalidRequest for 401 with the detail message', () => {
83
+ expect(() => handleApiError(401, 'token expired')).toThrowError(expect.objectContaining({
84
+ code: ErrorCode.InvalidRequest,
85
+ message: expect.stringContaining('Authentication failed (401): token expired'),
86
+ }));
87
+ });
88
+ it('throws InvalidRequest for 403 with the detail message', () => {
89
+ expect(() => handleApiError(403, 'plan limit reached')).toThrowError(expect.objectContaining({
90
+ code: ErrorCode.InvalidRequest,
91
+ message: expect.stringContaining('Access denied (403): plan limit reached'),
92
+ }));
93
+ });
94
+ it('throws InternalError for other status codes', () => {
95
+ expect(() => handleApiError(500, 'server crash')).toThrowError(expect.objectContaining({
96
+ code: ErrorCode.InternalError,
97
+ message: expect.stringContaining('cachly API error 500: server crash'),
98
+ }));
99
+ });
100
+ it('includes the cachly.dev/setup-ai link for 401 errors', () => {
101
+ expect(() => handleApiError(401, 'Unauthorized')).toThrowError(expect.objectContaining({ message: expect.stringContaining('cachly.dev/setup-ai') }));
102
+ });
103
+ it('includes account access hint for 403 errors', () => {
104
+ expect(() => handleApiError(403, 'Forbidden')).toThrowError(expect.objectContaining({ message: expect.stringContaining('access to this resource') }));
105
+ });
106
+ });
107
+ //# sourceMappingURL=auth.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.test.js","sourceRoot":"","sources":["../../src/__tests__/auth.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAY,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEnE,SAAS,OAAO,CAAC,OAAgC;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC1E,OAAO,GAAG,MAAM,IAAI,IAAI,UAAU,CAAC;AACrC,CAAC;AAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAEnD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,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AAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAC5D,MAAM,CAAC,gBAAgB,CAAC;YACtB,IAAI,EAAE,SAAS,CAAC,aAAa;YAC7B,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,oCAAoC,CAAC;SACvE,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAC5D,MAAM,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC,CACrF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,YAAY,CACzD,MAAM,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,EAAE,CAAC,CACzF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -5,13 +5,15 @@ import { safeJsonParse } from '../utils.js';
5
5
  import { keywordSearch, tokenize, splitMultiQuery, levenshtein, indexVocab as _indexVocab } from '../search.js';
6
6
  import { computeEmbedding, hasEmbedProvider } from '../embeddings.js';
7
7
  // โ”€โ”€ Changelog (shown once per version in session_start) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
8
- const MCP_VERSION = '0.10.10';
8
+ const MCP_VERSION = '0.10.0';
9
9
  const WHATS_NEW = {
10
- '0.10.10': [
10
+ '0.10.0': [
11
11
  `๐Ÿ†• **What's new in v${MCP_VERSION}:**`,
12
- ` ๐Ÿ“Œ **pin_lesson / unpin_lesson** โ€” Pin critical lessons to always show in session_start`,
13
- ` ๐Ÿ“Š **brain_stats** โ€” At-a-glance health dashboard (lessons, streak, roadmap, pinned, top topics)`,
14
- ` โœ… Pinned lessons appear at top of every session briefing โ€” never decay, never forgotten`,
12
+ ` โœ… Zero-friction setup โ€” auto-provisions your Brain, no manual config needed`,
13
+ ` โœ… 10ร— faster briefings โ€” batch Redis fetches replace per-key loops`,
14
+ ` โœ… Crash-proof data reads โ€” corrupted cache entries no longer break tools`,
15
+ ` โœ… \`session_end\` warns when called without an active session`,
16
+ ` โœ… \`get_api_status\` now shows live Redis ping + all instance statuses`,
15
17
  ],
16
18
  };
17
19
  export const BRAIN_TOOL_NAMES = new Set([
@@ -270,20 +272,6 @@ export async function handleBrainTool(name, args, getConnection, apiFetch) {
270
272
  }
271
273
  }
272
274
  catch { /* CKG updates are non-critical */ }
273
- // โ”€โ”€ Auto-pin critical lessons โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
274
- // severity=critical โ†’ always pin automatically so the lesson
275
- // appears in every session_start without the user ever calling pin_lesson.
276
- let autoPinNote = '';
277
- if (severity === 'critical' && (outcome === 'success' || outcome === 'partial')) {
278
- try {
279
- const alreadyPinned = await redis.exists(`cachly:lesson:pin:${topic}`);
280
- if (!alreadyPinned) {
281
- await redis.set(`cachly:lesson:pin:${topic}`, '1');
282
- autoPinNote = `๐Ÿ“Œ Auto-pinned (critical severity) โ€” will appear in every session_start.`;
283
- }
284
- }
285
- catch { /* non-critical */ }
286
- }
287
275
  const emoji = outcome === 'success' ? 'โœ…' : outcome === 'partial' ? 'โš ๏ธ' : 'โŒ';
288
276
  const sevEmoji = severity === 'critical' ? '๐Ÿ”ด' : severity === 'major' ? '๐ŸŸก' : '๐ŸŸข';
289
277
  const action = isUpdate ? 'updated' : 'stored';
@@ -304,7 +292,6 @@ export async function handleBrainTool(name, args, getConnection, apiFetch) {
304
292
  depends_on.length > 0
305
293
  ? `๐Ÿ”— Depends on: ${depends_on.map(d => `\`${d}\``).join(', ')} โ†’ trace with \`trace_dependency\``
306
294
  : '',
307
- autoPinNote,
308
295
  ...templateWarnings,
309
296
  ...iWasWrongWarning,
310
297
  ].filter(l => l !== '').join('\n');
@@ -831,37 +818,6 @@ export async function handleBrainTool(name, args, getConnection, apiFetch) {
831
818
  }
832
819
  lines.push('');
833
820
  }
834
- // โ”€โ”€ Pinned lessons โ€” always shown regardless of age/confidence โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
835
- try {
836
- const pinKeys = [];
837
- const pinStream = redis.scanStream({ match: 'cachly:lesson:pin:*', count: 100 });
838
- await new Promise((res, rej) => {
839
- pinStream.on('data', (b) => pinKeys.push(...b));
840
- pinStream.on('end', res);
841
- pinStream.on('error', rej);
842
- });
843
- if (pinKeys.length > 0) {
844
- const pinnedTopics = pinKeys.map(k => k.replace('cachly:lesson:pin:', ''));
845
- const pinLessonRaws = await redis.mget(...pinnedTopics.map(t => `cachly:lesson:best:${t}`));
846
- const pinLines = [];
847
- for (const raw of pinLessonRaws) {
848
- if (!raw)
849
- continue;
850
- const l = safeJsonParse(raw, null);
851
- if (!l)
852
- continue;
853
- const emoji = l.outcome === 'success' ? 'โœ…' : l.outcome === 'partial' ? 'โš ๏ธ' : 'โŒ';
854
- const sev = l.severity === 'critical' ? '๐Ÿ”ด' : l.severity === 'major' ? '๐ŸŸก' : '';
855
- pinLines.push(` ๐Ÿ“Œ${emoji}${sev} \`${l.topic}\` โ€” ${l.what_worked.slice(0, 100)}`);
856
- }
857
- if (pinLines.length > 0) {
858
- lines.push(`๐Ÿ“Œ **Pinned lessons (always shown):**`);
859
- lines.push(...pinLines);
860
- lines.push('');
861
- }
862
- }
863
- }
864
- catch { /* non-critical */ }
865
821
  // Recent lessons
866
822
  if (lessons.length > 0) {
867
823
  lines.push(`๐Ÿ• **Recent lessons:**`);
@@ -1328,21 +1284,6 @@ export async function handleBrainTool(name, args, getConnection, apiFetch) {
1328
1284
  catch { /* git not available or not a repo โ€” silent skip */ }
1329
1285
  }
1330
1286
  const durationStr = durationMin !== undefined ? ` ยท ${durationMin} min` : '';
1331
- // โ”€โ”€ Mini brain-stats snapshot at session end โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1332
- let miniStatsLines = [];
1333
- try {
1334
- const totalLessons = await redis.keys('cachly:lesson:best:*').then(k => k.length).catch(() => 0);
1335
- const pinCount = await redis.keys('cachly:lesson:pin:*').then(k => k.length).catch(() => 0);
1336
- const streakRaw = await redis.get('cachly:streak:current');
1337
- const streak = streakRaw ? JSON.parse(streakRaw).days : 0;
1338
- const parts = [`๐Ÿ“š ${totalLessons} lesson${totalLessons !== 1 ? 's' : ''} total`];
1339
- if (pinCount > 0)
1340
- parts.push(`๐Ÿ“Œ ${pinCount} pinned`);
1341
- if (streak > 1)
1342
- parts.push(`๐Ÿ”ฅ ${streak}-day streak`);
1343
- miniStatsLines = [`๐Ÿง  **Brain:** ${parts.join(' ยท ')}`];
1344
- }
1345
- catch { /* non-critical */ }
1346
1287
  return [
1347
1288
  `โœ… **Session saved**${durationStr}`,
1348
1289
  ``,
@@ -1351,7 +1292,6 @@ export async function handleBrainTool(name, args, getConnection, apiFetch) {
1351
1292
  lessons_learned !== undefined ? `๐Ÿง  **Lessons stored:** ${lessons_learned}` : '',
1352
1293
  autoLearned.length > 0 ? `๐Ÿค– **Auto-learned:** ${autoLearned.length} lessons extracted from summary (${autoLearned.slice(0, 3).map(t => `\`${t}\``).join(', ')}${autoLearned.length > 3 ? 'โ€ฆ' : ''})` : '',
1353
1294
  ambientLearned.length > 0 ? `๐ŸŒฟ **Ambient git learning:** ${ambientLearned.length} commit${ambientLearned.length > 1 ? 's' : ''} auto-learned (${ambientLearned.slice(0, 3).map(t => `\`${t}\``).join(', ')}${ambientLearned.length > 3 ? 'โ€ฆ' : ''})` : '',
1354
- ...miniStatsLines,
1355
1295
  ``,
1356
1296
  `๐Ÿ’ก Next session: \`session_start(focus="...")\` to see this summary.`,
1357
1297
  ].filter(l => l !== '').join('\n');