@levalicious/server-memory 0.0.13 → 0.0.14

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.
@@ -1027,4 +1027,133 @@ describe('MCP Memory Server E2E Tests', () => {
1027
1027
  });
1028
1028
  });
1029
1029
  });
1030
+ describe('kb_load', () => {
1031
+ let docFile;
1032
+ beforeEach(async () => {
1033
+ docFile = path.join(testDir, 'test-doc.txt');
1034
+ });
1035
+ it('should reject non-plaintext extensions', async () => {
1036
+ const pdfPath = path.join(testDir, 'test.pdf');
1037
+ await fs.writeFile(pdfPath, 'fake pdf content');
1038
+ await expect(callTool(client, 'kb_load', { filePath: pdfPath })).rejects.toThrow(/Unsupported file extension/);
1039
+ });
1040
+ it('should reject files with no extension', async () => {
1041
+ const noExtPath = path.join(testDir, 'noext');
1042
+ await fs.writeFile(noExtPath, 'some content');
1043
+ await expect(callTool(client, 'kb_load', { filePath: noExtPath })).rejects.toThrow(/no extension/);
1044
+ });
1045
+ it('should reject missing files', async () => {
1046
+ await expect(callTool(client, 'kb_load', { filePath: path.join(testDir, 'nonexistent.txt') })).rejects.toThrow(/Failed to read file/);
1047
+ });
1048
+ it('should load a small document and create entities + relations', async () => {
1049
+ const text = [
1050
+ 'Abstract interpretation is a theory of sound approximation of program semantics.',
1051
+ 'The key idea is to compute over abstract domains instead of concrete domains.',
1052
+ 'This enables static analysis to scale to large programs.',
1053
+ 'Galois connections formalize the relationship between abstract and concrete.',
1054
+ 'Widening operators ensure termination of the analysis.',
1055
+ ].join(' ');
1056
+ await fs.writeFile(docFile, text);
1057
+ const result = await callTool(client, 'kb_load', { filePath: docFile });
1058
+ expect(result.document).toBe('test-doc');
1059
+ expect(result.entitiesCreated).toBeGreaterThan(0);
1060
+ expect(result.relationsCreated).toBeGreaterThan(0);
1061
+ expect(result.stats.chunks).toBeGreaterThan(0);
1062
+ expect(result.stats.sentences).toBeGreaterThan(0);
1063
+ });
1064
+ it('should create Document, TextChunk, and DocumentIndex entities', async () => {
1065
+ await fs.writeFile(docFile, 'The quick brown fox jumps over the lazy dog. The fox was very quick and the dog was very lazy. This sentence makes the document long enough to have multiple chunks for testing purposes and analysis.');
1066
+ await callTool(client, 'kb_load', { filePath: docFile });
1067
+ // Check document entity
1068
+ const docResult = await callTool(client, 'open_nodes', { names: ['test-doc'] });
1069
+ expect(docResult.entities.items).toHaveLength(1);
1070
+ expect(docResult.entities.items[0].entityType).toBe('Document');
1071
+ // Check index entity
1072
+ const indexResult = await callTool(client, 'open_nodes', { names: ['test-doc__index'] });
1073
+ expect(indexResult.entities.items).toHaveLength(1);
1074
+ expect(indexResult.entities.items[0].entityType).toBe('DocumentIndex');
1075
+ // Check TextChunk entities exist via type query
1076
+ const chunks = await callTool(client, 'get_entities_by_type', { entityType: 'TextChunk' });
1077
+ expect(chunks.items.length).toBeGreaterThan(0);
1078
+ for (const chunk of chunks.items) {
1079
+ expect(chunk.observations.length).toBeLessThanOrEqual(2);
1080
+ for (const obs of chunk.observations) {
1081
+ expect(obs.length).toBeLessThanOrEqual(140);
1082
+ }
1083
+ }
1084
+ });
1085
+ it('should create chain relations (starts_with, ends_with, follows)', async () => {
1086
+ const text = 'First sentence of the document goes here. ' +
1087
+ 'Second sentence adds more content to the document. ' +
1088
+ 'Third sentence continues the thought further along. ' +
1089
+ 'Fourth sentence wraps up the document nicely.';
1090
+ await fs.writeFile(docFile, text);
1091
+ await callTool(client, 'kb_load', { filePath: docFile });
1092
+ // Get the document's relations
1093
+ const docResult = await callTool(client, 'open_nodes', { names: ['test-doc'] });
1094
+ const relTypes = docResult.relations.items.map(r => r.relationType);
1095
+ expect(relTypes).toContain('starts_with');
1096
+ expect(relTypes).toContain('has_index');
1097
+ });
1098
+ it('should create index → chunk highlight relations', async () => {
1099
+ const sentences = [];
1100
+ for (let i = 0; i < 20; i++) {
1101
+ sentences.push(`This is sentence number ${i} about abstract interpretation and program analysis with different keywords each time.`);
1102
+ }
1103
+ await fs.writeFile(docFile, sentences.join(' '));
1104
+ const result = await callTool(client, 'kb_load', { filePath: docFile });
1105
+ expect(result.stats.indexHighlights).toBeGreaterThan(0);
1106
+ // Open the index and verify it has highlight relations
1107
+ const indexResult = await callTool(client, 'open_nodes', { names: ['test-doc__index'] });
1108
+ const highlightRels = indexResult.relations.items.filter(r => r.relationType === 'highlights');
1109
+ expect(highlightRels.length).toBeGreaterThan(0);
1110
+ });
1111
+ it('should respect custom title', async () => {
1112
+ await fs.writeFile(docFile, 'Some document content that is long enough to process.');
1113
+ const result = await callTool(client, 'kb_load', {
1114
+ filePath: docFile,
1115
+ title: 'my-custom-title',
1116
+ });
1117
+ expect(result.document).toBe('my-custom-title');
1118
+ const docResult = await callTool(client, 'open_nodes', { names: ['my-custom-title'] });
1119
+ expect(docResult.entities.items).toHaveLength(1);
1120
+ });
1121
+ it('should not create duplicate document entity on reload with different content', async () => {
1122
+ await fs.writeFile(docFile, 'Short doc for dedup testing purposes here.');
1123
+ await callTool(client, 'kb_load', { filePath: docFile });
1124
+ // Second load with different content but same title — Document entity
1125
+ // already exists with entityType 'Document' and no observations,
1126
+ // so it gets silently skipped. But the index entity already exists
1127
+ // with different observations, so it should error.
1128
+ await fs.writeFile(docFile, 'Completely different content for dedup testing now.');
1129
+ await expect(callTool(client, 'kb_load', { filePath: docFile })).rejects.toThrow(/already exists/);
1130
+ });
1131
+ it('should enforce observation length limits', async () => {
1132
+ // Create a document with very long words that might challenge splitting
1133
+ const longWord = 'a'.repeat(200);
1134
+ await fs.writeFile(docFile, `${longWord} is a very long word that tests our splitting logic handles edge cases.`);
1135
+ const result = await callTool(client, 'kb_load', { filePath: docFile });
1136
+ expect(result.entitiesCreated).toBeGreaterThan(0);
1137
+ // All observations should be within limits
1138
+ const chunks = await callTool(client, 'get_entities_by_type', { entityType: 'TextChunk' });
1139
+ for (const chunk of chunks.items) {
1140
+ for (const obs of chunk.observations) {
1141
+ expect(obs.length).toBeLessThanOrEqual(140);
1142
+ }
1143
+ }
1144
+ });
1145
+ it('should accept various plaintext extensions', async () => {
1146
+ const extensions = ['.txt', '.md', '.tex', '.py', '.ts', '.c'];
1147
+ for (const ext of extensions) {
1148
+ const filePath = path.join(testDir, `test${ext}`);
1149
+ await fs.writeFile(filePath, 'Some plaintext content for extension testing purposes here.');
1150
+ // Should not throw on validation — use a unique title per extension
1151
+ const result = await callTool(client, 'kb_load', {
1152
+ filePath,
1153
+ title: `ext-test-${ext.slice(1)}`,
1154
+ });
1155
+ expect(result.entitiesCreated).toBeGreaterThan(0);
1156
+ }
1157
+ });
1158
+ });
1030
1159
  });
@@ -31,6 +31,12 @@ const PAGINATED_TOOLS = new Set([
31
31
  'get_orphaned_entities',
32
32
  ]);
33
33
  export async function callTool(client, name, args) {
34
+ // Verify tool is discoverable via ListTools before calling it
35
+ const listing = await client.listTools();
36
+ const toolNames = listing.tools.map((t) => t.name);
37
+ if (!toolNames.includes(name)) {
38
+ throw new Error(`Tool "${name}" is not listed in ListTools. Available: ${toolNames.join(', ')}`);
39
+ }
34
40
  const result = await client.callTool({ name, arguments: args });
35
41
  const content = result.content;
36
42
  if (!content || content.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levalicious/server-memory",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "MCP server for enabling memory for Claude through a knowledge graph",
5
5
  "license": "MIT",
6
6
  "author": "Levalicious",
@@ -19,6 +19,8 @@
19
19
  "scripts": {
20
20
  "build": "node-gyp rebuild && tsc && shx chmod +x dist/*.js",
21
21
  "build:native": "node-gyp rebuild",
22
+ "lint": "eslint .",
23
+ "lint:fix": "eslint . --fix",
22
24
  "prepare": "husky && npm run build",
23
25
  "watch": "tsc --watch",
24
26
  "test": "NODE_OPTIONS='--experimental-vm-modules' jest"
@@ -31,10 +33,12 @@
31
33
  "@types/jest": "^30.0.0",
32
34
  "@types/node": "^25",
33
35
  "@types/proper-lockfile": "^4.1.4",
36
+ "eslint": "^10.0.0",
34
37
  "husky": "^9.1.7",
35
38
  "jest": "^30.2.0",
36
39
  "shx": "^0.4.0",
37
40
  "ts-jest": "^29.4.5",
38
- "typescript": "^5.6.2"
41
+ "typescript": "^5.6.2",
42
+ "typescript-eslint": "^8.55.0"
39
43
  }
40
44
  }