@aeriondyseti/vector-memory-mcp 0.4.0 → 0.5.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 +7 -1
- package/package.json +9 -4
- package/scripts/test-runner.ts +66 -0
- package/src/config/index.ts +8 -0
- package/src/http/server.ts +173 -0
- package/src/index.ts +7 -1
- package/src/mcp/tools.ts +25 -7
package/README.md
CHANGED
|
@@ -73,7 +73,13 @@ bun install -g @aeriondyseti/vector-memory-mcp
|
|
|
73
73
|
{
|
|
74
74
|
"mcpServers": {
|
|
75
75
|
"memory": {
|
|
76
|
-
"
|
|
76
|
+
"type": "stdio",
|
|
77
|
+
"command": "bunx",
|
|
78
|
+
"args": [
|
|
79
|
+
"--bun",
|
|
80
|
+
"@aeriondyseti/vector-memory-mcp"
|
|
81
|
+
],
|
|
82
|
+
"env": {}
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriondyseti/vector-memory-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A zero-configuration RAG memory server for MCP clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"start": "bun run src/index.ts",
|
|
27
27
|
"dev": "bun --watch run src/index.ts",
|
|
28
28
|
"typecheck": "bunx tsc --noEmit",
|
|
29
|
-
"test": "bun
|
|
29
|
+
"test": "bun run scripts/test-runner.ts",
|
|
30
|
+
"test:raw": "bun test --preload ./tests/preload.ts",
|
|
30
31
|
"test:quick": "bun test",
|
|
31
32
|
"test:coverage": "bun test --preload ./tests/preload.ts --coverage",
|
|
32
33
|
"test:preload": "bun run tests/preload.ts",
|
|
@@ -36,9 +37,10 @@
|
|
|
36
37
|
"keywords": ["mcp", "memory", "rag", "embeddings", "lancedb"],
|
|
37
38
|
"license": "MIT",
|
|
38
39
|
"dependencies": {
|
|
40
|
+
"@huggingface/transformers": "^3.8.0",
|
|
39
41
|
"@lancedb/lancedb": "^0.22.3",
|
|
40
42
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
41
|
-
"
|
|
43
|
+
"hono": "^4.11.3"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@types/bun": "latest",
|
|
@@ -48,5 +50,8 @@
|
|
|
48
50
|
"onnxruntime-node",
|
|
49
51
|
"protobufjs",
|
|
50
52
|
"sharp"
|
|
51
|
-
]
|
|
53
|
+
],
|
|
54
|
+
"overrides": {
|
|
55
|
+
"onnxruntime-node": "1.23.2"
|
|
56
|
+
}
|
|
52
57
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Test runner wrapper that handles Bun's post-test crash gracefully.
|
|
4
|
+
*
|
|
5
|
+
* Bun crashes during native module cleanup after tests complete successfully.
|
|
6
|
+
* This wrapper captures the output, verifies tests passed, and exits cleanly.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from "bun";
|
|
10
|
+
|
|
11
|
+
const proc = spawn(["bun", "test", "--preload", "./tests/preload.ts"], {
|
|
12
|
+
stdout: "pipe",
|
|
13
|
+
stderr: "pipe",
|
|
14
|
+
env: { ...process.env, FORCE_COLOR: "1" },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
let stdout = "";
|
|
18
|
+
let stderr = "";
|
|
19
|
+
|
|
20
|
+
const decoder = new TextDecoder();
|
|
21
|
+
|
|
22
|
+
// Stream stdout in real-time
|
|
23
|
+
const stdoutReader = proc.stdout.getReader();
|
|
24
|
+
(async () => {
|
|
25
|
+
while (true) {
|
|
26
|
+
const { done, value } = await stdoutReader.read();
|
|
27
|
+
if (done) break;
|
|
28
|
+
const text = decoder.decode(value);
|
|
29
|
+
stdout += text;
|
|
30
|
+
process.stdout.write(text);
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
// Stream stderr in real-time
|
|
35
|
+
const stderrReader = proc.stderr.getReader();
|
|
36
|
+
(async () => {
|
|
37
|
+
while (true) {
|
|
38
|
+
const { done, value } = await stderrReader.read();
|
|
39
|
+
if (done) break;
|
|
40
|
+
const text = decoder.decode(value);
|
|
41
|
+
stderr += text;
|
|
42
|
+
process.stderr.write(text);
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
await proc.exited;
|
|
47
|
+
|
|
48
|
+
// Check if tests actually passed by looking for the summary line
|
|
49
|
+
const output = stdout + stderr;
|
|
50
|
+
const passMatch = output.match(/(\d+) pass/);
|
|
51
|
+
const failMatch = output.match(/(\d+) fail/);
|
|
52
|
+
|
|
53
|
+
const passed = passMatch ? parseInt(passMatch[1], 10) : 0;
|
|
54
|
+
const failed = failMatch ? parseInt(failMatch[1], 10) : 0;
|
|
55
|
+
|
|
56
|
+
// Exit based on test results, not Bun's crash
|
|
57
|
+
if (failed > 0) {
|
|
58
|
+
console.error(`\n❌ ${failed} test(s) failed`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
} else if (passed > 0) {
|
|
61
|
+
console.log(`\n✅ All ${passed} tests passed (ignoring Bun cleanup crash)`);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
} else {
|
|
64
|
+
console.error("\n⚠️ Could not determine test results");
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
package/src/config/index.ts
CHANGED
|
@@ -5,6 +5,9 @@ export interface Config {
|
|
|
5
5
|
dbPath: string;
|
|
6
6
|
embeddingModel: string;
|
|
7
7
|
embeddingDimension: number;
|
|
8
|
+
httpPort: number;
|
|
9
|
+
httpHost: string;
|
|
10
|
+
enableHttp: boolean;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
const DEFAULT_DB_PATH = join(
|
|
@@ -17,12 +20,17 @@ const DEFAULT_DB_PATH = join(
|
|
|
17
20
|
|
|
18
21
|
const DEFAULT_EMBEDDING_MODEL = "Xenova/all-MiniLM-L6-v2";
|
|
19
22
|
const DEFAULT_EMBEDDING_DIMENSION = 384;
|
|
23
|
+
const DEFAULT_HTTP_PORT = 3271;
|
|
24
|
+
const DEFAULT_HTTP_HOST = "127.0.0.1";
|
|
20
25
|
|
|
21
26
|
export function loadConfig(): Config {
|
|
22
27
|
return {
|
|
23
28
|
dbPath: process.env.VECTOR_MEMORY_DB_PATH ?? DEFAULT_DB_PATH,
|
|
24
29
|
embeddingModel: process.env.VECTOR_MEMORY_MODEL ?? DEFAULT_EMBEDDING_MODEL,
|
|
25
30
|
embeddingDimension: DEFAULT_EMBEDDING_DIMENSION,
|
|
31
|
+
httpPort: parseInt(process.env.VECTOR_MEMORY_HTTP_PORT ?? String(DEFAULT_HTTP_PORT), 10),
|
|
32
|
+
httpHost: process.env.VECTOR_MEMORY_HTTP_HOST ?? DEFAULT_HTTP_HOST,
|
|
33
|
+
enableHttp: process.env.VECTOR_MEMORY_ENABLE_HTTP !== "false",
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
36
|
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { cors } from "hono/cors";
|
|
3
|
+
import type { MemoryService } from "../services/memory.service.js";
|
|
4
|
+
import type { Config } from "../config/index.js";
|
|
5
|
+
import { isDeleted } from "../types/memory.js";
|
|
6
|
+
|
|
7
|
+
export interface HttpServerOptions {
|
|
8
|
+
memoryService: MemoryService;
|
|
9
|
+
config: Config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createHttpApp(memoryService: MemoryService): Hono {
|
|
13
|
+
const app = new Hono();
|
|
14
|
+
|
|
15
|
+
// Enable CORS for local development
|
|
16
|
+
app.use("/*", cors());
|
|
17
|
+
|
|
18
|
+
// Health check endpoint
|
|
19
|
+
app.get("/health", (c) => {
|
|
20
|
+
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Context endpoint for Claude Code hooks
|
|
24
|
+
// Returns relevant memories formatted for injection into conversation
|
|
25
|
+
app.post("/context", async (c) => {
|
|
26
|
+
try {
|
|
27
|
+
const body = await c.req.json();
|
|
28
|
+
const query = body.query;
|
|
29
|
+
|
|
30
|
+
if (!query || typeof query !== "string") {
|
|
31
|
+
return c.json({ error: "Missing or invalid 'query' field" }, 400);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const memories = await memoryService.search(query, 5);
|
|
35
|
+
|
|
36
|
+
if (memories.length === 0) {
|
|
37
|
+
return c.json({ context: null });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Format memories for context injection
|
|
41
|
+
const contextLines = memories.map((m, i) => {
|
|
42
|
+
const metadata = m.metadata as Record<string, unknown>;
|
|
43
|
+
const type = metadata.type ? `[${metadata.type}]` : "";
|
|
44
|
+
const date = m.createdAt.toISOString().split("T")[0];
|
|
45
|
+
return `${i + 1}. ${type} (${date}): ${m.content}`;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const context = `<relevant-memories>\n${contextLines.join("\n")}\n</relevant-memories>`;
|
|
49
|
+
|
|
50
|
+
return c.json({ context, count: memories.length });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
53
|
+
return c.json({ error: message }, 500);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Search endpoint (more detailed than /context)
|
|
58
|
+
app.post("/search", async (c) => {
|
|
59
|
+
try {
|
|
60
|
+
const body = await c.req.json();
|
|
61
|
+
const query = body.query;
|
|
62
|
+
const limit = body.limit ?? 10;
|
|
63
|
+
|
|
64
|
+
if (!query || typeof query !== "string") {
|
|
65
|
+
return c.json({ error: "Missing or invalid 'query' field" }, 400);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const memories = await memoryService.search(query, limit);
|
|
69
|
+
|
|
70
|
+
return c.json({
|
|
71
|
+
memories: memories.map((m) => ({
|
|
72
|
+
id: m.id,
|
|
73
|
+
content: m.content,
|
|
74
|
+
metadata: m.metadata,
|
|
75
|
+
createdAt: m.createdAt.toISOString(),
|
|
76
|
+
})),
|
|
77
|
+
count: memories.length,
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
81
|
+
return c.json({ error: message }, 500);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Store endpoint
|
|
86
|
+
app.post("/store", async (c) => {
|
|
87
|
+
try {
|
|
88
|
+
const body = await c.req.json();
|
|
89
|
+
const { content, metadata, embeddingText } = body;
|
|
90
|
+
|
|
91
|
+
if (!content || typeof content !== "string") {
|
|
92
|
+
return c.json({ error: "Missing or invalid 'content' field" }, 400);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const memory = await memoryService.store(
|
|
96
|
+
content,
|
|
97
|
+
metadata ?? {},
|
|
98
|
+
embeddingText
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return c.json({
|
|
102
|
+
id: memory.id,
|
|
103
|
+
createdAt: memory.createdAt.toISOString(),
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
107
|
+
return c.json({ error: message }, 500);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Delete endpoint
|
|
112
|
+
app.delete("/memories/:id", async (c) => {
|
|
113
|
+
try {
|
|
114
|
+
const id = c.req.param("id");
|
|
115
|
+
const deleted = await memoryService.delete(id);
|
|
116
|
+
|
|
117
|
+
if (!deleted) {
|
|
118
|
+
return c.json({ error: "Memory not found" }, 404);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return c.json({ deleted: true });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
124
|
+
return c.json({ error: message }, 500);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Get single memory
|
|
129
|
+
app.get("/memories/:id", async (c) => {
|
|
130
|
+
try {
|
|
131
|
+
const id = c.req.param("id");
|
|
132
|
+
const memory = await memoryService.get(id);
|
|
133
|
+
|
|
134
|
+
if (!memory || isDeleted(memory)) {
|
|
135
|
+
return c.json({ error: "Memory not found" }, 404);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return c.json({
|
|
139
|
+
id: memory.id,
|
|
140
|
+
content: memory.content,
|
|
141
|
+
metadata: memory.metadata,
|
|
142
|
+
createdAt: memory.createdAt.toISOString(),
|
|
143
|
+
updatedAt: memory.updatedAt.toISOString(),
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
147
|
+
return c.json({ error: message }, 500);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return app;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function startHttpServer(
|
|
155
|
+
memoryService: MemoryService,
|
|
156
|
+
config: Config
|
|
157
|
+
): Promise<{ stop: () => void }> {
|
|
158
|
+
const app = createHttpApp(memoryService);
|
|
159
|
+
|
|
160
|
+
const server = Bun.serve({
|
|
161
|
+
port: config.httpPort,
|
|
162
|
+
hostname: config.httpHost,
|
|
163
|
+
fetch: app.fetch,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
console.error(
|
|
167
|
+
`[vector-memory-mcp] HTTP server listening on http://${config.httpHost}:${config.httpPort}`
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
stop: () => server.stop(),
|
|
172
|
+
};
|
|
173
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { MemoryRepository } from "./db/memory.repository.js";
|
|
|
6
6
|
import { EmbeddingsService } from "./services/embeddings.service.js";
|
|
7
7
|
import { MemoryService } from "./services/memory.service.js";
|
|
8
8
|
import { startServer } from "./mcp/server.js";
|
|
9
|
+
import { startHttpServer } from "./http/server.js";
|
|
9
10
|
|
|
10
11
|
async function main(): Promise<void> {
|
|
11
12
|
// Check for warmup command
|
|
@@ -24,7 +25,12 @@ async function main(): Promise<void> {
|
|
|
24
25
|
const embeddings = new EmbeddingsService(config.embeddingModel, config.embeddingDimension);
|
|
25
26
|
const memoryService = new MemoryService(repository, embeddings);
|
|
26
27
|
|
|
27
|
-
// Start
|
|
28
|
+
// Start HTTP server if enabled
|
|
29
|
+
if (config.enableHttp) {
|
|
30
|
+
await startHttpServer(memoryService, config);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Start MCP server (stdio)
|
|
28
34
|
await startServer(memoryService);
|
|
29
35
|
}
|
|
30
36
|
|
package/src/mcp/tools.ts
CHANGED
|
@@ -3,7 +3,13 @@ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
|
3
3
|
export const storeMemoryTool: Tool = {
|
|
4
4
|
name: "store_memory",
|
|
5
5
|
description:
|
|
6
|
-
"Store a new memory
|
|
6
|
+
"Store a new memory for later recall. " +
|
|
7
|
+
"PROACTIVELY store memories when: " +
|
|
8
|
+
"(1) Important decisions are made (technical choices, architecture decisions, tradeoffs); " +
|
|
9
|
+
"(2) Problems are solved (bugs fixed, errors resolved - include the solution); " +
|
|
10
|
+
"(3) User preferences or conventions are established; " +
|
|
11
|
+
"(4) Project-specific patterns or configurations are discussed; " +
|
|
12
|
+
"(5) Key information would be valuable in future sessions. " +
|
|
7
13
|
"IMPORTANT: If the content exceeds 1000 characters, you MUST provide an embedding_text " +
|
|
8
14
|
"parameter with a concise summary (under 1000 characters) that captures the key semantic " +
|
|
9
15
|
"meaning for search purposes. The full content will still be stored and returned in search results.",
|
|
@@ -12,18 +18,21 @@ export const storeMemoryTool: Tool = {
|
|
|
12
18
|
properties: {
|
|
13
19
|
content: {
|
|
14
20
|
type: "string",
|
|
15
|
-
description:
|
|
21
|
+
description:
|
|
22
|
+
"The text content to store. Write in a way that will be useful when retrieved later - " +
|
|
23
|
+
"include context, reasoning, and outcomes, not just bare facts.",
|
|
16
24
|
},
|
|
17
25
|
embedding_text: {
|
|
18
26
|
type: "string",
|
|
19
27
|
description:
|
|
20
28
|
"A concise summary (under 1000 characters) used for generating the search embedding. " +
|
|
21
|
-
"REQUIRED when content exceeds 1000 characters.
|
|
22
|
-
"
|
|
29
|
+
"REQUIRED when content exceeds 1000 characters. Should capture the key topics and terms " +
|
|
30
|
+
"someone might search for to find this memory.",
|
|
23
31
|
},
|
|
24
32
|
metadata: {
|
|
25
33
|
type: "object",
|
|
26
|
-
description:
|
|
34
|
+
description:
|
|
35
|
+
"Optional key-value metadata. Recommended keys: 'project' (project name), 'type' (decision/solution/preference/pattern), 'tags' (array of keywords).",
|
|
27
36
|
additionalProperties: true,
|
|
28
37
|
},
|
|
29
38
|
},
|
|
@@ -50,13 +59,22 @@ export const deleteMemoryTool: Tool = {
|
|
|
50
59
|
export const searchMemoriesTool: Tool = {
|
|
51
60
|
name: "search_memories",
|
|
52
61
|
description:
|
|
53
|
-
"Search for memories using semantic similarity. Returns the most relevant memories for the given query."
|
|
62
|
+
"Search for memories using semantic similarity. Returns the most relevant memories for the given query. " +
|
|
63
|
+
"IMPORTANT: Use this tool PROACTIVELY without being asked when you detect: " +
|
|
64
|
+
"(1) References to past decisions or discussions ('what did we decide', 'as we discussed', 'previously'); " +
|
|
65
|
+
"(2) Questions about prior work ('how did we', 'similar to before', 'like last time'); " +
|
|
66
|
+
"(3) Project continuations or returning to earlier topics; " +
|
|
67
|
+
"(4) Debugging issues that may have been solved before; " +
|
|
68
|
+
"(5) Questions about established patterns, conventions, or preferences. " +
|
|
69
|
+
"When in doubt, search - it's better to check for relevant context than to miss important prior decisions.",
|
|
54
70
|
inputSchema: {
|
|
55
71
|
type: "object",
|
|
56
72
|
properties: {
|
|
57
73
|
query: {
|
|
58
74
|
type: "string",
|
|
59
|
-
description:
|
|
75
|
+
description:
|
|
76
|
+
"The search query to find relevant memories. Use natural language describing what context you need. " +
|
|
77
|
+
"Include relevant keywords, project names, or technical terms for better results.",
|
|
60
78
|
},
|
|
61
79
|
limit: {
|
|
62
80
|
type: "integer",
|