memoryai-mcp 2.2.0 → 2.3.1
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 +362 -304
- package/dist/claude-setup.d.ts +19 -0
- package/dist/claude-setup.js +216 -0
- package/dist/index.js +342 -77
- package/dist/kiro-setup.d.ts +11 -2
- package/dist/kiro-setup.js +143 -60
- package/package.json +46 -45
package/dist/kiro-setup.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* memoryai-kiro-setup
|
|
4
|
-
* Zero-dependency setup script that creates
|
|
5
|
-
*
|
|
4
|
+
* Zero-dependency setup script that creates, in the current project:
|
|
5
|
+
* - .kiro/settings/mcp.json (MCP server wiring)
|
|
6
|
+
* - .kiro/steering/memoryai.md (always-on instructions, soft fallback)
|
|
7
|
+
* - .kiro/hooks/memoryai-auto-recall.kiro.hook (promptSubmit → bootstrap/recall)
|
|
8
|
+
* - .kiro/hooks/memoryai-auto-capture.kiro.hook (agentStop → store/compact)
|
|
9
|
+
*
|
|
10
|
+
* The two hooks are what make memory TRULY automatic: they fire on IDE events
|
|
11
|
+
* (every prompt / end of every turn) instead of relying on the agent to
|
|
12
|
+
* remember the steering instructions. Result: the user installs once and never
|
|
13
|
+
* has to think about memory again — recall happens before answers, persistence
|
|
14
|
+
* happens after turns, compaction happens when context fills.
|
|
6
15
|
*/
|
|
7
16
|
export {};
|
package/dist/kiro-setup.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* memoryai-kiro-setup
|
|
4
|
-
* Zero-dependency setup script that creates
|
|
5
|
-
*
|
|
4
|
+
* Zero-dependency setup script that creates, in the current project:
|
|
5
|
+
* - .kiro/settings/mcp.json (MCP server wiring)
|
|
6
|
+
* - .kiro/steering/memoryai.md (always-on instructions, soft fallback)
|
|
7
|
+
* - .kiro/hooks/memoryai-auto-recall.kiro.hook (promptSubmit → bootstrap/recall)
|
|
8
|
+
* - .kiro/hooks/memoryai-auto-capture.kiro.hook (agentStop → store/compact)
|
|
9
|
+
*
|
|
10
|
+
* The two hooks are what make memory TRULY automatic: they fire on IDE events
|
|
11
|
+
* (every prompt / end of every turn) instead of relying on the agent to
|
|
12
|
+
* remember the steering instructions. Result: the user installs once and never
|
|
13
|
+
* has to think about memory again — recall happens before answers, persistence
|
|
14
|
+
* happens after turns, compaction happens when context fills.
|
|
6
15
|
*/
|
|
7
16
|
import { createInterface } from "node:readline";
|
|
8
17
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
18
|
+
import { join, dirname } from "node:path";
|
|
10
19
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
11
20
|
function ask(question, fallback) {
|
|
12
21
|
const suffix = fallback ? ` [${fallback}]` : "";
|
|
@@ -21,12 +30,42 @@ function writeIfMissing(filePath, content, label) {
|
|
|
21
30
|
console.log(` skip ${label} (already exists)`);
|
|
22
31
|
return false;
|
|
23
32
|
}
|
|
24
|
-
const dir =
|
|
33
|
+
const dir = dirname(filePath);
|
|
25
34
|
mkdirSync(dir, { recursive: true });
|
|
26
35
|
writeFileSync(filePath, content, "utf-8");
|
|
27
36
|
console.log(` create ${label}`);
|
|
28
37
|
return true;
|
|
29
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Auto-provision a fresh API key from the public self-service endpoint so the
|
|
41
|
+
* user does nothing — no curl, no dashboard. Returns the key, or null on
|
|
42
|
+
* failure (caller falls back to asking). Public + IP-rate-limited server-side.
|
|
43
|
+
*/
|
|
44
|
+
async function provisionKey(endpoint, name) {
|
|
45
|
+
const base = endpoint.replace(/\/+$/, "");
|
|
46
|
+
try {
|
|
47
|
+
const resp = await fetch(`${base}/v1/admin/provision`, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { "Content-Type": "application/json" },
|
|
50
|
+
body: JSON.stringify({ name: name || "kiro", tos_accepted: true }),
|
|
51
|
+
});
|
|
52
|
+
if (!resp.ok) {
|
|
53
|
+
const txt = await resp.text().catch(() => "");
|
|
54
|
+
console.error(` warn auto-provision failed (HTTP ${resp.status}). ${txt.slice(0, 200)}`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const data = (await resp.json());
|
|
58
|
+
if (data?.api_key) {
|
|
59
|
+
console.log(` ok provisioned new API key (${String(data.api_key).slice(0, 10)}…, plan=${data.plan || "?"})`);
|
|
60
|
+
return data.api_key;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(` warn auto-provision request error: ${e instanceof Error ? e.message : String(e)}`);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
30
69
|
const MCP_CONFIG = (apiKey, endpoint) => JSON.stringify({
|
|
31
70
|
mcpServers: {
|
|
32
71
|
memoryai: {
|
|
@@ -36,76 +75,120 @@ const MCP_CONFIG = (apiKey, endpoint) => JSON.stringify({
|
|
|
36
75
|
HM_API_KEY: apiKey,
|
|
37
76
|
HM_ENDPOINT: endpoint,
|
|
38
77
|
},
|
|
78
|
+
// Auto-approve the everyday memory tools so the hooks can run them
|
|
79
|
+
// without prompting the user — this is what makes memory truly
|
|
80
|
+
// hands-off. These are all low-risk (read + append-only store +
|
|
81
|
+
// context bookkeeping); no destructive operations are listed.
|
|
82
|
+
autoApprove: [
|
|
83
|
+
"memory_bootstrap",
|
|
84
|
+
"memory_recall",
|
|
85
|
+
"memory_store",
|
|
86
|
+
"memory_recover",
|
|
87
|
+
"context_guard_check",
|
|
88
|
+
"context_guard_compact",
|
|
89
|
+
"ide_turn_check",
|
|
90
|
+
"memory_pitfall_check",
|
|
91
|
+
],
|
|
39
92
|
},
|
|
40
93
|
},
|
|
41
94
|
}, null, 2) + "\n";
|
|
42
|
-
const STEERING = `---
|
|
43
|
-
inclusion: always
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
# MemoryAI — Persistent Memory
|
|
47
|
-
|
|
48
|
-
You have
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
## Session End
|
|
78
|
-
|
|
79
|
-
When wrapping up or when the agent is about to stop:
|
|
80
|
-
1. Call \`memory_compact\` to consolidate the session's context into durable memories
|
|
81
|
-
2. Call \`memory_store\` with a brief summary of what was accomplished
|
|
82
|
-
|
|
83
|
-
## Rules
|
|
84
|
-
|
|
85
|
-
- Recall only when past context is actually needed — not on every message
|
|
86
|
-
- Store important outcomes after completing tasks, not after every interaction
|
|
87
|
-
- Present memories naturally — integrate recalled info into responses, don't show raw API output
|
|
88
|
-
- Use \`zone: "critical"\` for decisions that must never be forgotten
|
|
89
|
-
- Use \`retention: "forever"\` for permanent project knowledge
|
|
95
|
+
const STEERING = `---
|
|
96
|
+
inclusion: always
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
# MemoryAI — Persistent Memory (mostly automatic)
|
|
100
|
+
|
|
101
|
+
You have MemoryAI tools via MCP. Two Agent Hooks automate the common path:
|
|
102
|
+
- **Auto-Recall** (on every prompt) loads memory before you answer.
|
|
103
|
+
- **Auto-Capture** (end of every turn) stores important memory and compacts when full.
|
|
104
|
+
|
|
105
|
+
So you normally do NOT need to manage memory by hand. This file is a fallback
|
|
106
|
+
for cases the hooks don't cover, plus the rules for HOW to use memory well.
|
|
107
|
+
|
|
108
|
+
## What the hooks already handle
|
|
109
|
+
- Session-start \`memory_bootstrap\`, per-prompt \`memory_recall\`.
|
|
110
|
+
- Post-turn \`memory_store\` for decisions/preferences/facts/pitfalls/procedures.
|
|
111
|
+
- \`context_guard_check\` → \`context_guard_compact\` when context fills.
|
|
112
|
+
|
|
113
|
+
Don't duplicate these on your own unless a hook clearly didn't run.
|
|
114
|
+
|
|
115
|
+
## Memory types
|
|
116
|
+
- \`decision\` — architectural/technical decisions (DNA-protected, never decays)
|
|
117
|
+
- \`preference\` — user preferences and conventions (DNA-protected)
|
|
118
|
+
- \`fact\` — codebase facts, API details, configs
|
|
119
|
+
- \`pitfall\` — a mistake + its lesson (DNA-protected)
|
|
120
|
+
- \`procedure\` — a reusable workflow (DNA-protected)
|
|
121
|
+
- \`error\` / \`goal\` — lessons and current objectives
|
|
122
|
+
|
|
123
|
+
## Rules
|
|
124
|
+
- Recall only when past context is actually needed — not on every trivial message.
|
|
125
|
+
- Store important outcomes, not every interaction. Dedup is automatic.
|
|
126
|
+
- Integrate recalled info naturally; never show raw tool output.
|
|
127
|
+
- Never store secrets, credentials, tokens, or full API keys.
|
|
128
|
+
- Use \`zone: "critical"\` for things that must never be forgotten.
|
|
129
|
+
- Use \`retention: "forever"\` for permanent project knowledge.
|
|
90
130
|
`;
|
|
131
|
+
// ── Agent Hooks — event-level automation (the real "zero-action" layer) ──
|
|
132
|
+
// These fire on IDE events so memory works even if the agent ignores steering.
|
|
133
|
+
const HOOK_AUTO_RECALL = JSON.stringify({
|
|
134
|
+
enabled: true,
|
|
135
|
+
name: "MemoryAI Auto-Recall",
|
|
136
|
+
description: "Before answering each user message, automatically load relevant memory so the agent always has prior context — zero user action.",
|
|
137
|
+
version: "1",
|
|
138
|
+
when: { type: "promptSubmit" },
|
|
139
|
+
then: {
|
|
140
|
+
type: "askAgent",
|
|
141
|
+
prompt: "Before responding, ensure you have the relevant long-term memory (do this silently, integrate naturally, never show raw tool output):\n\n" +
|
|
142
|
+
"1. If this is the first turn of the session, call memory_bootstrap once to load preferences, decisions, and recent project context.\n" +
|
|
143
|
+
"2. If the user's message references past work, decisions, preferences, or anything that might be stored (\"what did we\", \"last time\", \"our approach\", \"why did we\", or a question about the project), call memory_recall with a focused query first, then answer using what you find.\n" +
|
|
144
|
+
"3. If the message is trivial small-talk, skip recall.\n\n" +
|
|
145
|
+
"Use recalled memory to inform the answer; do not announce that a memory system exists unless asked.",
|
|
146
|
+
},
|
|
147
|
+
}, null, 2) + "\n";
|
|
148
|
+
const HOOK_AUTO_CAPTURE = JSON.stringify({
|
|
149
|
+
enabled: true,
|
|
150
|
+
name: "MemoryAI Auto-Capture",
|
|
151
|
+
description: "Fully automatic: persist memorable events to MemoryAI after every turn, and persist session state silently when pressure thresholds hit. No user action ever required — the IDE host handles window eviction on its own and the auto-recall hook rehydrates context afterwards.",
|
|
152
|
+
version: "5",
|
|
153
|
+
when: { type: "agentStop" },
|
|
154
|
+
then: {
|
|
155
|
+
type: "askAgent",
|
|
156
|
+
prompt: "Run two background tasks SILENTLY. Do not tell the user about either task, do not change your normal reply, do not suggest /compact or 'open a new conversation' — those are not user actions in this design.\n\n" +
|
|
157
|
+
"1. PERSIST: If the turn produced a decision, preference, important project fact, lesson from a mistake (pitfall), or reusable procedure, call memory_store with the correct memory_type. Skip greetings and trivia. Dedup is automatic. Never store secrets.\n\n" +
|
|
158
|
+
"2. RELEASE CHECK: Count the assistant turns in this conversation, then call ide_turn_check with turn_count = (your count) and max_tokens = 200000. Read the response's action_prompt field and follow it VERBATIM. Every action_prompt in this design tells you to act SILENTLY — call context_guard_compact when asked, do nothing when asked. Never message the user from this hook.\n\n" +
|
|
159
|
+
"The design: MemoryAI persists to DB on threshold; the IDE host (Kiro auto-summarize, Claude Code /clear, Cursor /reset) evicts the window on its own schedule; the auto-recall hook on the next user message rehydrates context. From the user's view, nothing ever happens — the chat just keeps working.",
|
|
160
|
+
},
|
|
161
|
+
}, null, 2) + "\n";
|
|
91
162
|
async function main() {
|
|
92
163
|
const cwd = process.cwd();
|
|
93
164
|
console.log(`\nMemoryAI Kiro Setup`);
|
|
94
165
|
console.log(`Project: ${cwd}\n`);
|
|
95
|
-
const
|
|
166
|
+
const endpoint = await ask("Endpoint", process.env.HM_ENDPOINT || "https://memoryai.dev");
|
|
167
|
+
let apiKey = process.env.HM_API_KEY || (await ask("MemoryAI API key (blank = auto-provision a free one)")).trim();
|
|
96
168
|
if (!apiKey) {
|
|
97
|
-
console.
|
|
169
|
+
console.log(" ... no key given — provisioning one for you");
|
|
170
|
+
const provisioned = await provisionKey(endpoint, "kiro");
|
|
171
|
+
if (provisioned)
|
|
172
|
+
apiKey = provisioned;
|
|
173
|
+
}
|
|
174
|
+
if (!apiKey) {
|
|
175
|
+
console.error("Error: could not obtain an API key (auto-provision failed). Set HM_API_KEY and re-run.");
|
|
98
176
|
process.exit(1);
|
|
99
177
|
}
|
|
100
|
-
const endpoint = await ask("Endpoint", process.env.HM_ENDPOINT || "https://memoryai.dev");
|
|
101
178
|
console.log("");
|
|
102
179
|
writeIfMissing(join(cwd, ".kiro", "settings", "mcp.json"), MCP_CONFIG(apiKey, endpoint), ".kiro/settings/mcp.json");
|
|
103
180
|
writeIfMissing(join(cwd, ".kiro", "steering", "memoryai.md"), STEERING, ".kiro/steering/memoryai.md");
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
181
|
+
writeIfMissing(join(cwd, ".kiro", "hooks", "memoryai-auto-recall.kiro.hook"), HOOK_AUTO_RECALL, ".kiro/hooks/memoryai-auto-recall.kiro.hook");
|
|
182
|
+
writeIfMissing(join(cwd, ".kiro", "hooks", "memoryai-auto-capture.kiro.hook"), HOOK_AUTO_CAPTURE, ".kiro/hooks/memoryai-auto-capture.kiro.hook");
|
|
183
|
+
console.log(`
|
|
184
|
+
Done. MemoryAI now runs automatically — you don't have to do anything.
|
|
185
|
+
- Auto-Recall hook loads relevant memory before each answer.
|
|
186
|
+
- Auto-Capture hook stores decisions/preferences and compacts when full.
|
|
187
|
+
|
|
188
|
+
Next steps:
|
|
189
|
+
1. Restart Kiro (loads the MCP server + hooks)
|
|
190
|
+
2. Just work normally. Memory persists across sessions on its own.
|
|
191
|
+
3. Optional check: ask "What do you remember about this project?"
|
|
109
192
|
`);
|
|
110
193
|
rl.close();
|
|
111
194
|
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "memoryai-mcp",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "MCP server for MemoryAI v2.
|
|
5
|
-
"homepage": "https://memoryai.dev",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/memoryai-dev/memoryai"
|
|
9
|
-
},
|
|
10
|
-
"type": "module",
|
|
11
|
-
"main": "dist/index.js",
|
|
12
|
-
"bin": {
|
|
13
|
-
"memoryai-mcp": "dist/index.js",
|
|
14
|
-
"memoryai-kiro-setup": "dist/kiro-setup.js"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "memoryai-mcp",
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "MCP server for MemoryAI v2.3 — One brain. ∞ agents. Forever. Adds Brain Inheritance/Federation (P2.3), L2 Inject endpoint (DNA #2 retina), Protocol v1 spec lookup. Plus the v2.0 base: Brain Export/Import, Public Benchmark, Trust Graph, Cognitive Twin. Plus the v1.5 base: 11 biological behaviors, DNA-protected memories, Multi-Agent Mesh.",
|
|
5
|
+
"homepage": "https://memoryai.dev",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/memoryai-dev/memoryai"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"bin": {
|
|
13
|
+
"memoryai-mcp": "dist/index.js",
|
|
14
|
+
"memoryai-kiro-setup": "dist/kiro-setup.js",
|
|
15
|
+
"memoryai-claude-setup": "dist/claude-setup.js"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"dev": "tsx src/index.ts"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"mcp",
|
|
24
|
+
"memory",
|
|
25
|
+
"ai",
|
|
26
|
+
"llm",
|
|
27
|
+
"context"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.12.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.19.15",
|
|
43
|
+
"tsx": "^4.0.0",
|
|
44
|
+
"typescript": "^5.5.0"
|
|
45
|
+
}
|
|
46
|
+
}
|