search_nodes
Find nodes in a knowledge graph by searching entity names, types, and observation content with a query to retrieve relevant information.
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:671-696 (handler)Core handler function implementing the search logic: loads graph, filters entities by query match in name/type/observations, filters connected relations, caches result.async searchNodes(query: string): Promise<KnowledgeGraph> { const cacheKey = this.getCacheKey('searchNodes', { query }); const cached = this.cache.get<KnowledgeGraph>(cacheKey); if (cached) return cached; const graph = await this.loadGraph(); 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())) ); const filteredEntityNames = new Set(filteredEntities.map(e => e.name)); const filteredRelations = graph.relations.filter(r => filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to) ); const result = { entities: filteredEntities, relations: filteredRelations, }; this.cache.set(cacheKey, result); return result; }
- index.ts:1070-1080 (registration)Tool registration in the list of tools returned by ListToolsRequestSchema, including name, description, and input schema.{ 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"], }, },
- index.ts:1240-1241 (handler)Dispatcher case in CallToolRequestSchema handler that invokes the searchNodes method with tool arguments and formats response.case "search_nodes": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.searchNodes(args.query as string), null, 2) }] };
- index.ts:1073-1079 (schema)Input schema definition specifying the required 'query' string parameter.inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to match against entity names, types, and observation content" }, }, required: ["query"], },