Skip to main content
Glama

search_nodes

Find relevant entities in a knowledge graph by searching names, types, and content to support semantic code indexing and retrieval.

Instructions

Search for nodes in the knowledge graph based on a query

Input Schema

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

Implementation Reference

  • The searchNodesHandler function implements the core logic of the 'search_nodes' tool. It validates the query input, calls knowledgeGraphManager.searchNodes, formats the result as JSON text content, and handles errors.
    export const searchNodesHandler = async (args) => { if (!args.query || typeof args.query !== 'string') { throw new Error("The 'query' parameter is required and must be a string"); } try { const results = await knowledgeGraphManager.searchNodes(args.query); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (error) { console.error("Error in search_nodes tool:", error); throw error; } };
  • The input schema and metadata definition for the 'search_nodes' tool, specifying the required 'query' string parameter.
    export const searchNodesTool = { 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"], }, };
  • Explicit registration of the 'search_nodes' tool and its handler into the toolRegistry.
    // Enregistrer search_nodes try { toolRegistry.register(searchNodesTool, searchNodesHandler); console.log(`✅ Outil enregistré: ${searchNodesTool.name}`); } catch (error) { console.error(`❌ Erreur lors de l'enregistrement de ${searchNodesTool.name}:`, error);
  • The core searchNodes method in KnowledgeGraphManager that performs the actual node searching by filtering entities and relations based on the query matching names, types, or observations case-insensitively.
    async searchNodes(query) { 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 = { entities: filteredEntities, relations: filteredRelations, }; return filteredGraph; }
  • The 'search_nodes' tool is listed in the expected tools array for verification in the auto-registry system.
    'search_nodes', 'open_nodes',

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/ali-48/rag-mcp-server'

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