@datafrog-io/n2n-memory 1.0.2 → 1.1.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.
@@ -0,0 +1,340 @@
1
+ import { Mutex } from "async-mutex";
2
+ import lockfile from "proper-lockfile";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { MemoryManager, MEMORY_FILE_PATH, CONTEXT_FILE_PATH } from "./memory-manager.js";
6
+ /**
7
+ * MemoryService - High reliability dual-buffer memory manager.
8
+ * - Snapshot Buffer: Instant in-memory reads for both Graph and Context.
9
+ * - Write Queue: Sequentialized, atomic writes with independent cross-process locking for Graph and Context.
10
+ */
11
+ export class MemoryService {
12
+ static instance;
13
+ // Graph state
14
+ snapshots = new Map();
15
+ writeMutexes = new Map();
16
+ lastMtimes = new Map();
17
+ // Context state (Hot data)
18
+ contextSnapshots = new Map();
19
+ contextMutexes = new Map();
20
+ contextMtimes = new Map();
21
+ // Resource Management
22
+ activeLocks = new Map();
23
+ projectAccessOrder = [];
24
+ MAX_PROJECTS = 20;
25
+ constructor() { }
26
+ static getInstance() {
27
+ if (!MemoryService.instance) {
28
+ MemoryService.instance = new MemoryService();
29
+ }
30
+ return MemoryService.instance;
31
+ }
32
+ /** @internal */
33
+ static resetInstance() {
34
+ MemoryService.instance = new MemoryService();
35
+ }
36
+ /**
37
+ * Gracefully shuts down the service, releasing all active file locks.
38
+ */
39
+ async shutdown() {
40
+ console.error(`[MemoryService] Shutting down, releasing ${this.activeLocks.size} locks...`);
41
+ const lockReleases = Array.from(this.activeLocks.values());
42
+ await Promise.all(lockReleases.map(release => release().catch(() => { })));
43
+ this.activeLocks.clear();
44
+ }
45
+ /**
46
+ * Simple LRU pruning to prevent memory growth.
47
+ */
48
+ touchProject(projectPath) {
49
+ this.projectAccessOrder = this.projectAccessOrder.filter(p => p !== projectPath);
50
+ this.projectAccessOrder.push(projectPath);
51
+ if (this.projectAccessOrder.length > this.MAX_PROJECTS) {
52
+ const oldest = this.projectAccessOrder.shift();
53
+ if (oldest) {
54
+ this.snapshots.delete(oldest);
55
+ this.lastMtimes.delete(oldest);
56
+ this.contextSnapshots.delete(oldest);
57
+ this.contextMtimes.delete(oldest);
58
+ this.writeMutexes.delete(oldest);
59
+ this.contextMutexes.delete(oldest);
60
+ }
61
+ }
62
+ }
63
+ getMutex(projectPath) {
64
+ if (!this.writeMutexes.has(projectPath)) {
65
+ this.writeMutexes.set(projectPath, new Mutex());
66
+ }
67
+ return this.writeMutexes.get(projectPath);
68
+ }
69
+ getContextMutex(projectPath) {
70
+ if (!this.contextMutexes.has(projectPath)) {
71
+ this.contextMutexes.set(projectPath, new Mutex());
72
+ }
73
+ return this.contextMutexes.get(projectPath);
74
+ }
75
+ // --- Graph Operations ---
76
+ async loadSnapshot(projectPath) {
77
+ this.touchProject(projectPath);
78
+ const filePath = path.resolve(projectPath, MEMORY_FILE_PATH);
79
+ try {
80
+ if (await fs.pathExists(filePath)) {
81
+ const stats = await fs.stat(filePath);
82
+ const currentMtime = stats.mtimeMs;
83
+ if (this.snapshots.has(projectPath) && this.lastMtimes.get(projectPath) === currentMtime) {
84
+ return this.snapshots.get(projectPath);
85
+ }
86
+ const graph = await MemoryManager.readGraph(projectPath);
87
+ this.snapshots.set(projectPath, graph);
88
+ this.lastMtimes.set(projectPath, currentMtime);
89
+ return graph;
90
+ }
91
+ }
92
+ catch (error) {
93
+ console.error(`[MemoryService] Failed to load graph snapshot: ${error}`);
94
+ }
95
+ const emptyGraph = { entities: [], relations: [] };
96
+ this.snapshots.set(projectPath, emptyGraph);
97
+ return emptyGraph;
98
+ }
99
+ async getGraph(projectPath) {
100
+ if (!this.snapshots.has(projectPath)) {
101
+ return await this.loadSnapshot(projectPath);
102
+ }
103
+ return this.snapshots.get(projectPath);
104
+ }
105
+ // --- Context Operations ---
106
+ async loadContextSnapshot(projectPath) {
107
+ this.touchProject(projectPath);
108
+ const filePath = path.resolve(projectPath, CONTEXT_FILE_PATH);
109
+ try {
110
+ if (await fs.pathExists(filePath)) {
111
+ const stats = await fs.stat(filePath);
112
+ const currentMtime = stats.mtimeMs;
113
+ if (this.contextSnapshots.has(projectPath) && this.contextMtimes.get(projectPath) === currentMtime) {
114
+ return this.contextSnapshots.get(projectPath);
115
+ }
116
+ const context = await MemoryManager.readContext(projectPath);
117
+ this.contextSnapshots.set(projectPath, context);
118
+ this.contextMtimes.set(projectPath, currentMtime);
119
+ return context;
120
+ }
121
+ }
122
+ catch (error) {
123
+ console.error(`[MemoryService] Failed to load context snapshot: ${error}`);
124
+ }
125
+ const defaultContext = { status: "PLANNING", nextSteps: [] };
126
+ this.contextSnapshots.set(projectPath, defaultContext);
127
+ return defaultContext;
128
+ }
129
+ async getContext(projectPath) {
130
+ if (!this.contextSnapshots.has(projectPath)) {
131
+ return await this.loadContextSnapshot(projectPath);
132
+ }
133
+ return this.contextSnapshots.get(projectPath);
134
+ }
135
+ /**
136
+ * Updates project context with independent locking.
137
+ */
138
+ async updateContext(projectPath, update) {
139
+ const mutex = this.getContextMutex(projectPath);
140
+ const filePath = path.resolve(projectPath, CONTEXT_FILE_PATH);
141
+ const dirPath = path.dirname(filePath);
142
+ await mutex.runExclusive(async () => {
143
+ await fs.ensureDir(dirPath);
144
+ const fileExists = await fs.pathExists(filePath);
145
+ let release;
146
+ try {
147
+ if (fileExists) {
148
+ release = await lockfile.lock(filePath, { retries: 5 });
149
+ }
150
+ else {
151
+ release = await lockfile.lock(dirPath, { retries: 5 });
152
+ }
153
+ this.activeLocks.set(filePath, release);
154
+ const currentContext = await MemoryManager.readContext(projectPath);
155
+ const updatedContext = { ...currentContext, ...update };
156
+ await MemoryManager.writeContext(projectPath, updatedContext);
157
+ // Update local snapshot
158
+ const stats = await fs.stat(filePath);
159
+ this.contextMtimes.set(projectPath, stats.mtimeMs);
160
+ this.contextSnapshots.set(projectPath, updatedContext);
161
+ }
162
+ finally {
163
+ if (release) {
164
+ this.activeLocks.delete(filePath);
165
+ await release();
166
+ }
167
+ }
168
+ });
169
+ }
170
+ // --- Combined Operations ---
171
+ async getCompleteState(projectPath, options = {}) {
172
+ const [graph, context] = await Promise.all([
173
+ this.getGraph(projectPath),
174
+ this.getContext(projectPath)
175
+ ]);
176
+ const totalEntityCount = graph.entities.length;
177
+ const offset = options.offset || 0;
178
+ const limit = options.limit || totalEntityCount;
179
+ const paginatedEntities = graph.entities.slice(offset, offset + limit);
180
+ const isTruncated = (offset + limit) < totalEntityCount;
181
+ const entities = options.summaryMode
182
+ ? paginatedEntities.map(e => ({ name: e.name, entityType: e.entityType, observations: [] }))
183
+ : paginatedEntities;
184
+ // Filter relations to only include those where BOTH nodes are in the current page
185
+ // to maintain UI/Logic consistency during paginated reading.
186
+ const entityNameSet = new Set(paginatedEntities.map(e => e.name));
187
+ const relations = graph.relations.filter(r => entityNameSet.has(r.from) && entityNameSet.has(r.to));
188
+ return {
189
+ graph: { entities, relations },
190
+ context,
191
+ totalEntityCount,
192
+ isTruncated
193
+ };
194
+ }
195
+ async getGraphSummary(projectPath, options = {}) {
196
+ const graph = await this.getGraph(projectPath);
197
+ const totalEntityCount = graph.entities.length;
198
+ const offset = options.offset || 0;
199
+ const limit = options.limit || totalEntityCount;
200
+ const paginated = graph.entities.slice(offset, offset + limit);
201
+ const isTruncated = (offset + limit) < totalEntityCount;
202
+ return {
203
+ entities: paginated.map(e => ({ name: e.name, type: e.entityType })),
204
+ relationCount: graph.relations.length,
205
+ totalEntityCount,
206
+ isTruncated
207
+ };
208
+ }
209
+ // --- Mutation Helpers ---
210
+ async executeWrite(projectPath, updateFn) {
211
+ const mutex = this.getMutex(projectPath);
212
+ const filePath = path.resolve(projectPath, MEMORY_FILE_PATH);
213
+ const dirPath = path.dirname(filePath);
214
+ await mutex.runExclusive(async () => {
215
+ await fs.ensureDir(dirPath);
216
+ const fileExists = await fs.pathExists(filePath);
217
+ let release;
218
+ try {
219
+ if (fileExists) {
220
+ release = await lockfile.lock(filePath, { retries: 5 });
221
+ }
222
+ else {
223
+ release = await lockfile.lock(dirPath, { retries: 5 });
224
+ }
225
+ this.activeLocks.set(filePath, release);
226
+ const currentGraph = await MemoryManager.readGraph(projectPath);
227
+ updateFn(currentGraph);
228
+ await MemoryManager.writeGraph(projectPath, currentGraph);
229
+ const stats = await fs.stat(filePath);
230
+ this.lastMtimes.set(projectPath, stats.mtimeMs);
231
+ this.snapshots.set(projectPath, currentGraph);
232
+ }
233
+ catch (error) {
234
+ console.error(`[MemoryService] Write operation failed for ${projectPath}:`, error);
235
+ throw error;
236
+ }
237
+ finally {
238
+ if (release) {
239
+ this.activeLocks.delete(filePath);
240
+ await release();
241
+ }
242
+ }
243
+ });
244
+ }
245
+ async addEntities(projectPath, entities) {
246
+ await this.executeWrite(projectPath, (graph) => {
247
+ entities.forEach(newEntity => {
248
+ const existing = graph.entities.find(e => e.name === newEntity.name);
249
+ if (existing) {
250
+ existing.observations = Array.from(new Set([...existing.observations, ...newEntity.observations]));
251
+ }
252
+ else {
253
+ graph.entities.push(newEntity);
254
+ }
255
+ });
256
+ });
257
+ }
258
+ async addObservations(projectPath, observations) {
259
+ let count = 0;
260
+ await this.executeWrite(projectPath, (graph) => {
261
+ observations.forEach(obs => {
262
+ const entity = graph.entities.find(e => e.name === obs.entityName);
263
+ if (entity) {
264
+ const originalLen = entity.observations.length;
265
+ entity.observations = Array.from(new Set([...entity.observations, ...obs.contents]));
266
+ count += entity.observations.length - originalLen;
267
+ }
268
+ });
269
+ });
270
+ return count;
271
+ }
272
+ async createRelations(projectPath, relations) {
273
+ await this.executeWrite(projectPath, (graph) => {
274
+ relations.forEach(newRel => {
275
+ const exists = graph.relations.some(r => r.from === newRel.from && r.to === newRel.to && r.relationType === newRel.relationType);
276
+ if (!exists) {
277
+ graph.relations.push(newRel);
278
+ }
279
+ });
280
+ });
281
+ }
282
+ async deleteEntities(projectPath, entityNames) {
283
+ let count = 0;
284
+ await this.executeWrite(projectPath, (graph) => {
285
+ const namesToDelete = new Set(entityNames);
286
+ const originalLen = graph.entities.length;
287
+ graph.entities = graph.entities.filter(e => !namesToDelete.has(e.name));
288
+ graph.relations = graph.relations.filter(r => !namesToDelete.has(r.from) && !namesToDelete.has(r.to));
289
+ count = originalLen - graph.entities.length;
290
+ });
291
+ return count;
292
+ }
293
+ async deleteObservations(projectPath, deletions) {
294
+ let count = 0;
295
+ await this.executeWrite(projectPath, (graph) => {
296
+ deletions.forEach(del => {
297
+ const entity = graph.entities.find(e => e.name === del.entityName);
298
+ if (entity) {
299
+ const obsToDelete = new Set(del.observations);
300
+ const originalLen = entity.observations.length;
301
+ entity.observations = entity.observations.filter(o => !obsToDelete.has(o));
302
+ count += originalLen - entity.observations.length;
303
+ }
304
+ });
305
+ });
306
+ return count;
307
+ }
308
+ async deleteRelations(projectPath, relations) {
309
+ let count = 0;
310
+ await this.executeWrite(projectPath, (graph) => {
311
+ const originalLen = graph.relations.length;
312
+ graph.relations = graph.relations.filter(r => !relations.some(del => del.from === r.from && del.to === r.to && del.relationType === r.relationType));
313
+ count = originalLen - graph.relations.length;
314
+ });
315
+ return count;
316
+ }
317
+ async search(projectPath, query, options = {}) {
318
+ const graph = await this.getGraph(projectPath);
319
+ const lowerQuery = query.toLowerCase();
320
+ const filteredEntities = graph.entities.filter(e => e.name.toLowerCase().includes(lowerQuery) ||
321
+ e.entityType.toLowerCase().includes(lowerQuery) ||
322
+ e.observations.some(o => o.toLowerCase().includes(lowerQuery)));
323
+ const totalResults = filteredEntities.length;
324
+ const offset = options.offset || 0;
325
+ const limit = options.limit || totalResults;
326
+ const paginatedEntities = filteredEntities.slice(offset, offset + limit);
327
+ const isTruncated = (offset + limit) < totalResults;
328
+ const entityNames = new Set(paginatedEntities.map(e => e.name));
329
+ const filteredRelations = graph.relations.filter(r => r.from.toLowerCase().includes(lowerQuery) ||
330
+ r.to.toLowerCase().includes(lowerQuery) ||
331
+ r.relationType.toLowerCase().includes(lowerQuery) ||
332
+ (entityNames.has(r.from) || entityNames.has(r.to)));
333
+ return {
334
+ graph: { entities: paginatedEntities, relations: filteredRelations },
335
+ totalResults,
336
+ isTruncated
337
+ };
338
+ }
339
+ }
340
+ //# sourceMappingURL=memory-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-service.js","sourceRoot":"","sources":["../../src/core/memory-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACpB,MAAM,qBAAqB,CAAC;AAE7B;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACd,MAAM,CAAC,QAAQ,CAAgB;IAEvC,cAAc;IACN,SAAS,GAAgC,IAAI,GAAG,EAAE,CAAC;IACnD,YAAY,GAAuB,IAAI,GAAG,EAAE,CAAC;IAC7C,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEpD,2BAA2B;IACnB,gBAAgB,GAAgC,IAAI,GAAG,EAAE,CAAC;IAC1D,cAAc,GAAuB,IAAI,GAAG,EAAE,CAAC;IAC/C,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEvD,sBAAsB;IACd,WAAW,GAAqC,IAAI,GAAG,EAAE,CAAC;IAC1D,kBAAkB,GAAa,EAAE,CAAC;IACzB,YAAY,GAAG,EAAE,CAAC;IAEnC,gBAAwB,CAAC;IAElB,MAAM,CAAC,WAAW;QACrB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC1B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,aAAa;QACvB,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;IACjD,CAAC;IAED;;OA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from "../tools/schemas.js";
4
+ import { MemoryService } from "../core/memory-service.js";
5
+ import { MemoryManager } from "../core/memory-manager.js";
6
+ import { findProjectRoot } from "../utils/path-utils.js";
7
+ import { z } from "zod";
8
+ /**
9
+ * Handlers object containing the core logic for each tool/resource.
10
+ */
11
+ export const Handlers = {
12
+ /**
13
+ * Handles the Project Root Handshake.
14
+ * Strictly enforces that memory is only initialized at project roots.
15
+ */
16
+ async resolveRootWithHandshake(args) {
17
+ const { projectPath, confirmNewProjectRoot } = args;
18
+ let discovery;
19
+ try {
20
+ discovery = await findProjectRoot(projectPath);
21
+ }
22
+ catch (error) {
23
+ // Strict rejection for non-project folders
24
+ return {
25
+ content: [{
26
+ type: "text",
27
+ text: error instanceof Error ? error.message : String(error)
28
+ }],
29
+ isError: true
30
+ };
31
+ }
32
+ if (discovery.hasMcp) {
33
+ return discovery.rootPath;
34
+ }
35
+ // New project initialization
36
+ if (confirmNewProjectRoot === discovery.rootPath) {
37
+ return discovery.rootPath;
38
+ }
39
+ // Handshake required for recognized projects that lack .mcp
40
+ return {
41
+ content: [{
42
+ type: "text",
43
+ text: JSON.stringify({
44
+ status: "AWAITING_CONFIRMATION",
45
+ detectedRoot: discovery.rootPath,
46
+ markersFound: discovery.markersFound,
47
+ message: `N2N-Memory detected a valid project root at [${discovery.rootPath}]. ` +
48
+ `To initialize memory for this project, please call the tool again and include the 'confirmNewProjectRoot' parameter set to the 'detectedRoot' path above.`
49
+ }, null, 2)
50
+ }],
51
+ isError: true
52
+ };
53
+ },
54
+ async addEntities(args) {
55
+ const parsed = Schemas.AddEntitiesSchema.parse(args);
56
+ const root = await this.resolveRootWithHandshake(parsed);
57
+ if (typeof root !== 'string')
58
+ return root;
59
+ await MemoryService.getInstance().addEntities(root, parsed.entities);
60
+ return { content: [{ type: "text", text: `Success: Added ${parsed.entities.length} entities to root: ${root}` }] };
61
+ },
62
+ async addObservations(args) {
63
+ const parsed = Schemas.AddObservationsSchema.parse(args);
64
+ const root = await this.resolveRootWithHandshake(parsed);
65
+ if (typeof root !== 'string')
66
+ return root;
67
+ const addedCount = await MemoryService.getInstance().addObservations(root, parsed.observations);
68
+ return { content: [{ type: "text", text: `Success: Added ${addedCount} observation fragments to root: ${root}` }] };
69
+ },
70
+ async createRelations(args) {
71
+ const parsed = Schemas.CreateRelationsSchema.parse(args);
72
+ const root = await this.resolveRootWithHandshake(parsed);
73
+ if (typeof root !== 'string')
74
+ return root;
75
+ await MemoryService.getInstance().createRelations(root, parsed.relations);
76
+ return { content: [{ type: "text", text: `Success: Created ${parsed.relations.length} relations in root: ${root}` }] };
77
+ },
78
+ async readGraph(args) {
79
+ const parsed = Schemas.ReadGraphSchema.parse(args);
80
+ const root = await this.resolveRootWithHandshake(parsed);
81
+ if (typeof root !== 'string')
82
+ return root;
83
+ const state = await MemoryService.getInstance().getCompleteState(root, {
84
+ summaryMode: parsed.summaryMode,
85
+ limit: parsed.limit,
86
+ offset: parsed.offset
87
+ });
88
+ return { content: [{ type: "text", text: JSON.stringify(state, null, 2) }] };
89
+ },
90
+ async getGraphSummary(args) {
91
+ const parsed = Schemas.GetGraphSummarySchema.parse(args);
92
+ const root = await this.resolveRootWithHandshake(parsed);
93
+ if (typeof root !== 'string')
94
+ return root;
95
+ const result = await MemoryService.getInstance().getGraphSummary(root, {
96
+ limit: parsed.limit,
97
+ offset: parsed.offset
98
+ });
99
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
100
+ },
101
+ async updateContext(args) {
102
+ const parsed = Schemas.UpdateContextSchema.parse(args);
103
+ const root = await this.resolveRootWithHandshake(parsed);
104
+ if (typeof root !== 'string')
105
+ return root;
106
+ const { projectPath: _, confirmNewProjectRoot: __, ...updates } = parsed;
107
+ await MemoryService.getInstance().updateContext(root, updates);
108
+ return { content: [{ type: "text", text: `Success: Project context (hot-state) updated for root: ${root}` }] };
109
+ },
110
+ async search(args) {
111
+ const parsed = Schemas.SearchSchema.parse(args);
112
+ const root = await this.resolveRootWithHandshake(parsed);
113
+ if (typeof root !== 'string')
114
+ return root;
115
+ const result = await MemoryService.getInstance().search(root, parsed.query, {
116
+ limit: parsed.limit,
117
+ offset: parsed.offset
118
+ });
119
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
120
+ },
121
+ async deleteEntities(args) {
122
+ const parsed = Schemas.DeleteEntitiesSchema.parse(args);
123
+ const root = await this.resolveRootWithHandshake(parsed);
124
+ if (typeof root !== 'string')
125
+ return root;
126
+ const deletedCount = await MemoryService.getInstance().deleteEntities(root, parsed.entityNames);
127
+ return { content: [{ type: "text", text: `Success: Deleted ${deletedCount} entities from root: ${root}` }] };
128
+ },
129
+ async deleteObservations(args) {
130
+ const parsed = Schemas.DeleteObservationsSchema.parse(args);
131
+ const root = await this.resolveRootWithHandshake(parsed);
132
+ if (typeof root !== 'string')
133
+ return root;
134
+ const deletedCount = await MemoryService.getInstance().deleteObservations(root, parsed.deletions);
135
+ return { content: [{ type: "text", text: `Success: Deleted ${deletedCount} observations from root: ${root}` }] };
136
+ },
137
+ async deleteRelations(args) {
138
+ const parsed = Schemas.DeleteRelationsSchema.parse(args);
139
+ const root = await this.resolveRootWithHandshake(parsed);
140
+ if (typeof root !== 'string')
141
+ return root;
142
+ const deletedCount = await MemoryService.getInstance().deleteRelations(root, parsed.relations);
143
+ return { content: [{ type: "text", text: `Success: Deleted ${deletedCount} relations from root: ${root}` }] };
144
+ },
145
+ async openNodes(args) {
146
+ const parsed = Schemas.OpenNodesSchema.parse(args);
147
+ const root = await this.resolveRootWithHandshake(parsed);
148
+ if (typeof root !== 'string')
149
+ return root;
150
+ const result = await MemoryManager.openNodes(root, parsed.names);
151
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
152
+ },
153
+ async exportMarkdown(args) {
154
+ const parsed = Schemas.ExportMarkdownSchema.parse(args);
155
+ const root = await this.resolveRootWithHandshake(parsed);
156
+ if (typeof root !== 'string')
157
+ return root;
158
+ const filePath = await MemoryManager.exportToMarkdown(root, parsed.outputPath);
159
+ return { content: [{ type: "text", text: `Success: Exported knowledge graph to ${filePath}` }] };
160
+ },
161
+ async readResource(uriString) {
162
+ const uri = new URL(uriString);
163
+ if (uri.protocol !== "mcp:" || uri.host !== "memory") {
164
+ throw new McpError(ErrorCode.InvalidRequest, `Unknown resource URI: ${uriString}`);
165
+ }
166
+ const projectPath = uri.searchParams.get("path");
167
+ if (!projectPath) {
168
+ throw new McpError(ErrorCode.InvalidParams, "projectPath query parameter 'path' is required");
169
+ }
170
+ // Resources are tricky since they don't take extra arguments.
171
+ // We assume resource reading is for established projects.
172
+ const discovery = await findProjectRoot(projectPath);
173
+ if (!discovery.hasMcp) {
174
+ throw new McpError(ErrorCode.InvalidRequest, "Handshake required for new projects. Use tools first.");
175
+ }
176
+ const state = await MemoryService.getInstance().getCompleteState(discovery.rootPath);
177
+ return {
178
+ contents: [{
179
+ uri: uriString,
180
+ mimeType: "application/json",
181
+ text: JSON.stringify(state, null, 2),
182
+ }]
183
+ };
184
+ },
185
+ async callTool(name, args) {
186
+ try {
187
+ switch (name) {
188
+ case "n2n_add_entities": return await this.addEntities(args);
189
+ case "n2n_add_observations": return await this.addObservations(args);
190
+ case "n2n_create_relations": return await this.createRelations(args);
191
+ case "n2n_read_graph": return await this.readGraph(args);
192
+ case "n2n_get_graph_summary": return await this.getGraphSummary(args);
193
+ case "n2n_update_context": return await this.updateContext(args);
194
+ case "n2n_search": return await this.search(args);
195
+ case "n2n_delete_entities": return await this.deleteEntities(args);
196
+ case "n2n_delete_observations": return await this.deleteObservations(args);
197
+ case "n2n_delete_relations": return await this.deleteRelations(args);
198
+ case "n2n_open_nodes": return await this.openNodes(args);
199
+ case "n2n_export_markdown": return await this.exportMarkdown(args);
200
+ default: throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
201
+ }
202
+ }
203
+ catch (error) {
204
+ if (error instanceof z.ZodError) {
205
+ return {
206
+ content: [{
207
+ type: "text",
208
+ text: `Validation Error: ${error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join(', ')}`
209
+ }],
210
+ isError: true,
211
+ };
212
+ }
213
+ const message = error instanceof Error ? error.message : String(error);
214
+ if (message.startsWith("Directory Not Recognized as a Project")) {
215
+ return {
216
+ content: [{ type: "text", text: `Project Requirement Error: ${message}` }],
217
+ isError: true,
218
+ };
219
+ }
220
+ return {
221
+ content: [{ type: "text", text: `Execution Error: ${message}` }],
222
+ isError: true,
223
+ };
224
+ }
225
+ },
226
+ async listResources() {
227
+ return {
228
+ resources: [{
229
+ uri: "mcp://memory/graph",
230
+ name: "Project Knowledge Graph & Context",
231
+ description: "The complete knowledge graph and active project context.",
232
+ mimeType: "application/json",
233
+ }]
234
+ };
235
+ },
236
+ async listTools() {
237
+ return { tools: TOOL_DEFINITIONS };
238
+ }
239
+ };
240
+ /**
241
+ * Registers all tools and resources to the provided McpServer instance.
242
+ */
243
+ export function registerAll(server) {
244
+ server.tool("n2n_add_entities", Schemas.AddEntitiesSchema.shape, (args) => Handlers.addEntities(args));
245
+ server.tool("n2n_add_observations", Schemas.AddObservationsSchema.shape, (args) => Handlers.addObservations(args));
246
+ server.tool("n2n_create_relations", Schemas.CreateRelationsSchema.shape, (args) => Handlers.createRelations(args));
247
+ server.tool("n2n_read_graph", Schemas.ReadGraphSchema.shape, (args) => Handlers.readGraph(args));
248
+ server.tool("n2n_get_graph_summary", Schemas.GetGraphSummarySchema.shape, (args) => Handlers.getGraphSummary(args));
249
+ server.tool("n2n_update_context", Schemas.UpdateContextSchema.shape, (args) => Handlers.updateContext(args));
250
+ server.tool("n2n_search", Schemas.SearchSchema.shape, (args) => Handlers.search(args));
251
+ server.tool("n2n_delete_entities", Schemas.DeleteEntitiesSchema.shape, (args) => Handlers.deleteEntities(args));
252
+ server.tool("n2n_delete_observations", Schemas.DeleteObservationsSchema.shape, (args) => Handlers.deleteObservations(args));
253
+ server.tool("n2n_delete_relations", Schemas.DeleteRelationsSchema.shape, (args) => Handlers.deleteRelations(args));
254
+ server.tool("n2n_open_nodes", Schemas.OpenNodesSchema.shape, (args) => Handlers.openNodes(args));
255
+ server.tool("n2n_export_markdown", Schemas.ExportMarkdownSchema.shape, (args) => Handlers.exportMarkdown(args));
256
+ server.resource("graph", "mcp://memory/graph", (uri) => Handlers.readResource(uri.href));
257
+ }
258
+ //# sourceMappingURL=mcp-handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-handlers.js","sourceRoot":"","sources":["../../src/handlers/mcp-handlers.ts"],"names":[],"mappings":"AACA,OAAO,EACH,SAAS,EACT,QAAQ,EAGX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB;;;OAGG;IACH,KAAK,CAAC,wBAAwB,CAAC,IAAS;QACpC,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC;QACpD,IAAI,SAAS,CAAC;QACd,IAAI,CAAC;YACD,SAAS,GAAG,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,2CAA2C;YAC3C,OAAO;gBACH,OAAO,EAAE,CAAC;wBACN,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;qBAC/D,CAAC;gBACF,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;QAED,IAAI,SA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