Skip to main content
Glama

search_nodes

Find nodes in a knowledge graph memory by matching queries against entity names, types, and observation content. Ideal for retrieving relevant data in a scalable, semantic-aware system.

Instructions

Search for nodes in your Memento MCP knowledge graph memory based on a query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query to match against entity names, types, and observation content

Implementation Reference

  • Handler logic for the 'search_nodes' MCP tool. Dispatches the query argument to knowledgeGraphManager.searchNodes and returns the JSON-formatted KnowledgeGraph result.
    case 'search_nodes': return { content: [ { type: 'text', text: JSON.stringify(await knowledgeGraphManager.searchNodes(args.query), null, 2), }, ], };
  • Schema definition for 'search_nodes' tool including inputSchema requiring a 'query' string, description, and name. This is included in the static baseTools array returned by handleListToolsRequest, serving as both schema and registration.
    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'], }, },
  • Core searchNodes implementation in KnowledgeGraphManager. Delegates to storageProvider if available, otherwise performs case-insensitive substring search on entity names and relations' from/to fields.
    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, }; }
  • Implementation of searchNodes in the deprecated FileStorageProvider. Performs text search on entity names and observations, supports options like limit, caseSensitive, entityTypes, and filters 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, }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gannonh/memento-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server