search_nodes
Locate and retrieve relevant entities in a knowledge graph by executing precise queries to support structured reasoning and problem-solving tasks.
Instructions
Search for nodes in the knowledge graph based on a query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query to find matching entities |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"query": {
"description": "Search query to find matching entities",
"minLength": 1,
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/memory/tools.ts:414-441 (handler)The execute function that implements the core logic of the search_nodes tool. It performs direct matching on entity names, queries the memory store for observation matches, combines results, retrieves full entities, and returns a JSON string with the findings.execute: async (args) => { // First, check if any entity names directly match or contain the query const directMatches = Array.from(graph.entities.keys()).filter(name => name.toLowerCase().includes(args.query.toLowerCase()) ); // Then use the query interface to search observations const queryResults = await memoryStore.query({ keyword: args.query, limit: 100 }); // Combine direct entity name matches with observation content matches const entityNames = new Set<string>([ ...directMatches, ...queryResults.map(result => result.entityName) ]); // Get the full entities const results = graph.getEntities(Array.from(entityNames)); // Return as string return JSON.stringify({ entities: results, count: results.length, message: `Found ${results.length} matching entities.` }); }
- src/memory/tools.ts:410-442 (registration)Registers the search_nodes tool with the FastMCP server inside the registerMemoryTools function, specifying name, description, input schema, and inline handler.server.addTool({ name: 'search_nodes', description: 'Search for nodes in the knowledge graph based on a query', parameters: Schemas.SearchNodesSchema, execute: async (args) => { // First, check if any entity names directly match or contain the query const directMatches = Array.from(graph.entities.keys()).filter(name => name.toLowerCase().includes(args.query.toLowerCase()) ); // Then use the query interface to search observations const queryResults = await memoryStore.query({ keyword: args.query, limit: 100 }); // Combine direct entity name matches with observation content matches const entityNames = new Set<string>([ ...directMatches, ...queryResults.map(result => result.entityName) ]); // Get the full entities const results = graph.getEntities(Array.from(entityNames)); // Return as string return JSON.stringify({ entities: results, count: results.length, message: `Found ${results.length} matching entities.` }); } });
- src/utils/validation.ts:61-63 (schema)Zod schema defining the input parameters for the search_nodes tool: a required 'query' string.export const SearchNodesSchema = z.object({ query: z.string().min(1).describe('Search query to find matching entities') });