MCPcopy
hub / github.com/modelcontextprotocol/servers / searchNodes

Method searchNodes

src/memory/index.ts:187–212  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

185
186 // Very basic search function
187 async searchNodes(query: string): Promise<KnowledgeGraph> {
188 const graph = await this.loadGraph();
189
190 // Filter entities
191 const filteredEntities = graph.entities.filter(e =>
192 e.name.toLowerCase().includes(query.toLowerCase()) ||
193 e.entityType.toLowerCase().includes(query.toLowerCase()) ||
194 e.observations.some(o => o.toLowerCase().includes(query.toLowerCase()))
195 );
196
197 // Create a Set of filtered entity names for quick lookup
198 const filteredEntityNames = new Set(filteredEntities.map(e => e.name));
199
200 // Include relations where at least one endpoint matches the search results.
201 // This lets callers discover connections to nodes outside the result set.
202 const filteredRelations = graph.relations.filter(r =>
203 filteredEntityNames.has(r.from) || filteredEntityNames.has(r.to)
204 );
205
206 const filteredGraph: KnowledgeGraph = {
207 entities: filteredEntities,
208 relations: filteredRelations,
209 };
210
211 return filteredGraph;
212 }
213
214 async openNodes(names: string[]): Promise<KnowledgeGraph> {
215 const graph = await this.loadGraph();

Callers 2

index.tsFile · 0.80

Calls 1

loadGraphMethod · 0.95

Tested by

no test coverage detected