@danielsimonjr/memory-mcp 0.48.0 → 9.8.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.
Files changed (209) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2000 -194
  3. package/dist/__tests__/file-path.test.js +7 -11
  4. package/dist/__tests__/knowledge-graph.test.js +3 -8
  5. package/dist/core/EntityManager.d.ts +266 -0
  6. package/dist/core/EntityManager.d.ts.map +1 -0
  7. package/dist/core/EntityManager.js +85 -133
  8. package/dist/core/GraphEventEmitter.d.ts +202 -0
  9. package/dist/core/GraphEventEmitter.d.ts.map +1 -0
  10. package/dist/core/GraphEventEmitter.js +346 -0
  11. package/dist/core/GraphStorage.d.ts +395 -0
  12. package/dist/core/GraphStorage.d.ts.map +1 -0
  13. package/dist/core/GraphStorage.js +643 -31
  14. package/dist/core/GraphTraversal.d.ts +141 -0
  15. package/dist/core/GraphTraversal.d.ts.map +1 -0
  16. package/dist/core/GraphTraversal.js +573 -0
  17. package/dist/core/HierarchyManager.d.ts +111 -0
  18. package/dist/core/HierarchyManager.d.ts.map +1 -0
  19. package/dist/{features → core}/HierarchyManager.js +14 -9
  20. package/dist/core/ManagerContext.d.ts +72 -0
  21. package/dist/core/ManagerContext.d.ts.map +1 -0
  22. package/dist/core/ManagerContext.js +118 -0
  23. package/dist/core/ObservationManager.d.ts +85 -0
  24. package/dist/core/ObservationManager.d.ts.map +1 -0
  25. package/dist/core/ObservationManager.js +51 -57
  26. package/dist/core/RelationManager.d.ts +131 -0
  27. package/dist/core/RelationManager.d.ts.map +1 -0
  28. package/dist/core/RelationManager.js +31 -7
  29. package/dist/core/SQLiteStorage.d.ts +354 -0
  30. package/dist/core/SQLiteStorage.d.ts.map +1 -0
  31. package/dist/core/SQLiteStorage.js +917 -0
  32. package/dist/core/StorageFactory.d.ts +45 -0
  33. package/dist/core/StorageFactory.d.ts.map +1 -0
  34. package/dist/core/StorageFactory.js +64 -0
  35. package/dist/core/TransactionManager.d.ts +464 -0
  36. package/dist/core/TransactionManager.d.ts.map +1 -0
  37. package/dist/core/TransactionManager.js +490 -13
  38. package/dist/core/index.d.ts +17 -0
  39. package/dist/core/index.d.ts.map +1 -0
  40. package/dist/core/index.js +12 -2
  41. package/dist/features/AnalyticsManager.d.ts +44 -0
  42. package/dist/features/AnalyticsManager.d.ts.map +1 -0
  43. package/dist/features/AnalyticsManager.js +3 -2
  44. package/dist/features/ArchiveManager.d.ts +133 -0
  45. package/dist/features/ArchiveManager.d.ts.map +1 -0
  46. package/dist/features/ArchiveManager.js +221 -14
  47. package/dist/features/CompressionManager.d.ts +117 -0
  48. package/dist/features/CompressionManager.d.ts.map +1 -0
  49. package/dist/features/CompressionManager.js +189 -20
  50. package/dist/features/IOManager.d.ts +225 -0
  51. package/dist/features/IOManager.d.ts.map +1 -0
  52. package/dist/features/IOManager.js +1041 -0
  53. package/dist/features/StreamingExporter.d.ts +123 -0
  54. package/dist/features/StreamingExporter.d.ts.map +1 -0
  55. package/dist/features/StreamingExporter.js +203 -0
  56. package/dist/features/TagManager.d.ts +147 -0
  57. package/dist/features/TagManager.d.ts.map +1 -0
  58. package/dist/features/index.d.ts +12 -0
  59. package/dist/features/index.d.ts.map +1 -0
  60. package/dist/features/index.js +5 -6
  61. package/dist/index.d.ts +9 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -10
  64. package/dist/memory.jsonl +1 -26
  65. package/dist/search/BasicSearch.d.ts +51 -0
  66. package/dist/search/BasicSearch.d.ts.map +1 -0
  67. package/dist/search/BasicSearch.js +9 -3
  68. package/dist/search/BooleanSearch.d.ts +98 -0
  69. package/dist/search/BooleanSearch.d.ts.map +1 -0
  70. package/dist/search/BooleanSearch.js +156 -9
  71. package/dist/search/EmbeddingService.d.ts +178 -0
  72. package/dist/search/EmbeddingService.d.ts.map +1 -0
  73. package/dist/search/EmbeddingService.js +358 -0
  74. package/dist/search/FuzzySearch.d.ts +118 -0
  75. package/dist/search/FuzzySearch.d.ts.map +1 -0
  76. package/dist/search/FuzzySearch.js +241 -25
  77. package/dist/search/QueryCostEstimator.d.ts +111 -0
  78. package/dist/search/QueryCostEstimator.d.ts.map +1 -0
  79. package/dist/search/QueryCostEstimator.js +355 -0
  80. package/dist/search/RankedSearch.d.ts +71 -0
  81. package/dist/search/RankedSearch.d.ts.map +1 -0
  82. package/dist/search/RankedSearch.js +54 -6
  83. package/dist/search/SavedSearchManager.d.ts +79 -0
  84. package/dist/search/SavedSearchManager.d.ts.map +1 -0
  85. package/dist/search/SearchFilterChain.d.ts +120 -0
  86. package/dist/search/SearchFilterChain.d.ts.map +1 -0
  87. package/dist/search/SearchFilterChain.js +2 -4
  88. package/dist/search/SearchManager.d.ts +326 -0
  89. package/dist/search/SearchManager.d.ts.map +1 -0
  90. package/dist/search/SearchManager.js +148 -0
  91. package/dist/search/SearchSuggestions.d.ts +27 -0
  92. package/dist/search/SearchSuggestions.d.ts.map +1 -0
  93. package/dist/search/SearchSuggestions.js +1 -1
  94. package/dist/search/SemanticSearch.d.ts +149 -0
  95. package/dist/search/SemanticSearch.d.ts.map +1 -0
  96. package/dist/search/SemanticSearch.js +323 -0
  97. package/dist/search/TFIDFEventSync.d.ts +85 -0
  98. package/dist/search/TFIDFEventSync.d.ts.map +1 -0
  99. package/dist/search/TFIDFEventSync.js +133 -0
  100. package/dist/search/TFIDFIndexManager.d.ts +151 -0
  101. package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
  102. package/dist/search/TFIDFIndexManager.js +232 -17
  103. package/dist/search/VectorStore.d.ts +235 -0
  104. package/dist/search/VectorStore.d.ts.map +1 -0
  105. package/dist/search/VectorStore.js +311 -0
  106. package/dist/search/index.d.ts +21 -0
  107. package/dist/search/index.d.ts.map +1 -0
  108. package/dist/search/index.js +12 -0
  109. package/dist/server/MCPServer.d.ts +21 -0
  110. package/dist/server/MCPServer.d.ts.map +1 -0
  111. package/dist/server/MCPServer.js +4 -4
  112. package/dist/server/responseCompressor.d.ts +94 -0
  113. package/dist/server/responseCompressor.d.ts.map +1 -0
  114. package/dist/server/responseCompressor.js +127 -0
  115. package/dist/server/toolDefinitions.d.ts +27 -0
  116. package/dist/server/toolDefinitions.d.ts.map +1 -0
  117. package/dist/server/toolDefinitions.js +188 -17
  118. package/dist/server/toolHandlers.d.ts +41 -0
  119. package/dist/server/toolHandlers.d.ts.map +1 -0
  120. package/dist/server/toolHandlers.js +467 -75
  121. package/dist/types/index.d.ts +13 -0
  122. package/dist/types/index.d.ts.map +1 -0
  123. package/dist/types/index.js +1 -1
  124. package/dist/types/types.d.ts +1654 -0
  125. package/dist/types/types.d.ts.map +1 -0
  126. package/dist/types/types.js +9 -0
  127. package/dist/utils/compressedCache.d.ts +192 -0
  128. package/dist/utils/compressedCache.d.ts.map +1 -0
  129. package/dist/utils/compressedCache.js +309 -0
  130. package/dist/utils/compressionUtil.d.ts +214 -0
  131. package/dist/utils/compressionUtil.d.ts.map +1 -0
  132. package/dist/utils/compressionUtil.js +247 -0
  133. package/dist/utils/constants.d.ts +245 -0
  134. package/dist/utils/constants.d.ts.map +1 -0
  135. package/dist/utils/constants.js +124 -0
  136. package/dist/utils/entityUtils.d.ts +321 -0
  137. package/dist/utils/entityUtils.d.ts.map +1 -0
  138. package/dist/utils/entityUtils.js +434 -4
  139. package/dist/utils/errors.d.ts +95 -0
  140. package/dist/utils/errors.d.ts.map +1 -0
  141. package/dist/utils/errors.js +24 -0
  142. package/dist/utils/formatters.d.ts +145 -0
  143. package/dist/utils/formatters.d.ts.map +1 -0
  144. package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
  145. package/dist/utils/index.d.ts +23 -0
  146. package/dist/utils/index.d.ts.map +1 -0
  147. package/dist/utils/index.js +69 -31
  148. package/dist/utils/indexes.d.ts +270 -0
  149. package/dist/utils/indexes.d.ts.map +1 -0
  150. package/dist/utils/indexes.js +526 -0
  151. package/dist/utils/logger.d.ts +24 -0
  152. package/dist/utils/logger.d.ts.map +1 -0
  153. package/dist/utils/operationUtils.d.ts +124 -0
  154. package/dist/utils/operationUtils.d.ts.map +1 -0
  155. package/dist/utils/operationUtils.js +175 -0
  156. package/dist/utils/parallelUtils.d.ts +72 -0
  157. package/dist/utils/parallelUtils.d.ts.map +1 -0
  158. package/dist/utils/parallelUtils.js +169 -0
  159. package/dist/utils/schemas.d.ts +374 -0
  160. package/dist/utils/schemas.d.ts.map +1 -0
  161. package/dist/utils/schemas.js +302 -2
  162. package/dist/utils/searchAlgorithms.d.ts +99 -0
  163. package/dist/utils/searchAlgorithms.d.ts.map +1 -0
  164. package/dist/utils/searchAlgorithms.js +167 -0
  165. package/dist/utils/searchCache.d.ts +108 -0
  166. package/dist/utils/searchCache.d.ts.map +1 -0
  167. package/dist/utils/taskScheduler.d.ts +290 -0
  168. package/dist/utils/taskScheduler.d.ts.map +1 -0
  169. package/dist/utils/taskScheduler.js +466 -0
  170. package/dist/workers/index.d.ts +12 -0
  171. package/dist/workers/index.d.ts.map +1 -0
  172. package/dist/workers/index.js +9 -0
  173. package/dist/workers/levenshteinWorker.d.ts +60 -0
  174. package/dist/workers/levenshteinWorker.d.ts.map +1 -0
  175. package/dist/workers/levenshteinWorker.js +98 -0
  176. package/package.json +17 -4
  177. package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
  178. package/dist/__tests__/integration/workflows.test.js +0 -449
  179. package/dist/__tests__/performance/benchmarks.test.js +0 -413
  180. package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
  181. package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
  182. package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
  183. package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
  184. package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
  185. package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
  186. package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
  187. package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
  188. package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
  189. package/dist/core/KnowledgeGraphManager.js +0 -423
  190. package/dist/features/BackupManager.js +0 -311
  191. package/dist/features/ExportManager.js +0 -305
  192. package/dist/features/ImportExportManager.js +0 -50
  193. package/dist/features/ImportManager.js +0 -328
  194. package/dist/memory-saved-searches.jsonl +0 -0
  195. package/dist/memory-tag-aliases.jsonl +0 -0
  196. package/dist/types/analytics.types.js +0 -6
  197. package/dist/types/entity.types.js +0 -7
  198. package/dist/types/import-export.types.js +0 -7
  199. package/dist/types/search.types.js +0 -7
  200. package/dist/types/tag.types.js +0 -6
  201. package/dist/utils/dateUtils.js +0 -89
  202. package/dist/utils/filterUtils.js +0 -155
  203. package/dist/utils/levenshtein.js +0 -62
  204. package/dist/utils/pathUtils.js +0 -115
  205. package/dist/utils/responseFormatter.js +0 -55
  206. package/dist/utils/tagUtils.js +0 -107
  207. package/dist/utils/tfidf.js +0 -90
  208. package/dist/utils/validationHelper.js +0 -99
  209. package/dist/utils/validationUtils.js +0 -109
@@ -0,0 +1,94 @@
1
+ /**
2
+ * MCP Response Compression Module
3
+ *
4
+ * Provides automatic compression for large MCP tool responses using brotli.
5
+ * Responses exceeding the threshold (default 256KB) are automatically
6
+ * compressed and base64-encoded for transport.
7
+ *
8
+ * @module server/responseCompressor
9
+ */
10
+ /**
11
+ * Structure of a compressed MCP response.
12
+ * Clients receiving this format should check the `compressed` field
13
+ * and decompress the `data` field if true.
14
+ */
15
+ export interface CompressedResponse {
16
+ /** Whether the response data is compressed */
17
+ compressed: boolean;
18
+ /** Compression format used */
19
+ compressionFormat: 'brotli' | 'none';
20
+ /** Encoding of the data field */
21
+ encoding: 'utf-8' | 'base64';
22
+ /** Original size in bytes (only present if compressed) */
23
+ originalSize?: number;
24
+ /** Compressed size in bytes (only present if compressed) */
25
+ compressedSize?: number;
26
+ /** The response data (compressed and base64-encoded, or plain text) */
27
+ data: string;
28
+ }
29
+ /**
30
+ * Options for response compression.
31
+ */
32
+ export interface ResponseCompressionOptions {
33
+ /** Force compression regardless of size threshold */
34
+ forceCompress?: boolean;
35
+ /** Custom size threshold in bytes (default: 256KB from COMPRESSION_CONFIG) */
36
+ threshold?: number;
37
+ /** Brotli quality level 0-11 (default: 6 from COMPRESSION_CONFIG) */
38
+ quality?: number;
39
+ }
40
+ /**
41
+ * Conditionally compress a response based on size threshold.
42
+ *
43
+ * Responses smaller than the threshold are returned unchanged.
44
+ * Responses larger than the threshold are compressed with brotli
45
+ * and base64-encoded for safe JSON transport.
46
+ *
47
+ * @param content - The response content to potentially compress
48
+ * @param options - Compression options
49
+ * @returns A CompressedResponse object indicating compression status
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Auto-compress large response
54
+ * const response = await maybeCompressResponse(largeJsonString);
55
+ * if (response.compressed) {
56
+ * console.log(`Compressed from ${response.originalSize} to ${response.compressedSize}`);
57
+ * }
58
+ *
59
+ * // Force compression
60
+ * const compressed = await maybeCompressResponse(data, { forceCompress: true });
61
+ * ```
62
+ */
63
+ export declare function maybeCompressResponse(content: string, options?: ResponseCompressionOptions): Promise<CompressedResponse>;
64
+ /**
65
+ * Decompress a compressed response back to its original string content.
66
+ *
67
+ * If the response is not compressed, returns the data unchanged.
68
+ *
69
+ * @param response - The CompressedResponse to decompress
70
+ * @returns The original string content
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const original = await decompressResponse(compressedResponse);
75
+ * const parsed = JSON.parse(original);
76
+ * ```
77
+ */
78
+ export declare function decompressResponse(response: CompressedResponse): Promise<string>;
79
+ /**
80
+ * Check if a response object is a CompressedResponse.
81
+ *
82
+ * @param obj - The object to check
83
+ * @returns True if the object has the CompressedResponse structure
84
+ */
85
+ export declare function isCompressedResponse(obj: unknown): obj is CompressedResponse;
86
+ /**
87
+ * Calculate potential compression savings without actually compressing.
88
+ * Useful for estimating whether compression would be beneficial.
89
+ *
90
+ * @param content - The content to estimate compression for
91
+ * @returns Estimated compression ratio (0-1, lower is better compression)
92
+ */
93
+ export declare function estimateCompressionRatio(content: string): number;
94
+ //# sourceMappingURL=responseCompressor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responseCompressor.d.ts","sourceRoot":"","sources":["../../src/server/responseCompressor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAC9B,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;IACrC,iCAAiC;IACjC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,kBAAkB,CAAC,CA2B7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAY5E;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA8BhE"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * MCP Response Compression Module
3
+ *
4
+ * Provides automatic compression for large MCP tool responses using brotli.
5
+ * Responses exceeding the threshold (default 256KB) are automatically
6
+ * compressed and base64-encoded for transport.
7
+ *
8
+ * @module server/responseCompressor
9
+ */
10
+ import { compress, decompress } from '../utils/compressionUtil.js';
11
+ import { COMPRESSION_CONFIG } from '../utils/constants.js';
12
+ /**
13
+ * Conditionally compress a response based on size threshold.
14
+ *
15
+ * Responses smaller than the threshold are returned unchanged.
16
+ * Responses larger than the threshold are compressed with brotli
17
+ * and base64-encoded for safe JSON transport.
18
+ *
19
+ * @param content - The response content to potentially compress
20
+ * @param options - Compression options
21
+ * @returns A CompressedResponse object indicating compression status
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Auto-compress large response
26
+ * const response = await maybeCompressResponse(largeJsonString);
27
+ * if (response.compressed) {
28
+ * console.log(`Compressed from ${response.originalSize} to ${response.compressedSize}`);
29
+ * }
30
+ *
31
+ * // Force compression
32
+ * const compressed = await maybeCompressResponse(data, { forceCompress: true });
33
+ * ```
34
+ */
35
+ export async function maybeCompressResponse(content, options = {}) {
36
+ const threshold = options.threshold ?? COMPRESSION_CONFIG.AUTO_COMPRESS_RESPONSE_SIZE;
37
+ const originalSize = Buffer.byteLength(content, 'utf-8');
38
+ const shouldCompress = options.forceCompress || originalSize > threshold;
39
+ if (!shouldCompress) {
40
+ return {
41
+ compressed: false,
42
+ compressionFormat: 'none',
43
+ encoding: 'utf-8',
44
+ data: content,
45
+ };
46
+ }
47
+ const quality = options.quality ?? COMPRESSION_CONFIG.BROTLI_QUALITY_BATCH;
48
+ const result = await compress(content, { quality });
49
+ return {
50
+ compressed: true,
51
+ compressionFormat: 'brotli',
52
+ encoding: 'base64',
53
+ originalSize,
54
+ compressedSize: result.compressedSize,
55
+ data: result.compressed.toString('base64'),
56
+ };
57
+ }
58
+ /**
59
+ * Decompress a compressed response back to its original string content.
60
+ *
61
+ * If the response is not compressed, returns the data unchanged.
62
+ *
63
+ * @param response - The CompressedResponse to decompress
64
+ * @returns The original string content
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const original = await decompressResponse(compressedResponse);
69
+ * const parsed = JSON.parse(original);
70
+ * ```
71
+ */
72
+ export async function decompressResponse(response) {
73
+ if (!response.compressed) {
74
+ return response.data;
75
+ }
76
+ const buffer = Buffer.from(response.data, 'base64');
77
+ const decompressed = await decompress(buffer);
78
+ return decompressed.toString('utf-8');
79
+ }
80
+ /**
81
+ * Check if a response object is a CompressedResponse.
82
+ *
83
+ * @param obj - The object to check
84
+ * @returns True if the object has the CompressedResponse structure
85
+ */
86
+ export function isCompressedResponse(obj) {
87
+ if (typeof obj !== 'object' || obj === null) {
88
+ return false;
89
+ }
90
+ const response = obj;
91
+ return (typeof response.compressed === 'boolean' &&
92
+ (response.compressionFormat === 'brotli' || response.compressionFormat === 'none') &&
93
+ (response.encoding === 'utf-8' || response.encoding === 'base64') &&
94
+ typeof response.data === 'string');
95
+ }
96
+ /**
97
+ * Calculate potential compression savings without actually compressing.
98
+ * Useful for estimating whether compression would be beneficial.
99
+ *
100
+ * @param content - The content to estimate compression for
101
+ * @returns Estimated compression ratio (0-1, lower is better compression)
102
+ */
103
+ export function estimateCompressionRatio(content) {
104
+ // Rough heuristic: JSON and repetitive text compress well (0.25-0.35)
105
+ // Random/binary data compresses poorly (0.9+)
106
+ const size = Buffer.byteLength(content, 'utf-8');
107
+ // Very small content has overhead that makes compression not worthwhile
108
+ if (size < 1000) {
109
+ return 1.0;
110
+ }
111
+ // Check for JSON-like content (compresses very well)
112
+ const jsonIndicators = (content.match(/[{}\[\]":,]/g) || []).length;
113
+ const jsonRatio = jsonIndicators / size;
114
+ if (jsonRatio > 0.1) {
115
+ // Highly JSON-like, expect 60-75% compression
116
+ return 0.25 + (0.1 * Math.random());
117
+ }
118
+ // Check for repetitive content
119
+ const uniqueChars = new Set(content).size;
120
+ const repetitionRatio = uniqueChars / Math.min(size, 256);
121
+ if (repetitionRatio < 0.3) {
122
+ // Very repetitive, expect 50-70% compression
123
+ return 0.3 + (0.15 * Math.random());
124
+ }
125
+ // Default estimate for mixed content
126
+ return 0.5 + (0.2 * Math.random());
127
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * MCP Tool Definitions
3
+ *
4
+ * Extracted from MCPServer.ts to reduce file size and improve maintainability.
5
+ * Contains all 47 tool schemas for the Knowledge Graph MCP Server.
6
+ *
7
+ * @module server/toolDefinitions
8
+ */
9
+ /**
10
+ * Tool definition type matching MCP SDK expectations.
11
+ */
12
+ export interface ToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: {
16
+ type: 'object';
17
+ properties: Record<string, unknown>;
18
+ required?: string[];
19
+ additionalProperties?: boolean;
20
+ };
21
+ }
22
+ /**
23
+ * All tool definitions for the Knowledge Graph MCP Server.
24
+ * Organized by category for easier maintenance.
25
+ */
26
+ export declare const toolDefinitions: ToolDefinition[];
27
+ //# sourceMappingURL=toolDefinitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolDefinitions.d.ts","sourceRoot":"","sources":["../../src/server/toolDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAChC,CAAC;CACH;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,cAAc,EA03B3C,CAAC"}
@@ -284,6 +284,20 @@ export const toolDefinitions = [
284
284
  additionalProperties: false,
285
285
  },
286
286
  },
287
+ // Phase 10 Sprint 4: Automatic search method selection
288
+ {
289
+ name: 'search_auto',
290
+ description: 'Automatically select and execute the best search method based on query characteristics and graph size. Returns results along with the selected method and reasoning.',
291
+ inputSchema: {
292
+ type: 'object',
293
+ properties: {
294
+ query: { type: 'string', description: 'Search query' },
295
+ limit: { type: 'number', description: 'Maximum results to return (default: 10)' },
296
+ },
297
+ required: ['query'],
298
+ additionalProperties: false,
299
+ },
300
+ },
287
301
  // ==================== SAVED SEARCH TOOLS ====================
288
302
  {
289
303
  name: 'save_search',
@@ -667,6 +681,95 @@ export const toolDefinitions = [
667
681
  additionalProperties: false,
668
682
  },
669
683
  },
684
+ // ==================== GRAPH ALGORITHM TOOLS (Phase 4 Sprint 9) ====================
685
+ {
686
+ name: 'find_shortest_path',
687
+ description: 'Find the shortest path between two entities in the knowledge graph',
688
+ inputSchema: {
689
+ type: 'object',
690
+ properties: {
691
+ source: { type: 'string', description: 'Source entity name' },
692
+ target: { type: 'string', description: 'Target entity name' },
693
+ direction: {
694
+ type: 'string',
695
+ enum: ['outgoing', 'incoming', 'both'],
696
+ description: 'Direction of traversal (default: both)',
697
+ },
698
+ relationTypes: {
699
+ type: 'array',
700
+ items: { type: 'string' },
701
+ description: 'Optional filter for relation types to follow',
702
+ },
703
+ },
704
+ required: ['source', 'target'],
705
+ additionalProperties: false,
706
+ },
707
+ },
708
+ {
709
+ name: 'find_all_paths',
710
+ description: 'Find all paths between two entities up to a maximum depth',
711
+ inputSchema: {
712
+ type: 'object',
713
+ properties: {
714
+ source: { type: 'string', description: 'Source entity name' },
715
+ target: { type: 'string', description: 'Target entity name' },
716
+ maxDepth: { type: 'number', description: 'Maximum path length (default: 5)' },
717
+ direction: {
718
+ type: 'string',
719
+ enum: ['outgoing', 'incoming', 'both'],
720
+ description: 'Direction of traversal (default: both)',
721
+ },
722
+ relationTypes: {
723
+ type: 'array',
724
+ items: { type: 'string' },
725
+ description: 'Optional filter for relation types to follow',
726
+ },
727
+ },
728
+ required: ['source', 'target'],
729
+ additionalProperties: false,
730
+ },
731
+ },
732
+ {
733
+ name: 'get_connected_components',
734
+ description: 'Find all connected components in the knowledge graph',
735
+ inputSchema: {
736
+ type: 'object',
737
+ properties: {},
738
+ additionalProperties: false,
739
+ },
740
+ },
741
+ {
742
+ name: 'get_centrality',
743
+ description: 'Calculate centrality metrics for entities in the graph',
744
+ inputSchema: {
745
+ type: 'object',
746
+ properties: {
747
+ algorithm: {
748
+ type: 'string',
749
+ enum: ['degree', 'betweenness', 'pagerank'],
750
+ description: 'Centrality algorithm to use (default: degree)',
751
+ },
752
+ direction: {
753
+ type: 'string',
754
+ enum: ['in', 'out', 'both'],
755
+ description: 'Direction for degree centrality (default: both)',
756
+ },
757
+ topN: { type: 'number', description: 'Number of top entities to return (default: 10)' },
758
+ dampingFactor: { type: 'number', description: 'Damping factor for PageRank (default: 0.85)' },
759
+ approximate: {
760
+ type: 'boolean',
761
+ description: 'Use approximation for faster betweenness centrality (default: false)',
762
+ },
763
+ sampleRate: {
764
+ type: 'number',
765
+ description: 'Sample rate for approximation (0.0-1.0, default: 0.2)',
766
+ minimum: 0.01,
767
+ maximum: 1.0,
768
+ },
769
+ },
770
+ additionalProperties: false,
771
+ },
772
+ },
670
773
  // ==================== IMPORT/EXPORT TOOLS ====================
671
774
  {
672
775
  name: 'import_graph',
@@ -689,7 +792,7 @@ export const toolDefinitions = [
689
792
  },
690
793
  {
691
794
  name: 'export_graph',
692
- description: 'Export knowledge graph in various formats',
795
+ description: 'Export knowledge graph in various formats with optional brotli compression and streaming for large graphs',
693
796
  inputSchema: {
694
797
  type: 'object',
695
798
  properties: {
@@ -708,25 +811,93 @@ export const toolDefinitions = [
708
811
  },
709
812
  description: 'Optional filter',
710
813
  },
814
+ compress: {
815
+ type: 'boolean',
816
+ description: 'Compress output with brotli (auto-enabled for >100KB)',
817
+ default: false,
818
+ },
819
+ compressionQuality: {
820
+ type: 'number',
821
+ description: 'Brotli quality level 0-11 (default: 6). Higher = better compression but slower.',
822
+ minimum: 0,
823
+ maximum: 11,
824
+ default: 6,
825
+ },
826
+ streaming: {
827
+ type: 'boolean',
828
+ description: 'Use streaming mode to write directly to file (requires outputPath)',
829
+ default: false,
830
+ },
831
+ outputPath: {
832
+ type: 'string',
833
+ description: 'File path for streaming export. Auto-enables streaming for graphs with >= 5000 entities.',
834
+ },
711
835
  },
712
836
  required: ['format'],
713
837
  additionalProperties: false,
714
838
  },
715
839
  },
840
+ // ==================== SEMANTIC SEARCH TOOLS (Phase 4 Sprint 12) ====================
841
+ {
842
+ name: 'semantic_search',
843
+ description: 'Search for entities using semantic similarity. Requires embedding provider to be configured via MEMORY_EMBEDDING_PROVIDER.',
844
+ inputSchema: {
845
+ type: 'object',
846
+ properties: {
847
+ query: { type: 'string', description: 'Natural language search query' },
848
+ limit: { type: 'number', description: 'Maximum number of results (default: 10, max: 100)' },
849
+ minSimilarity: {
850
+ type: 'number',
851
+ description: 'Minimum similarity score threshold (0.0-1.0, default: 0)',
852
+ },
853
+ },
854
+ required: ['query'],
855
+ additionalProperties: false,
856
+ },
857
+ },
858
+ {
859
+ name: 'find_similar_entities',
860
+ description: 'Find entities similar to a given entity using semantic similarity. Requires embedding provider.',
861
+ inputSchema: {
862
+ type: 'object',
863
+ properties: {
864
+ entityName: { type: 'string', description: 'Name of entity to find similar entities for' },
865
+ limit: { type: 'number', description: 'Maximum number of results (default: 10, max: 100)' },
866
+ minSimilarity: {
867
+ type: 'number',
868
+ description: 'Minimum similarity score threshold (0.0-1.0, default: 0)',
869
+ },
870
+ },
871
+ required: ['entityName'],
872
+ additionalProperties: false,
873
+ },
874
+ },
875
+ {
876
+ name: 'index_embeddings',
877
+ description: 'Index all entities for semantic search. Call this after adding entities to enable semantic search. Requires embedding provider.',
878
+ inputSchema: {
879
+ type: 'object',
880
+ properties: {
881
+ forceReindex: {
882
+ type: 'boolean',
883
+ description: 'Force re-indexing of all entities even if already indexed (default: false)',
884
+ },
885
+ },
886
+ additionalProperties: false,
887
+ },
888
+ },
716
889
  ];
717
- /**
718
- * Get tool definitions by category.
719
- */
720
- export const toolCategories = {
721
- entity: ['create_entities', 'delete_entities', 'read_graph', 'open_nodes'],
722
- relation: ['create_relations', 'delete_relations'],
723
- observation: ['add_observations', 'delete_observations'],
724
- search: ['search_nodes', 'search_by_date_range', 'search_nodes_ranked', 'boolean_search', 'fuzzy_search', 'get_search_suggestions'],
725
- savedSearch: ['save_search', 'execute_saved_search', 'list_saved_searches', 'delete_saved_search', 'update_saved_search'],
726
- tag: ['add_tags', 'remove_tags', 'set_importance', 'add_tags_to_multiple_entities', 'replace_tag', 'merge_tags'],
727
- tagAlias: ['add_tag_alias', 'list_tag_aliases', 'remove_tag_alias', 'get_aliases_for_tag', 'resolve_tag'],
728
- hierarchy: ['set_entity_parent', 'get_children', 'get_parent', 'get_ancestors', 'get_descendants', 'get_subtree', 'get_root_entities', 'get_entity_depth', 'move_entity'],
729
- analytics: ['get_graph_stats', 'validate_graph'],
730
- compression: ['find_duplicates', 'merge_entities', 'compress_graph', 'archive_entities'],
731
- importExport: ['import_graph', 'export_graph'],
732
- };
890
+ // Tool categories are documented in CLAUDE.md for reference:
891
+ // - Entity Operations: create_entities, delete_entities, read_graph, open_nodes
892
+ // - Relation Operations: create_relations, delete_relations
893
+ // - Observation Management: add_observations, delete_observations
894
+ // - Search: search_nodes, search_by_date_range, search_nodes_ranked, boolean_search, fuzzy_search, get_search_suggestions, search_auto
895
+ // - Semantic Search: semantic_search, find_similar_entities, index_embeddings
896
+ // - Saved Searches: save_search, execute_saved_search, list_saved_searches, delete_saved_search, update_saved_search
897
+ // - Tag Management: add_tags, remove_tags, set_importance, add_tags_to_multiple_entities, replace_tag, merge_tags
898
+ // - Tag Aliases: add_tag_alias, list_tag_aliases, remove_tag_alias, get_aliases_for_tag, resolve_tag
899
+ // - Hierarchy: set_entity_parent, get_children, get_parent, get_ancestors, get_descendants, get_subtree, get_root_entities, get_entity_depth, move_entity
900
+ // - Graph Algorithms: find_shortest_path, find_all_paths, get_connected_components, get_centrality
901
+ // - Analytics: get_graph_stats, validate_graph
902
+ // - Compression: find_duplicates, merge_entities, compress_graph, archive_entities
903
+ // - Import/Export: import_graph, export_graph
@@ -0,0 +1,41 @@
1
+ /**
2
+ * MCP Tool Handlers
3
+ *
4
+ * Contains handler functions for all 51 Knowledge Graph tools.
5
+ * Handlers call managers directly via ManagerContext.
6
+ * Phase 4: Updated to use specialized managers for single responsibility.
7
+ * Phase 4 Sprint 9: Added 4 graph algorithm tools (find_shortest_path, find_all_paths, get_connected_components, get_centrality).
8
+ * Phase 6: Updated to use Zod validation instead of type assertions.
9
+ * Phase 3 Sprint 4: Added response compression for large payloads.
10
+ *
11
+ * @module server/toolHandlers
12
+ */
13
+ import { formatToolResponse } from '../utils/index.js';
14
+ import type { ManagerContext } from '../core/ManagerContext.js';
15
+ /**
16
+ * Tool response type for MCP SDK compatibility.
17
+ */
18
+ export type ToolResponse = ReturnType<typeof formatToolResponse>;
19
+ /**
20
+ * Tool handler function signature.
21
+ */
22
+ export type ToolHandler = (ctx: ManagerContext, args: Record<string, unknown>) => Promise<ToolResponse>;
23
+ /**
24
+ * Registry of all tool handlers keyed by tool name.
25
+ * Handlers call managers directly for reduced abstraction layers.
26
+ *
27
+ * Note: Large-response tools (read_graph, search_nodes, get_subtree, open_nodes)
28
+ * are wrapped with automatic response compression for payloads >256KB.
29
+ */
30
+ export declare const toolHandlers: Record<string, ToolHandler>;
31
+ /**
32
+ * Handle a tool call by dispatching to the appropriate handler.
33
+ *
34
+ * @param name - Tool name to call
35
+ * @param args - Tool arguments
36
+ * @param ctx - Manager context with all manager instances
37
+ * @returns Tool response
38
+ * @throws Error if tool name is unknown
39
+ */
40
+ export declare function handleToolCall(name: string, args: Record<string, unknown>, ctx: ManagerContext): Promise<ToolResponse>;
41
+ //# sourceMappingURL=toolHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolHandlers.d.ts","sourceRoot":"","sources":["../../src/server/toolHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,kBAAkB,EAkBnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC,YAAY,CAAC,CAAC;AAyC3B;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAqhBpD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,YAAY,CAAC,CAMvB"}