@cachly-dev/mcp-server 0.10.5 → 0.10.6
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/.github/workflows/publish.yml +45 -0
- package/LAUNCH_TEXTS.md +182 -0
- package/LICENSE +202 -0
- package/dist/__tests__/auth.test.d.ts +1 -0
- package/dist/__tests__/auth.test.js +107 -0
- package/dist/__tests__/auth.test.js.map +1 -0
- package/dist/auth.d.ts +3 -0
- package/dist/auth.js +32 -0
- package/dist/auth.js.map +1 -0
- package/dist/handlers/advanced.js +38 -31
- package/dist/handlers/advanced.js.map +1 -1
- package/dist/handlers/brain.js +144 -50
- package/dist/handlers/brain.js.map +1 -1
- package/dist/handlers/fedbrain.js +55 -38
- package/dist/handlers/fedbrain.js.map +1 -1
- package/dist/handlers/roadmap.js +8 -2
- package/dist/handlers/roadmap.js.map +1 -1
- package/dist/handlers/syndicate.js +15 -7
- package/dist/handlers/syndicate.js.map +1 -1
- package/dist/handlers/team.js +62 -50
- package/dist/handlers/team.js.map +1 -1
- package/dist/index.js +222 -217
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts +0 -8
- package/dist/tools.js +5 -15
- package/dist/tools.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/glama.json +29 -0
- package/llms.txt +155 -0
- package/package.json +29 -13
- package/scripts/postinstall.js +12 -19
- package/server.json +3 -9
- package/smithery.yaml +6 -8
- package/src/__tests__/auth.test.ts +147 -0
- package/src/auth.ts +46 -0
- package/src/handlers/advanced.ts +37 -23
- package/src/handlers/brain.ts +141 -47
- package/src/handlers/fedbrain.ts +43 -31
- package/src/handlers/roadmap.ts +7 -2
- package/src/handlers/syndicate.ts +13 -7
- package/src/handlers/team.ts +57 -33
- package/src/index.ts +224 -234
- package/src/tools.ts +5 -16
- package/src/utils.ts +10 -0
- package/dist/__tests__/brain-predict-failures.test.d.ts +0 -17
- package/dist/__tests__/brain-predict-failures.test.js +0 -339
- package/dist/__tests__/brain-predict-failures.test.js.map +0 -1
- package/src/__tests__/brain-predict-failures.test.ts +0 -430
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: '20'
|
|
17
|
+
registry-url: 'https://registry.npmjs.org'
|
|
18
|
+
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: npm install --ignore-scripts
|
|
21
|
+
|
|
22
|
+
- name: Test
|
|
23
|
+
run: npm test
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: npm run build
|
|
27
|
+
|
|
28
|
+
- name: Check if version is already published
|
|
29
|
+
id: version_check
|
|
30
|
+
run: |
|
|
31
|
+
PKG_VERSION=$(node -p "require('./package.json').version")
|
|
32
|
+
echo "version=$PKG_VERSION" >> $GITHUB_OUTPUT
|
|
33
|
+
if npm view "@cachly-dev/mcp-server@$PKG_VERSION" version &>/dev/null; then
|
|
34
|
+
echo "skip=true" >> $GITHUB_OUTPUT
|
|
35
|
+
echo "Version $PKG_VERSION already published — skipping."
|
|
36
|
+
else
|
|
37
|
+
echo "skip=false" >> $GITHUB_OUTPUT
|
|
38
|
+
echo "Version $PKG_VERSION is new — will publish."
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
- name: Publish
|
|
42
|
+
if: steps.version_check.outputs.skip == 'false'
|
|
43
|
+
run: npm publish --access public
|
|
44
|
+
env:
|
|
45
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LAUNCH_TEXTS.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Launch Texts — cachly AI Brain
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Product Hunt
|
|
6
|
+
|
|
7
|
+
### Tagline (60 chars max)
|
|
8
|
+
Persistent memory + causal AI for Claude, Cursor & Copilot
|
|
9
|
+
|
|
10
|
+
### Description (260 chars)
|
|
11
|
+
Your AI forgets everything between sessions. cachly fixes that permanently. One command sets it up: detects your editors, writes all configs, bootstraps lessons from your git history. Free forever. No credentials required.
|
|
12
|
+
|
|
13
|
+
### Full Description
|
|
14
|
+
|
|
15
|
+
**The problem:** Every morning you re-explain your architecture to your AI. Every bug gets re-researched. Every fix gets re-discovered. The average developer wastes 45 minutes/day on this.
|
|
16
|
+
|
|
17
|
+
**The fix:** `npx @cachly-dev/mcp-server@latest setup`
|
|
18
|
+
|
|
19
|
+
One command. It signs you in (one browser click), detects every editor you have (Claude Code, Cursor, Windsurf, VS Code, Copilot, Cline, Zed), writes the correct config for each, bootstraps your Brain from your git history, and installs a git hook that learns from every future commit automatically.
|
|
20
|
+
|
|
21
|
+
**What your AI gets:**
|
|
22
|
+
- A briefing at every session start: last session, open failures, relevant past fixes
|
|
23
|
+
- Causal root cause analysis: `causal_trace("auth breaks after restart")` → Root cause → Chain → Exact fix from 3 months ago with the command that worked
|
|
24
|
+
- Failure prediction before it happens: `brain_predict` reads your history before every deploy
|
|
25
|
+
- A running "time saved" counter — so you can see the ROI
|
|
26
|
+
|
|
27
|
+
**What makes it different from mem0, MemGPT, etc.:**
|
|
28
|
+
The `causal_trace` tool. No other memory system builds a Causal Knowledge Graph. Most systems store facts. cachly stores WHY things broke and HOW they were fixed — with the full chain of cause and effect. 30 minutes of git blame in one call.
|
|
29
|
+
|
|
30
|
+
**Free forever:** 25 MB, German servers, GDPR-compliant, no credit card.
|
|
31
|
+
|
|
32
|
+
### First Comment (post immediately after launch)
|
|
33
|
+
Hey PH! 👋
|
|
34
|
+
|
|
35
|
+
I built cachly after watching my AI re-research the same deployment bug for the third time in a month. It had no memory. I did.
|
|
36
|
+
|
|
37
|
+
The thing I'm most proud of: `causal_trace`. You describe a problem in plain English, and it walks your Brain's Causal Knowledge Graph to find: the root cause, the intermediate failure chain, and the exact fix that worked last time — including the date and the command. Nothing else does this.
|
|
38
|
+
|
|
39
|
+
5000+ developers are already using the npm package. Would love your feedback on what's missing.
|
|
40
|
+
|
|
41
|
+
**Commands to try after setup:**
|
|
42
|
+
- `causal_trace(problem="[your last bug]")` — see if it already knows the answer
|
|
43
|
+
- `brain_predict(context="about to deploy")` — what will go wrong?
|
|
44
|
+
- `brain_doctor` — Brain health check
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Hacker News — Show HN
|
|
49
|
+
|
|
50
|
+
**Title:**
|
|
51
|
+
Show HN: cachly – causal memory for AI coding assistants (MCP server, free)
|
|
52
|
+
|
|
53
|
+
**Text:**
|
|
54
|
+
I built cachly after noticing that my AI re-researched the same bug three times in a month. The context window empties, the memory vanishes.
|
|
55
|
+
|
|
56
|
+
cachly is an MCP server that gives Claude Code, Cursor, Copilot, and Windsurf persistent memory with one command:
|
|
57
|
+
|
|
58
|
+
npx @cachly-dev/mcp-server@latest setup
|
|
59
|
+
|
|
60
|
+
It detects your editors, writes all the MCP configs, bootstraps from your git history, and installs a git hook that learns from every future commit. No credentials needed in any config file — OAuth Device Flow handles auth inline on the first tool call.
|
|
61
|
+
|
|
62
|
+
The part I think is technically interesting: `causal_trace`. Instead of just storing facts like most memory systems, cachly builds a Causal Knowledge Graph — typed edges: `fixes`, `requires`, `co-occurs`, `causes`, `contradicts`. When you describe a problem, it walks the graph to reconstruct the failure chain and surface the exact fix.
|
|
63
|
+
|
|
64
|
+
causal_trace(problem="auth breaks after restart")
|
|
65
|
+
→ Root: k8s:namespace-terminating
|
|
66
|
+
→ Via: keycloak:jwks-race
|
|
67
|
+
→ Fix: PollUntilContextTimeout 3min ← worked March 12
|
|
68
|
+
|
|
69
|
+
Sessions start and end automatically (no manual session_start/session_end). Everything runs in the background.
|
|
70
|
+
|
|
71
|
+
Free tier: 25 MB, German servers, GDPR. Apache-2.0.
|
|
72
|
+
|
|
73
|
+
GitHub: https://github.com/cachly-dev/cachly-mcp
|
|
74
|
+
npm: https://www.npmjs.com/package/@cachly-dev/mcp-server
|
|
75
|
+
|
|
76
|
+
Happy to answer questions about the architecture.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Reddit — r/ClaudeAI
|
|
81
|
+
|
|
82
|
+
**Title:**
|
|
83
|
+
I built persistent memory for Claude Code — no credentials, no config, one command
|
|
84
|
+
|
|
85
|
+
**Text:**
|
|
86
|
+
After the 10th time explaining my project architecture to Claude, I built cachly.
|
|
87
|
+
|
|
88
|
+
**What it does:**
|
|
89
|
+
Run `npx @cachly-dev/mcp-server@latest setup` once. It:
|
|
90
|
+
1. Signs you in with one browser click (no credentials in config)
|
|
91
|
+
2. Detects Claude Code, Cursor, Windsurf, VS Code, Cline — writes all configs automatically
|
|
92
|
+
3. Bootstraps your Brain from your git history right away
|
|
93
|
+
4. Installs a git hook so every future commit feeds the brain automatically
|
|
94
|
+
|
|
95
|
+
From that point, your AI arrives pre-briefed every session. No `session_start` needed — it's automatic.
|
|
96
|
+
|
|
97
|
+
**The feature I'm most excited about:**
|
|
98
|
+
`causal_trace("auth breaks after restart")` — it doesn't just search for similar lessons, it walks a Causal Knowledge Graph to reconstruct the failure chain and return the exact fix you used before, with commands and file paths.
|
|
99
|
+
|
|
100
|
+
**Free forever** — 25 MB, German servers, GDPR, no credit card.
|
|
101
|
+
|
|
102
|
+
GitHub: https://github.com/cachly-dev/cachly-mcp
|
|
103
|
+
|
|
104
|
+
Would love feedback from this community — what memory features would you most want?
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Reddit — r/LocalLLaMA
|
|
109
|
+
|
|
110
|
+
**Title:**
|
|
111
|
+
MCP server that learns from your git history automatically — causal memory for AI coding
|
|
112
|
+
|
|
113
|
+
**Text:**
|
|
114
|
+
Built this for the problem of AI context loss between sessions. Technical highlights:
|
|
115
|
+
|
|
116
|
+
- **Causal Knowledge Graph (CKG):** Typed edges (fixes, requires, co-occurs, causes, contradicts). `causal_trace` walks the graph instead of just doing text similarity.
|
|
117
|
+
- **Continuous Learning Stream:** git post-commit hook + GitHub Actions step. Every commit → lessons extracted automatically. Zero `session_end` calls needed.
|
|
118
|
+
- **brain_predict:** Before deploys, reads your CKG for patterns that match past failures and returns probability-weighted warnings.
|
|
119
|
+
- **Memory Crystals:** Compresses 30-50 sessions into a dense snapshot injected at every session start.
|
|
120
|
+
- **11-language BM25+ search:** EN, DE, FR, ES, IT, PT, ZH, JA, KO, AR, HE — cross-lingual retrieval (e.g. `smart_recall("deploy")` finds デプロイ, 部署, 배포).
|
|
121
|
+
|
|
122
|
+
Works with any MCP host: Claude Code, Cursor, Windsurf, VS Code, Cline, Zed, Continue.dev.
|
|
123
|
+
|
|
124
|
+
Free tier: 25 MB. Apache-2.0. German servers.
|
|
125
|
+
|
|
126
|
+
GitHub: https://github.com/cachly-dev/cachly-mcp
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Twitter/X Thread
|
|
131
|
+
|
|
132
|
+
**Tweet 1:**
|
|
133
|
+
Your AI forgets everything between sessions.
|
|
134
|
+
I built the fix.
|
|
135
|
+
|
|
136
|
+
`npx @cachly-dev/mcp-server@latest setup`
|
|
137
|
+
|
|
138
|
+
One command → persistent AI memory across Claude, Cursor, Copilot, Windsurf.
|
|
139
|
+
Free forever. 🧵
|
|
140
|
+
|
|
141
|
+
**Tweet 2:**
|
|
142
|
+
The part that took the longest to build: `causal_trace`
|
|
143
|
+
|
|
144
|
+
You type: "auth breaks after restart"
|
|
145
|
+
|
|
146
|
+
It returns:
|
|
147
|
+
→ Root: k8s:namespace-terminating
|
|
148
|
+
→ Via: keycloak:jwks-race
|
|
149
|
+
→ Fix: PollUntilContextTimeout 3min ← you used this March 12, it worked
|
|
150
|
+
|
|
151
|
+
30 minutes of git blame. One call.
|
|
152
|
+
|
|
153
|
+
**Tweet 3:**
|
|
154
|
+
How setup works:
|
|
155
|
+
1. Run the command
|
|
156
|
+
2. Browser opens → one click sign-in (no password)
|
|
157
|
+
3. It detects every editor you have
|
|
158
|
+
4. Writes MCP config for each automatically
|
|
159
|
+
5. Bootstraps Brain from your git history
|
|
160
|
+
6. Installs git hook for automatic future learning
|
|
161
|
+
|
|
162
|
+
Restart editor. Done.
|
|
163
|
+
|
|
164
|
+
**Tweet 4:**
|
|
165
|
+
What your AI sees every morning:
|
|
166
|
+
|
|
167
|
+
🧠 Session Briefing
|
|
168
|
+
⏱️ Brain saved you ~4h 30m total
|
|
169
|
+
✅ api:auth — Bearer in header, not cookie
|
|
170
|
+
✅ docker:build — ARG changes bust cache
|
|
171
|
+
⚠️ k8s:deploy — namespace terminating race condition
|
|
172
|
+
|
|
173
|
+
🤝 Your team has 3 new lessons since yesterday
|
|
174
|
+
|
|
175
|
+
**Tweet 5:**
|
|
176
|
+
Free tier: 25 MB, German servers, GDPR-compliant, no credit card.
|
|
177
|
+
Open source: Apache-2.0
|
|
178
|
+
|
|
179
|
+
GitHub: github.com/cachly-dev/cachly-mcp
|
|
180
|
+
npm: @cachly-dev/mcp-server
|
|
181
|
+
|
|
182
|
+
If this saves you time, a ⭐ means a lot.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -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,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,SAAS,CAAC,cAAc;YAC9B,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,yCAAyC,CAAC;SAC5E,CAAC,CACH,CAAC;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"}
|
package/dist/auth.d.ts
ADDED
package/dist/auth.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
export function jwtExpiryMs(token) {
|
|
3
|
+
try {
|
|
4
|
+
const parts = token.split('.');
|
|
5
|
+
if (parts.length !== 3)
|
|
6
|
+
return null;
|
|
7
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf-8'));
|
|
8
|
+
return payload.exp ? payload.exp * 1000 : null;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function checkJwt(jwt) {
|
|
15
|
+
if (!jwt) {
|
|
16
|
+
throw new McpError(ErrorCode.InvalidRequest, 'CACHLY_JWT env var not set.\n\nGet your token at https://cachly.dev/setup-ai and add it to your MCP config:\n CACHLY_JWT=<your-token>');
|
|
17
|
+
}
|
|
18
|
+
const expMs = jwtExpiryMs(jwt);
|
|
19
|
+
if (expMs !== null && expMs < Date.now()) {
|
|
20
|
+
throw new McpError(ErrorCode.InvalidRequest, `CACHLY_JWT expired at ${new Date(expMs).toISOString()}.\n\nGet a fresh token at https://cachly.dev/setup-ai and update CACHLY_JWT in your MCP config.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function handleApiError(status, detail) {
|
|
24
|
+
if (status === 401) {
|
|
25
|
+
throw new McpError(ErrorCode.InvalidRequest, `Authentication failed (401): ${detail}\n\nYour CACHLY_JWT may be expired or invalid. Get a fresh token at https://cachly.dev/setup-ai`);
|
|
26
|
+
}
|
|
27
|
+
if (status === 403) {
|
|
28
|
+
throw new McpError(ErrorCode.InvalidRequest, `Access denied (403): ${detail}\n\nCheck that your CACHLY_JWT belongs to an account with access to this resource.`);
|
|
29
|
+
}
|
|
30
|
+
throw new McpError(ErrorCode.InternalError, `cachly API error ${status}: ${detail}`);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,UAAU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