Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query to find matching entities

Implementation Reference

  • 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.`
      });
    }
  • 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.`
        });
      }
    });
  • 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')
    });

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/flight505/mcp-think-tank'

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