ac-framework 1.8.0 → 1.9.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/bin/postinstall.js +13 -0
- package/package.json +4 -2
- package/src/commands/init.js +101 -1
- package/src/commands/memory.js +107 -46
- package/src/mcp/server.js +345 -0
- package/src/mcp/server.js.bak +727 -0
- package/src/services/mcp-installer.js +194 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MCP Server for AC Framework Memory System
|
|
5
|
+
* Exposes memory system functionality via Model Context Protocol
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import {
|
|
12
|
+
initDatabase,
|
|
13
|
+
isDatabaseInitialized,
|
|
14
|
+
saveMemory,
|
|
15
|
+
searchMemories,
|
|
16
|
+
getContext,
|
|
17
|
+
getTimeline,
|
|
18
|
+
getMemory,
|
|
19
|
+
updateMemory,
|
|
20
|
+
deleteMemory,
|
|
21
|
+
startSession,
|
|
22
|
+
endSession,
|
|
23
|
+
getStats,
|
|
24
|
+
findPatterns,
|
|
25
|
+
getConnections,
|
|
26
|
+
anticipateNeeds,
|
|
27
|
+
exportMemories,
|
|
28
|
+
importMemories,
|
|
29
|
+
pruneMemories,
|
|
30
|
+
MEMORY_TYPES,
|
|
31
|
+
IMPORTANCE_LEVELS
|
|
32
|
+
} from "../memory/index.js";
|
|
33
|
+
|
|
34
|
+
function getMemoryTypeDescription(type) {
|
|
35
|
+
const descriptions = {
|
|
36
|
+
architectural_decision: "Major design decisions about system architecture",
|
|
37
|
+
bugfix_pattern: "Solutions to bugs and issues encountered",
|
|
38
|
+
api_pattern: "Patterns and best practices for API design",
|
|
39
|
+
performance_insight: "Learnings from performance optimization work",
|
|
40
|
+
security_fix: "Security vulnerability fixes and patches",
|
|
41
|
+
refactor_technique: "Successful code refactoring patterns",
|
|
42
|
+
dependency_note: "Notes about project dependencies and versions",
|
|
43
|
+
workaround: "Temporary solutions to problems",
|
|
44
|
+
convention: "Established project conventions and standards",
|
|
45
|
+
context_boundary: "Defined system boundaries and limitations",
|
|
46
|
+
general_insight: "General insights and learnings",
|
|
47
|
+
session_summary: "Summary of work completed in a session"
|
|
48
|
+
};
|
|
49
|
+
return descriptions[type] || "Memory type description not available";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class MCPMemoryServer {
|
|
53
|
+
constructor() {
|
|
54
|
+
// Initialize database if not already done
|
|
55
|
+
if (!isDatabaseInitialized()) {
|
|
56
|
+
initDatabase();
|
|
57
|
+
console.error("Memory system initialized for MCP server");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.server = new McpServer({
|
|
61
|
+
name: "ac-framework-memory",
|
|
62
|
+
version: "1.0.0",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.setupTools();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setupTools() {
|
|
69
|
+
// ── memory_save ──────────────────────────────────────────────
|
|
70
|
+
this.server.tool(
|
|
71
|
+
"memory_save",
|
|
72
|
+
"Save a memory observation to the persistent knowledge base",
|
|
73
|
+
{
|
|
74
|
+
content: z.string().describe("Content to save in memory"),
|
|
75
|
+
type: z.enum(MEMORY_TYPES).default("general_insight").describe("Type of memory"),
|
|
76
|
+
importance: z.enum(IMPORTANCE_LEVELS).default("medium").describe("Importance level"),
|
|
77
|
+
tags: z.array(z.string()).optional().describe("Tags for categorization"),
|
|
78
|
+
projectPath: z.string().optional().describe("Associated project path"),
|
|
79
|
+
changeName: z.string().optional().describe("Associated change name"),
|
|
80
|
+
confidence: z.number().min(0).max(1).default(0.8).describe("Confidence score (0-1)")
|
|
81
|
+
},
|
|
82
|
+
async ({ content, type, importance, tags, projectPath, changeName, confidence }) => {
|
|
83
|
+
try {
|
|
84
|
+
const result = saveMemory({ content, type, importance, tags, projectPath, changeName, confidence });
|
|
85
|
+
return {
|
|
86
|
+
content: [{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: JSON.stringify({ success: true, id: result.id, operation: result.operation, revisionCount: result.revisionCount }, null, 2)
|
|
89
|
+
}]
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// ── memory_search ─────────────────────────────────────────────
|
|
98
|
+
this.server.tool(
|
|
99
|
+
"memory_search",
|
|
100
|
+
"Search memories using full-text search (FTS5)",
|
|
101
|
+
{
|
|
102
|
+
query: z.string().describe("Search query"),
|
|
103
|
+
limit: z.number().int().positive().default(10).describe("Maximum results"),
|
|
104
|
+
type: z.enum(MEMORY_TYPES).optional().describe("Filter by memory type"),
|
|
105
|
+
importance: z.enum(IMPORTANCE_LEVELS).optional().describe("Filter by importance"),
|
|
106
|
+
projectPath: z.string().optional().describe("Filter by project path"),
|
|
107
|
+
minConfidence: z.number().min(0).max(1).default(0).describe("Minimum confidence score")
|
|
108
|
+
},
|
|
109
|
+
async ({ query, limit, type, importance, projectPath, minConfidence }) => {
|
|
110
|
+
try {
|
|
111
|
+
const results = searchMemories(query, { limit, type, importance, projectPath, minConfidence });
|
|
112
|
+
return {
|
|
113
|
+
content: [{
|
|
114
|
+
type: "text",
|
|
115
|
+
text: JSON.stringify({ query, count: results.length, results }, null, 2)
|
|
116
|
+
}]
|
|
117
|
+
};
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// ── memory_recall ─────────────────────────────────────────────
|
|
125
|
+
this.server.tool(
|
|
126
|
+
"memory_recall",
|
|
127
|
+
"Recall relevant context for a task or project",
|
|
128
|
+
{
|
|
129
|
+
task: z.string().optional().describe("Specific task to recall context for"),
|
|
130
|
+
projectPath: z.string().optional().describe("Project path"),
|
|
131
|
+
changeName: z.string().optional().describe("Change name"),
|
|
132
|
+
limit: z.number().int().positive().default(5).describe("Number of memories to return"),
|
|
133
|
+
days: z.number().int().positive().default(30).describe("Days to look back")
|
|
134
|
+
},
|
|
135
|
+
async ({ task, projectPath, changeName, limit, days }) => {
|
|
136
|
+
try {
|
|
137
|
+
const results = getContext({ projectPath, changeName, currentTask: task, limit, lookbackDays: days });
|
|
138
|
+
return {
|
|
139
|
+
content: [{
|
|
140
|
+
type: "text",
|
|
141
|
+
text: JSON.stringify({ task: task || null, projectPath, count: results.length, memories: results }, null, 2)
|
|
142
|
+
}]
|
|
143
|
+
};
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
// ── memory_get ────────────────────────────────────────────────
|
|
151
|
+
this.server.tool(
|
|
152
|
+
"memory_get",
|
|
153
|
+
"Get a specific memory by ID",
|
|
154
|
+
{
|
|
155
|
+
id: z.number().int().positive().describe("Memory ID")
|
|
156
|
+
},
|
|
157
|
+
async ({ id }) => {
|
|
158
|
+
try {
|
|
159
|
+
const memory = getMemory(id);
|
|
160
|
+
if (!memory) {
|
|
161
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Memory not found" }) }], isError: true };
|
|
162
|
+
}
|
|
163
|
+
return { content: [{ type: "text", text: JSON.stringify({ memory }, null, 2) }] };
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// ── memory_timeline ───────────────────────────────────────────
|
|
171
|
+
this.server.tool(
|
|
172
|
+
"memory_timeline",
|
|
173
|
+
"Get chronological timeline around a specific memory",
|
|
174
|
+
{
|
|
175
|
+
id: z.number().int().positive().describe("Memory ID"),
|
|
176
|
+
window: z.number().int().positive().default(3).describe("Number of memories before/after")
|
|
177
|
+
},
|
|
178
|
+
async ({ id, window }) => {
|
|
179
|
+
try {
|
|
180
|
+
const timeline = getTimeline(id, { window });
|
|
181
|
+
if (!timeline) {
|
|
182
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Memory not found" }) }], isError: true };
|
|
183
|
+
}
|
|
184
|
+
return { content: [{ type: "text", text: JSON.stringify(timeline, null, 2) }] };
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// ── memory_stats ──────────────────────────────────────────────
|
|
192
|
+
this.server.tool(
|
|
193
|
+
"memory_stats",
|
|
194
|
+
"Get memory system statistics",
|
|
195
|
+
{
|
|
196
|
+
projectPath: z.string().optional().describe("Filter by project path"),
|
|
197
|
+
since: z.string().optional().describe("ISO date string to filter from")
|
|
198
|
+
},
|
|
199
|
+
async ({ projectPath, since }) => {
|
|
200
|
+
try {
|
|
201
|
+
const stats = getStats({ projectPath, since });
|
|
202
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
203
|
+
} catch (error) {
|
|
204
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// ── memory_patterns ───────────────────────────────────────────
|
|
210
|
+
this.server.tool(
|
|
211
|
+
"memory_patterns",
|
|
212
|
+
"Find patterns and clusters in the memory system",
|
|
213
|
+
{
|
|
214
|
+
type: z.enum(MEMORY_TYPES).optional().describe("Filter by memory type"),
|
|
215
|
+
minFrequency: z.number().int().positive().default(2).describe("Minimum frequency for pattern detection")
|
|
216
|
+
},
|
|
217
|
+
async ({ type, minFrequency }) => {
|
|
218
|
+
try {
|
|
219
|
+
const patterns = findPatterns({ type, minFrequency });
|
|
220
|
+
return { content: [{ type: "text", text: JSON.stringify({ patterns }, null, 2) }] };
|
|
221
|
+
} catch (error) {
|
|
222
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
// ── memory_anticipate ─────────────────────────────────────────
|
|
228
|
+
this.server.tool(
|
|
229
|
+
"memory_anticipate",
|
|
230
|
+
"Anticipate memories that will be needed for a future task",
|
|
231
|
+
{
|
|
232
|
+
task: z.string().describe("Task to anticipate needs for"),
|
|
233
|
+
projectPath: z.string().optional().describe("Project path"),
|
|
234
|
+
limit: z.number().int().positive().default(5).describe("Number of suggestions")
|
|
235
|
+
},
|
|
236
|
+
async ({ task, projectPath, limit }) => {
|
|
237
|
+
try {
|
|
238
|
+
const memories = anticipateNeeds(task, projectPath);
|
|
239
|
+
return {
|
|
240
|
+
content: [{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: JSON.stringify({ task, suggestions: memories.slice(0, limit) }, null, 2)
|
|
243
|
+
}]
|
|
244
|
+
};
|
|
245
|
+
} catch (error) {
|
|
246
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// ── memory_export ─────────────────────────────────────────────
|
|
252
|
+
this.server.tool(
|
|
253
|
+
"memory_export",
|
|
254
|
+
"Export memories to JSON (to file or as response)",
|
|
255
|
+
{
|
|
256
|
+
filePath: z.string().optional().describe("File path to export to (optional, returns inline if omitted)"),
|
|
257
|
+
shareableOnly: z.boolean().default(true).describe("Only export shareable memories"),
|
|
258
|
+
projectPath: z.string().optional().describe("Filter by project path"),
|
|
259
|
+
since: z.string().optional().describe("ISO date string to filter from")
|
|
260
|
+
},
|
|
261
|
+
async ({ filePath, shareableOnly, projectPath, since }) => {
|
|
262
|
+
try {
|
|
263
|
+
const memories = exportMemories({ shareableOnly, projectPath, since });
|
|
264
|
+
const exportData = { exportedAt: new Date().toISOString(), count: memories.length, memories };
|
|
265
|
+
if (filePath) {
|
|
266
|
+
const { writeFileSync } = await import("node:fs");
|
|
267
|
+
writeFileSync(filePath, JSON.stringify(exportData, null, 2));
|
|
268
|
+
return {
|
|
269
|
+
content: [{
|
|
270
|
+
type: "text",
|
|
271
|
+
text: JSON.stringify({ success: true, message: `Exported ${memories.length} memories to ${filePath}` }, null, 2)
|
|
272
|
+
}]
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return { content: [{ type: "text", text: JSON.stringify(exportData, null, 2) }] };
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
// ── memory_import ─────────────────────────────────────────────
|
|
283
|
+
this.server.tool(
|
|
284
|
+
"memory_import",
|
|
285
|
+
"Import memories from a JSON file",
|
|
286
|
+
{
|
|
287
|
+
filePath: z.string().describe("File path to import from"),
|
|
288
|
+
merge: z.boolean().default(true).describe("Merge with existing memories")
|
|
289
|
+
},
|
|
290
|
+
async ({ filePath, merge }) => {
|
|
291
|
+
try {
|
|
292
|
+
const { readFileSync } = await import("node:fs");
|
|
293
|
+
const data = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
294
|
+
const memories = data.memories || data;
|
|
295
|
+
const results = importMemories(memories, { merge });
|
|
296
|
+
const success = results.filter(r => r.success);
|
|
297
|
+
const failed = results.filter(r => !r.success);
|
|
298
|
+
return {
|
|
299
|
+
content: [{
|
|
300
|
+
type: "text",
|
|
301
|
+
text: JSON.stringify({ imported: success.length, failed: failed.length, results }, null, 2)
|
|
302
|
+
}]
|
|
303
|
+
};
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
// ── memory_prune ──────────────────────────────────────────────
|
|
311
|
+
this.server.tool(
|
|
312
|
+
"memory_prune",
|
|
313
|
+
"Prune obsolete or low-confidence memories",
|
|
314
|
+
{
|
|
315
|
+
olderThanDays: z.number().int().positive().default(90).describe("Delete memories older than this many days"),
|
|
316
|
+
dryRun: z.boolean().default(false).describe("Show what would be pruned without actually deleting")
|
|
317
|
+
},
|
|
318
|
+
async ({ olderThanDays, dryRun }) => {
|
|
319
|
+
try {
|
|
320
|
+
const result = pruneMemories({ olderThanDays, dryRun });
|
|
321
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: error.message }) }], isError: true };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async run() {
|
|
330
|
+
const transport = new StdioServerTransport();
|
|
331
|
+
await this.server.connect(transport);
|
|
332
|
+
console.error("AC Framework Memory MCP Server running on stdio");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Start server if called directly
|
|
337
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
338
|
+
const server = new MCPMemoryServer();
|
|
339
|
+
server.run().catch(error => {
|
|
340
|
+
console.error("Failed to start MCP server:", error);
|
|
341
|
+
process.exit(1);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export default MCPMemoryServer;
|