@datafrog-io/n2n-memory 1.0.0 → 1.0.3
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/CHANGELOG.md +60 -0
- package/LICENSE +21 -15
- package/README.md +89 -60
- package/build/core/memory-manager.js +141 -0
- package/build/core/memory-manager.js.map +1 -0
- package/build/core/memory-service.js +340 -0
- package/build/core/memory-service.js.map +1 -0
- package/build/handlers/mcp-handlers.js +258 -0
- package/build/handlers/mcp-handlers.js.map +1 -0
- package/build/index.js +28 -236
- package/build/index.js.map +1 -1
- package/build/tools/definitions.js +67 -0
- package/build/tools/definitions.js.map +1 -0
- package/build/tools/schemas.js +79 -0
- package/build/tools/schemas.js.map +1 -0
- package/build/types.js +8 -0
- package/build/types.js.map +1 -1
- package/build/utils/env.js +27 -0
- package/build/utils/env.js.map +1 -0
- package/build/utils/path-utils.js +62 -0
- package/build/utils/path-utils.js.map +1 -0
- package/package.json +25 -7
- package/build/memory-manager.js +0 -102
- package/build/memory-manager.js.map +0 -1
- package/docs/API_REFERENCE.md +0 -70
- package/docs/DESIGN.md +0 -52
- package/docs/DEVELOPMENT.md +0 -54
package/build/index.js
CHANGED
|
@@ -1,248 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
observations: z.array(z.object({
|
|
16
|
-
entityName: z.string(),
|
|
17
|
-
contents: z.array(z.string()),
|
|
18
|
-
})),
|
|
19
|
-
});
|
|
20
|
-
const CreateRelationsSchema = z.object({
|
|
21
|
-
projectPath: z.string(),
|
|
22
|
-
relations: z.array(RelationSchema),
|
|
23
|
-
});
|
|
24
|
-
const ReadGraphSchema = z.object({
|
|
25
|
-
projectPath: z.string(),
|
|
26
|
-
});
|
|
27
|
-
const SearchSchema = z.object({
|
|
28
|
-
projectPath: z.string(),
|
|
29
|
-
query: z.string().describe("Search keywords for entities, types, or observations"),
|
|
30
|
-
});
|
|
31
|
-
export const server = new Server({
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { registerAll } from "./handlers/mcp-handlers.js";
|
|
6
|
+
import { checkEnvironment } from "./utils/env.js";
|
|
7
|
+
import { MemoryService } from "./core/memory-service.js";
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const pkg = require("../package.json");
|
|
10
|
+
/**
|
|
11
|
+
* N2N Memory MCP Server
|
|
12
|
+
* Version is automatically read from package.json to ensure consistency.
|
|
13
|
+
*/
|
|
14
|
+
export const server = new McpServer({
|
|
32
15
|
name: "n2n-memory",
|
|
33
|
-
version:
|
|
34
|
-
}, {
|
|
35
|
-
capabilities: {
|
|
36
|
-
tools: {},
|
|
37
|
-
resources: {},
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
// --- Handler Logic Extensions (Exported for Testing) ---
|
|
41
|
-
export const Handlers = {
|
|
42
|
-
async listTools() {
|
|
43
|
-
return {
|
|
44
|
-
tools: [
|
|
45
|
-
{
|
|
46
|
-
name: "n2n_add_entities",
|
|
47
|
-
description: "Add new entities (concepts, components, nodes) to the project-local knowledge graph. Use this when you discover a new significant part of the project architecture or a core concept.",
|
|
48
|
-
inputSchema: {
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
projectPath: { type: "string", description: "Absolute path to the project root" },
|
|
52
|
-
entities: {
|
|
53
|
-
type: "array",
|
|
54
|
-
items: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: {
|
|
57
|
-
name: { type: "string", description: "Unique name of the entity" },
|
|
58
|
-
entityType: { type: "string", description: "Category of the entity (e.g., CLASS, FUNCTION, MODULE, UI_COMPONENT)" },
|
|
59
|
-
observations: { type: "array", items: { type: "string" }, description: "Initial facts or documentation fragments about this entity" },
|
|
60
|
-
},
|
|
61
|
-
required: ["name", "entityType", "observations"],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
required: ["projectPath", "entities"],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "n2n_add_observations",
|
|
70
|
-
description: "Append new facts or discovery details to existing entities. Use this as you explore the code and learn more about how specific parts work.",
|
|
71
|
-
inputSchema: {
|
|
72
|
-
type: "object",
|
|
73
|
-
properties: {
|
|
74
|
-
projectPath: { type: "string", description: "Absolute path to the project root" },
|
|
75
|
-
observations: {
|
|
76
|
-
type: "array",
|
|
77
|
-
items: {
|
|
78
|
-
type: "object",
|
|
79
|
-
properties: {
|
|
80
|
-
entityName: { type: "string", description: "The name of the existing entity to update" },
|
|
81
|
-
contents: { type: "array", items: { type: "string" }, description: "New specific facts or insights to add" },
|
|
82
|
-
},
|
|
83
|
-
required: ["entityName", "contents"],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
required: ["projectPath", "observations"],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: "n2n_create_relations",
|
|
92
|
-
description: "Define relationships between existing entities. Use this to map out dependencies, implementation details, or data flows (e.g., 'AuthService' IMPLEMENTS 'IAuth').",
|
|
93
|
-
inputSchema: {
|
|
94
|
-
type: "object",
|
|
95
|
-
properties: {
|
|
96
|
-
projectPath: { type: "string", description: "Absolute path to the project root" },
|
|
97
|
-
relations: {
|
|
98
|
-
type: "array",
|
|
99
|
-
items: {
|
|
100
|
-
type: "object",
|
|
101
|
-
properties: {
|
|
102
|
-
from: { type: "string", description: "Source entity name" },
|
|
103
|
-
to: { type: "string", description: "Target entity name" },
|
|
104
|
-
relationType: { type: "string", description: "The nature of the link (e.g., CALLS, EXTENDS, USES, CONTAINS)" },
|
|
105
|
-
},
|
|
106
|
-
required: ["from", "to", "relationType"],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
required: ["projectPath", "relations"],
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "n2n_read_graph",
|
|
115
|
-
description: "Fetch the entire knowledge graph for the current project. Use this to get an overview of the system architecture and previously stored context.",
|
|
116
|
-
inputSchema: {
|
|
117
|
-
type: "object",
|
|
118
|
-
properties: {
|
|
119
|
-
projectPath: { type: "string", description: "Absolute path to the project root" },
|
|
120
|
-
},
|
|
121
|
-
required: ["projectPath"],
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "n2n_search",
|
|
126
|
-
description: "Search for specific entities, relations, or observations within the project knowledge graph using keywords. Useful for large projects where the full graph is too big to browse.",
|
|
127
|
-
inputSchema: {
|
|
128
|
-
type: "object",
|
|
129
|
-
properties: {
|
|
130
|
-
projectPath: { type: "string", description: "Absolute path to the project root" },
|
|
131
|
-
query: { type: "string", description: "Keywords to search for in names, types, and observations" },
|
|
132
|
-
},
|
|
133
|
-
required: ["projectPath", "query"],
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
async callTool(name, args) {
|
|
140
|
-
try {
|
|
141
|
-
switch (name) {
|
|
142
|
-
case "n2n_add_entities": {
|
|
143
|
-
const parsed = AddEntitiesSchema.parse(args);
|
|
144
|
-
await MemoryManager.addEntities(parsed.projectPath, parsed.entities);
|
|
145
|
-
return { content: [{ type: "text", text: `Success: Added ${parsed.entities.length} entities.` }] };
|
|
146
|
-
}
|
|
147
|
-
case "n2n_add_observations": {
|
|
148
|
-
const parsed = AddObservationsSchema.parse(args);
|
|
149
|
-
const addedCount = await MemoryManager.addObservations(parsed.projectPath, parsed.observations);
|
|
150
|
-
return { content: [{ type: "text", text: `Success: Added ${addedCount} observation fragments.` }] };
|
|
151
|
-
}
|
|
152
|
-
case "n2n_create_relations": {
|
|
153
|
-
const parsed = CreateRelationsSchema.parse(args);
|
|
154
|
-
await MemoryManager.createRelations(parsed.projectPath, parsed.relations);
|
|
155
|
-
return { content: [{ type: "text", text: `Success: Created ${parsed.relations.length} relations.` }] };
|
|
156
|
-
}
|
|
157
|
-
case "n2n_read_graph": {
|
|
158
|
-
const parsed = ReadGraphSchema.parse(args);
|
|
159
|
-
const graph = await MemoryManager.readGraph(parsed.projectPath);
|
|
160
|
-
return { content: [{ type: "text", text: JSON.stringify(graph, null, 2) }] };
|
|
161
|
-
}
|
|
162
|
-
case "n2n_search": {
|
|
163
|
-
const parsed = SearchSchema.parse(args);
|
|
164
|
-
const result = await MemoryManager.search(parsed.projectPath, parsed.query);
|
|
165
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
166
|
-
}
|
|
167
|
-
default:
|
|
168
|
-
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
if (error instanceof z.ZodError) {
|
|
173
|
-
return {
|
|
174
|
-
content: [{
|
|
175
|
-
type: "text",
|
|
176
|
-
text: `Validation Error: ${error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join(', ')}`
|
|
177
|
-
}],
|
|
178
|
-
isError: true,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
content: [{ type: "text", text: `Execution Error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
183
|
-
isError: true,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
async listResources() {
|
|
188
|
-
return {
|
|
189
|
-
resources: [
|
|
190
|
-
{
|
|
191
|
-
uri: "mcp://memory/graph",
|
|
192
|
-
name: "Project Knowledge Graph",
|
|
193
|
-
description: "The complete knowledge graph stored in .mcp/memory.json",
|
|
194
|
-
mimeType: "application/json",
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
async readResource(uriString) {
|
|
200
|
-
const uri = new URL(uriString);
|
|
201
|
-
if (uri.protocol !== "mcp:" || uri.host !== "memory") {
|
|
202
|
-
throw new McpError(ErrorCode.InvalidRequest, `Unknown resource URI: ${uriString}`);
|
|
203
|
-
}
|
|
204
|
-
const projectPath = uri.searchParams.get("path");
|
|
205
|
-
if (!projectPath) {
|
|
206
|
-
throw new McpError(ErrorCode.InvalidParams, "projectPath query parameter 'path' is required");
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
const graph = await MemoryManager.readGraph(projectPath);
|
|
210
|
-
return {
|
|
211
|
-
contents: [
|
|
212
|
-
{
|
|
213
|
-
uri: uriString,
|
|
214
|
-
mimeType: "application/json",
|
|
215
|
-
text: JSON.stringify(graph, null, 2),
|
|
216
|
-
}
|
|
217
|
-
]
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
throw new McpError(ErrorCode.InternalError, `Failed to read memory: ${error instanceof Error ? error.message : String(error)}`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
// --- Resources ---
|
|
226
|
-
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
227
|
-
return Handlers.listResources();
|
|
228
|
-
});
|
|
229
|
-
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
230
|
-
return Handlers.readResource(request.params.uri);
|
|
231
|
-
});
|
|
232
|
-
// --- Tools ---
|
|
233
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
234
|
-
return Handlers.listTools();
|
|
235
|
-
});
|
|
236
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
237
|
-
return Handlers.callTool(request.params.name, request.params.arguments);
|
|
16
|
+
version: pkg.version,
|
|
238
17
|
});
|
|
18
|
+
// Register all tools and resources defined in handlers
|
|
19
|
+
registerAll(server);
|
|
239
20
|
async function main() {
|
|
21
|
+
checkEnvironment();
|
|
240
22
|
const transport = new StdioServerTransport();
|
|
23
|
+
// Graceful shutdown handlers
|
|
24
|
+
const shutdown = async () => {
|
|
25
|
+
console.error("\n[System] Shutdown signal received...");
|
|
26
|
+
await MemoryService.getInstance().shutdown();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
};
|
|
29
|
+
process.on("SIGINT", shutdown);
|
|
30
|
+
process.on("SIGTERM", shutdown);
|
|
31
|
+
// Use the internal server instance for connection
|
|
241
32
|
await server.connect(transport);
|
|
242
|
-
console.error(
|
|
33
|
+
console.error(`N2N Memory MCP server v${pkg.version} running on stdio`);
|
|
243
34
|
}
|
|
244
|
-
main().catch((error) => {
|
|
35
|
+
main().catch(async (error) => {
|
|
245
36
|
console.error("Fatal Server Error:", error);
|
|
37
|
+
await MemoryService.getInstance().shutdown();
|
|
246
38
|
process.exit(1);
|
|
247
39
|
});
|
|
248
40
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM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ptions and [MANDATORY PROTOCOLS].
|
|
4
|
+
*/
|
|
5
|
+
export const TOOL_DEFINITIONS = [
|
|
6
|
+
{
|
|
7
|
+
name: "n2n_add_entities",
|
|
8
|
+
description: "[MANDATORY PROTOCOL] Record new entities. [INIT HANDSHAKE] If this is a new project, you must first call this to get the 'detectedRoot', then call again with 'confirmNewProjectRoot'. [SYNC RULE] Call BEFORE every 'git commit'.",
|
|
9
|
+
inputSchema: { type: "object" } // Schema is managed via Zod in registerAll
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "n2n_add_observations",
|
|
13
|
+
description: "[MANDATORY PROTOCOL] Append learnings. [INIT HANDSHAKE] Required for new projects. [SYNC RULE] Call BEFORE every 'git commit'.",
|
|
14
|
+
inputSchema: { type: "object" }
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "n2n_create_relations",
|
|
18
|
+
description: "[RECOMMENDED PROTOCOL] Map connections. [INIT HANDSHAKE] Required for new projects. [SYNC RULE] Call BEFORE every 'git commit'.",
|
|
19
|
+
inputSchema: { type: "object" }
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "n2n_read_graph",
|
|
23
|
+
description: "[START HERE] Read project memory and active context. [INIT HANDSHAKE] For new projects, provide 'confirmNewProjectRoot' matching the server's detection. [N2N-SYNC] Respect the 'Update before Commit' policy. Set 'summaryMode' to true for a lightweight index.",
|
|
24
|
+
inputSchema: { type: "object" }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "n2n_get_graph_summary",
|
|
28
|
+
description: "Quickly fetch a list of all entity names and types plus a count of relations. Use this to get a 'map' of the project without consuming massive tokens.",
|
|
29
|
+
inputSchema: { type: "object" }
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "n2n_update_context",
|
|
33
|
+
description: "[MANDATORY PROTOCOL] Update task status and next steps. [INIT HANDSHAKE] Required for new projects. [SYNC RULE] MUST call BEFORE every 'git commit'.",
|
|
34
|
+
inputSchema: { type: "object" }
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "n2n_search",
|
|
38
|
+
description: "Search project memory by keyword. Helpful for locating specific context in large graphs.",
|
|
39
|
+
inputSchema: { type: "object" }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "n2n_delete_entities",
|
|
43
|
+
description: "Remove outdated entities and their relations.",
|
|
44
|
+
inputSchema: { type: "object" }
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "n2n_delete_observations",
|
|
48
|
+
description: "Remove specific outdated observations.",
|
|
49
|
+
inputSchema: { type: "object" }
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "n2n_delete_relations",
|
|
53
|
+
description: "Remove outdated relations.",
|
|
54
|
+
inputSchema: { type: "object" }
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "n2n_open_nodes",
|
|
58
|
+
description: "Retrieve specific entities by name. Efficient alternative to full graph read.",
|
|
59
|
+
inputSchema: { type: "object" }
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "n2n_export_markdown",
|
|
63
|
+
description: "Export knowledge graph to Markdown for documentation or review.",
|
|
64
|
+
inputSchema: { type: "object" }
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B;QACI,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,oOAAoO;QACjP,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,2CAA2C;KAC9E;IACD;QACI,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,gIAAgI;QAC7I,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAClC;IACD;QACI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z.string().describe("The absolute path to the project or any subdirectory within the project."),
|
|
4
|
+
confirmNewProjectRoot: z.string().optional().describe("MUST be provided ONLY when initializing a new project. Set this to the 'detectedRoot' path returned by the server's confirmation request."),
|
|
5
|
+
};
|
|
6
|
+
export const EntitySchema = z.object({
|
|
7
|
+
name: z.string().describe("Unique name of the entity"),
|
|
8
|
+
entityType: z.string().describe("Category of the entity (e.g., CLASS, FUNCTION, MODULE)"),
|
|
9
|
+
observations: z.array(z.string()).describe("List of facts or discoveries about this entity"),
|
|
10
|
+
});
|
|
11
|
+
export const RelationSchema = z.object({
|
|
12
|
+
from: z.string().describe("Source entity name"),
|
|
13
|
+
to: z.string().describe("Target entity name"),
|
|
14
|
+
relationType: z.string().describe("Nature of the link (e.g., CALLS, EXTENDS, USES)"),
|
|
15
|
+
});
|
|
16
|
+
export const AddEntitiesSchema = z.object({
|
|
17
|
+
...BaseSchema,
|
|
18
|
+
entities: z.array(EntitySchema),
|
|
19
|
+
});
|
|
20
|
+
export const AddObservationsSchema = z.object({
|
|
21
|
+
...BaseSchema,
|
|
22
|
+
observations: z.array(z.object({
|
|
23
|
+
entityName: z.string(),
|
|
24
|
+
contents: z.array(z.string()),
|
|
25
|
+
})),
|
|
26
|
+
});
|
|
27
|
+
export const CreateRelationsSchema = z.object({
|
|
28
|
+
...BaseSchema,
|
|
29
|
+
relations: z.array(RelationSchema),
|
|
30
|
+
});
|
|
31
|
+
export const ReadGraphSchema = z.object({
|
|
32
|
+
...BaseSchema,
|
|
33
|
+
summaryMode: z.boolean().optional().describe("If true, returns only entity names and types without detailed observations to save tokens."),
|
|
34
|
+
limit: z.number().int().positive().optional().describe("Maximum number of entities to return."),
|
|
35
|
+
offset: z.number().int().nonnegative().optional().describe("Number of entities to skip."),
|
|
36
|
+
});
|
|
37
|
+
export const GetGraphSummarySchema = z.object({
|
|
38
|
+
...BaseSchema,
|
|
39
|
+
limit: z.number().int().positive().optional().describe("Maximum number of entities to return."),
|
|
40
|
+
offset: z.number().int().nonnegative().optional().describe("Number of entities to skip."),
|
|
41
|
+
});
|
|
42
|
+
export const SearchSchema = z.object({
|
|
43
|
+
...BaseSchema,
|
|
44
|
+
query: z.string().describe("Search keywords for entities, types, or observations"),
|
|
45
|
+
limit: z.number().int().positive().optional().describe("Maximum number of entities to return."),
|
|
46
|
+
offset: z.number().int().nonnegative().optional().describe("Number of entities to skip."),
|
|
47
|
+
});
|
|
48
|
+
export const DeleteEntitiesSchema = z.object({
|
|
49
|
+
...BaseSchema,
|
|
50
|
+
entityNames: z.array(z.string()).describe("Names of entities to delete"),
|
|
51
|
+
});
|
|
52
|
+
export const DeleteObservationsSchema = z.object({
|
|
53
|
+
...BaseSchema,
|
|
54
|
+
deletions: z.array(z.object({
|
|
55
|
+
entityName: z.string(),
|
|
56
|
+
observations: z.array(z.string()),
|
|
57
|
+
})),
|
|
58
|
+
});
|
|
59
|
+
export const DeleteRelationsSchema = z.object({
|
|
60
|
+
...BaseSchema,
|
|
61
|
+
relations: z.array(RelationSchema),
|
|
62
|
+
});
|
|
63
|
+
export const OpenNodesSchema = z.object({
|
|
64
|
+
...BaseSchema,
|
|
65
|
+
names: z.array(z.string()).describe("Names of entities to retrieve"),
|
|
66
|
+
});
|
|
67
|
+
export const ExportMarkdownSchema = z.object({
|
|
68
|
+
...BaseSchema,
|
|
69
|
+
outputPath: z.string().optional().describe("Output file path relative to project root, defaults to KNOWLEDGE_GRAPH.md"),
|
|
70
|
+
});
|
|
71
|
+
export const UpdateContextSchema = z.object({
|
|
72
|
+
...BaseSchema,
|
|
73
|
+
activeTask: z.string().optional().describe("Current task being performed"),
|
|
74
|
+
status: z.enum(["IN_PROGRESS", "COMPLETED", "BLOCKED", "PLANNING"]).optional().describe("Current project status"),
|
|
75
|
+
reason: z.string().optional().describe("Reason for current status (especially if BLOCKED)"),
|
|
76
|
+
nextSteps: z.array(z.string()).optional().describe("Planned subsequent actions"),
|
|
77
|
+
lastCommit: z.string().optional().describe("Hash or message of the last relevant git commit"),
|
|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,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,+BAA+B,CAAC;CACvE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,GAAG,UAAU;IACb,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2EAA2E,CAAC;CAC1H,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,GAAG,UAAU;IACb,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;IAC1E,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IACjH,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;IAC3F,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAChF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;CAChG,CAAC,CAAC"}
|
package/build/types.js
CHANGED
|
@@ -13,4 +13,12 @@ export const KnowledgeGraphSchema = z.object({
|
|
|
13
13
|
entities: z.array(EntitySchema).default([]),
|
|
14
14
|
relations: z.array(RelationSchema).default([]),
|
|
15
15
|
});
|
|
16
|
+
export const ProjectContextSchema = z.object({
|
|
17
|
+
activeTask: z.string().optional().describe("Current task being performed"),
|
|
18
|
+
status: z.enum(["IN_PROGRESS", "COMPLETED", "BLOCKED", "PLANNING"]).default("PLANNING"),
|
|
19
|
+
reason: z.string().optional().describe("Reason for current status (especially if BLOCKED)"),
|
|
20
|
+
nextSteps: z.array(z.string()).default([]).describe("Planned subsequent actions"),
|
|
21
|
+
lastCommit: z.string().optional().describe("Hash or message of the last relevant git commit"),
|
|
22
|
+
updatedAt: z.string().optional().describe("ISO timestamp of the last context update")
|
|
23
|
+
});
|
|
16
24
|
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IACtD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;IAChF,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,kDAAkD,CAAC;CACjG,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IACtD,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IACpD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;CAC9F,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3C,SAAS,EAAE,CAAC,CAAC,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A8B,CAAC;IAC1E,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IACvF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;IAC3F,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IACjF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;IAC7F,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;CACxF,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
export function checkEnvironment() {
|
|
3
|
+
const minNodeMajor = 24;
|
|
4
|
+
const minNpmVersion = "11.5.1";
|
|
5
|
+
// 1. Check Node.js Version
|
|
6
|
+
const nodeVersion = process.version;
|
|
7
|
+
const nodeMajor = parseInt(nodeVersion.slice(1).split('.')[0], 10);
|
|
8
|
+
if (nodeMajor < minNodeMajor) {
|
|
9
|
+
console.error(`[Warning] Node.js version ${nodeVersion} detected. Node.js >= v${minNodeMajor}.0.0 is recommended for full feature support (e.g. OIDC publishing).`);
|
|
10
|
+
}
|
|
11
|
+
// 2. Check NPM Version (Dev/CI diagnostic)
|
|
12
|
+
try {
|
|
13
|
+
const npmVersion = execSync("npm -v", { encoding: "utf-8" }).trim();
|
|
14
|
+
const [major, minor, patch] = npmVersion.split('.').map(Number);
|
|
15
|
+
const [targetMajor, targetMinor, targetPatch] = minNpmVersion.split('.').map(Number);
|
|
16
|
+
const isLower = major < targetMajor ||
|
|
17
|
+
(major === targetMajor && minor < targetMinor) ||
|
|
18
|
+
(major === targetMajor && minor === targetMinor && patch < targetPatch);
|
|
19
|
+
if (isLower) {
|
|
20
|
+
console.error(`[Warning] npm version ${npmVersion} detected. npm >= ${minNpmVersion} is required for Trusted Publishing (OIDC).`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
// Silently ignore if npm is not in PATH at runtime
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,UAAU,gBAAgB;IAC5B,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,aAAa,GAAG,QAAQ,CAAC;IAE/B,2BAA2B;IAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnE,IAAI,SAAS,GAAG,YAAY,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,6BAA6B,WAAW,0BAA0B,YAAY,sEAAsE,CAAC,CAAC;IACxK,CAAC;IAED,2CAA2C;IAC3C,IAAI,CAAC;QACD,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChE,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAErF,MAAM,OAAO,GAAG,KAAK,GAAG,WAAW;YAC/B,CAAC,KAAK,KAAK,WAAW,IAAI,KAAK,GAAG,WAAW,CAAC;YAC9C,CAAC,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,IAAI,KAAK,GAAG,WAAW,CAAC,CAAC;QAE5E,IAAI,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,yBAAyB,UAAU,qBAAqB,aAAa,6CAA6C,CAAC,CAAC;QACtI,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,mDAAmD;IACvD,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
/**
|
|
4
|
+
* Common markers that define a project root.
|
|
5
|
+
*/
|
|
6
|
+
const ROOT_MARKERS = [
|
|
7
|
+
".git",
|
|
8
|
+
".mcp",
|
|
9
|
+
"package.json",
|
|
10
|
+
"go.mod",
|
|
11
|
+
"Cargo.toml",
|
|
12
|
+
"requirements.txt",
|
|
13
|
+
"pom.xml",
|
|
14
|
+
"composer.json",
|
|
15
|
+
"README.md",
|
|
16
|
+
".vscode",
|
|
17
|
+
"tsconfig.json",
|
|
18
|
+
".gitignore"
|
|
19
|
+
];
|
|
20
|
+
// Cache to store resolved roots to avoid redundant I/O (StartPath -> RootPath)
|
|
21
|
+
const rootCache = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Recursively finds the project root.
|
|
24
|
+
* NOTE: For N2N-Memory, we now strictly only check the provided path or its immediate markers
|
|
25
|
+
* to ensure that memory is only initialized at true project roots (IDE roots).
|
|
26
|
+
* @param startPath The path to start searching from.
|
|
27
|
+
*/
|
|
28
|
+
export async function findProjectRoot(startPath) {
|
|
29
|
+
const absoluteStart = path.resolve(startPath);
|
|
30
|
+
let current = absoluteStart;
|
|
31
|
+
const foundMarkers = [];
|
|
32
|
+
let hasMcp = false;
|
|
33
|
+
// Check current directory for markers
|
|
34
|
+
for (const marker of ROOT_MARKERS) {
|
|
35
|
+
const markerPath = path.join(current, marker);
|
|
36
|
+
if (await fs.pathExists(markerPath)) {
|
|
37
|
+
foundMarkers.push(marker);
|
|
38
|
+
if (marker === ".mcp")
|
|
39
|
+
hasMcp = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (foundMarkers.length > 0) {
|
|
43
|
+
return { rootPath: current, hasMcp, markersFound: foundMarkers };
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Directory Not Recognized as a Project Root: No project markers (.git, package.json, README.md, etc.) found in "${absoluteStart}". ` +
|
|
46
|
+
`N2N-Memory strictly requires you to open the IDE at the project root or use a workspace top-level directory. ` +
|
|
47
|
+
`Memory initialization is refused for generic or sub-directories to prevent context pollution.`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Basic absolute path validation.
|
|
51
|
+
*/
|
|
52
|
+
export function validateAbsolutePath(projectPath) {
|
|
53
|
+
if (!projectPath)
|
|
54
|
+
throw new Error("Project path is required.");
|
|
55
|
+
const resolved = path.resolve(projectPath);
|
|
56
|
+
if (!path.isAbsolute(resolved))
|
|
57
|
+
throw new Error(`Path must be absolute: ${projectPath}`);
|
|
58
|
+
if (resolved.includes('\0'))
|
|
59
|
+
throw new Error("Invalid path detected.");
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=path-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../../src/utils/path-utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B;;GAEG;AACH,MAAM,YAAY,GAAG;IACjB,MAAM;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;IAC3C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,EAAE,CAAC,CAAC;IACzF,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACvE,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datafrog-io/n2n-memory",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Project-local knowledge-graph memory MCP server for AI context isolation.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"n2n-memory": "build/index.js"
|
|
8
8
|
},
|
|
9
|
+
"repository": "n2ns/n2n-memory",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"provenance": true
|
|
13
|
+
},
|
|
9
14
|
"type": "module",
|
|
10
15
|
"scripts": {
|
|
11
16
|
"build": "tsc",
|
|
@@ -14,12 +19,25 @@
|
|
|
14
19
|
"test": "mocha --node-option import=tsx src/test/**/*.test.ts",
|
|
15
20
|
"lint": "eslint src/**/*.ts"
|
|
16
21
|
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
"keywords": [
|
|
23
|
+
"mcp",
|
|
24
|
+
"memory",
|
|
25
|
+
"context",
|
|
26
|
+
"ai",
|
|
27
|
+
"knowledge-graph"
|
|
28
|
+
],
|
|
29
|
+
"author": "DataFrog IO",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=24.0.0",
|
|
33
|
+
"npm": ">=11.5.1"
|
|
34
|
+
},
|
|
20
35
|
"dependencies": {
|
|
21
36
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
37
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
38
|
+
"async-mutex": "^0.5.0",
|
|
22
39
|
"fs-extra": "^11.3.3",
|
|
40
|
+
"proper-lockfile": "^4.1.2",
|
|
23
41
|
"zod": "^4.2.1"
|
|
24
42
|
},
|
|
25
43
|
"devDependencies": {
|
|
@@ -33,10 +51,10 @@
|
|
|
33
51
|
"chai": "^6.2.1",
|
|
34
52
|
"eslint": "^9.39.2",
|
|
35
53
|
"mocha": "^11.7.5",
|
|
36
|
-
"sinon": "^21.0.
|
|
54
|
+
"sinon": "^21.0.1",
|
|
37
55
|
"ts-node": "^10.9.2",
|
|
38
56
|
"tsx": "^4.21.0",
|
|
39
57
|
"typescript": "^5.9.3",
|
|
40
58
|
"typescript-eslint": "^8.50.0"
|
|
41
59
|
}
|
|
42
|
-
}
|
|
60
|
+
}
|