search_nodes
Find nodes in a knowledge graph by searching entity names, types, and observation content with a query.
Instructions
Search for nodes in the knowledge graph based on a query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to match against entity names, types, and observation content |
Implementation Reference
- index.ts:157-181 (handler)The core handler function that executes the search_nodes tool logic: loads the knowledge graph, filters entities matching the query in name, entityType, or observations, filters relations between those entities, and returns the filtered subgraph.async searchNodes(query: string): Promise<KnowledgeGraph> { const graph = await this.loadGraph(); // Filter entities const filteredEntities = graph.entities.filter(e => e.name.toLowerCase().includes(query.toLowerCase()) || e.entityType.toLowerCase().includes(query.toLowerCase()) || e.observations.some(o => o.toLowerCase().includes(query.toLowerCase())) ); // Create a Set of filtered entity names for quick lookup const filteredEntityNames = new Set(filteredEntities.map(e => e.name)); // Filter relations to only include those between filtered entities const filteredRelations = graph.relations.filter(r => filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to) ); const filteredGraph: KnowledgeGraph = { entities: filteredEntities, relations: filteredRelations, }; return filteredGraph; }
- index.ts:531-532 (registration)Registration and dispatch logic in the CallToolRequest handler switch statement, which calls the searchNodes method with the provided query argument.case "search_nodes": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.searchNodes(args.query as string), null, 2) }] };
- index.ts:429-438 (schema)Tool schema definition including name, description, and input schema requiring a 'query' string parameter, registered in the ListTools response.name: "search_nodes", description: "Search for nodes in the knowledge graph based on a query", inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to match against entity names, types, and observation content" }, }, required: ["query"], }, },