search_nodes
Search your Memento MCP knowledge graph memory by querying entity names, types, and observation content to find relevant nodes.
Instructions
Search for nodes in your Memento MCP knowledge graph memory 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
- MCP tool handler that executes 'search_nodes' by calling knowledgeGraphManager.searchNodes with the provided query argument and formats the KnowledgeGraph result as JSON text content.case 'search_nodes': return { content: [ { type: 'text', text: JSON.stringify(await knowledgeGraphManager.searchNodes(args.query), null, 2), }, ], };
- src/server/handlers/listToolsHandler.ts:322-336 (registration)Registers the 'search_nodes' tool in the MCP tools list with its name, description, and input schema defining a required 'query' string parameter.{ name: 'search_nodes', description: 'Search for nodes in your Memento MCP knowledge graph memory 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'], }, },
- src/storage/StorageProvider.ts:44-49 (schema)TypeScript interface definition in StorageProvider for the searchNodes method, specifying input parameters and return type KnowledgeGraph.* @param query The search query string * @param options Optional search parameters * @returns Promise resolving to a KnowledgeGraph containing matching nodes */ searchNodes(query: string, options?: SearchOptions): Promise<KnowledgeGraph>;
- src/KnowledgeGraphManager.ts:682-706 (helper)Implementation of searchNodes in KnowledgeGraphManager that delegates to the storage provider or performs simple keyword-based filtering on the full graph as fallback.async searchNodes(query: string): Promise<KnowledgeGraph> { if (this.storageProvider) { return this.storageProvider.searchNodes(query); } // Fallback to file-based implementation const graph = await this.loadGraph(); const lowercaseQuery = query.toLowerCase(); // Filter entities based on name match const filteredEntities = graph.entities.filter((e) => e.name.toLowerCase().includes(lowercaseQuery) ); // Get relations where either the source or target entity matches the query const filteredRelations = graph.relations.filter( (r) => r.from.toLowerCase().includes(lowercaseQuery) || r.to.toLowerCase().includes(lowercaseQuery) ); return { entities: filteredEntities, relations: filteredRelations, }; }
- Concrete keyword search implementation in FileStorageProvider that filters entities by query matches in names or observations (case-insensitive by default), applies limits and type filters, and includes relations between matching entities.async searchNodes(query: string, options?: SearchOptions): Promise<KnowledgeGraph> { // Load the entire graph const graph = await this.loadGraph(); // Apply default options const searchOptions = { limit: options?.limit ?? Number.MAX_SAFE_INTEGER, caseSensitive: options?.caseSensitive ?? false, entityTypes: options?.entityTypes ?? [], }; // Filter entities that match the query let matchingEntities = graph.entities.filter((entity) => { // Check if entity matches the query const nameMatches = searchOptions.caseSensitive ? entity.name.includes(query) : entity.name.toLowerCase().includes(query.toLowerCase()); const observationsMatch = entity.observations.some((obs) => searchOptions.caseSensitive ? obs.includes(query) : obs.toLowerCase().includes(query.toLowerCase()) ); // Match if name or any observation contains the query return nameMatches || observationsMatch; }); // Filter by entity type if specified if (searchOptions.entityTypes.length > 0) { matchingEntities = matchingEntities.filter((entity) => searchOptions.entityTypes.includes(entity.entityType) ); } // Apply limit matchingEntities = matchingEntities.slice(0, searchOptions.limit); // Get entity names for relation filtering const entityNames = new Set(matchingEntities.map((entity) => entity.name)); // Filter relations that connect matching entities const matchingRelations = graph.relations.filter( (relation) => entityNames.has(relation.from) && entityNames.has(relation.to) ); return { entities: matchingEntities, relations: matchingRelations, }; }