Skip to main content
Glama
yodakeisuke

Knowledge Graph Memory Server

by yodakeisuke

search_nodes

Find knowledge graph nodes by searching entity names, types, subdomains, and content using keywords with OR matching.

Instructions

Search for nodes in the knowledge graph based on one or more keywords. The search covers entity names, types, subdomains, and observation content. Multiple keywords are treated as OR conditions, where any keyword must match somewhere in the entity's fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSpace-separated keywords to match against entity fields. Any keyword must match (OR condition). Example: 'budget management' will find entities where either 'budget' or 'management' appears in any field.

Implementation Reference

  • The main handler function `searchNodes` in the `KnowledgeGraphManager` class. It implements the core logic for searching the knowledge graph: normalizes query to lowercase keywords, filters entities where any keyword matches (OR) in name, entityType, subdomain, or observations, includes related relations, with extensive debug logging.
    async searchNodes(query: string): Promise<KnowledgeGraph> {
      const graph = await this.loadGraph();
      
      // Normalize query by converting to lowercase first
      const normalizedQuery = query.toLowerCase();
      console.error(`[Debug] Original query: "${query}"`);
      console.error(`[Debug] Normalized query: "${normalizedQuery}"`);
      
      // Split into keywords and filter out empty strings
      const keywords = normalizedQuery
        .split(/[\s,&+]+/) // Split on whitespace and common separators
        .filter(k => k.length > 0);
      
      if (keywords.length === 0) {
        console.error(`[Debug] No valid keywords found in query: "${query}"`);
        return { entities: [], relations: [] };
      }
    
      console.error(`[Debug] Keywords (${keywords.length}): ${JSON.stringify(keywords)}`);
      console.error(`[Debug] Total entities before filter: ${graph.entities.length}`);
      
      const filteredEntities = graph.entities.filter(e => {
        // Prepare searchable fields
        const searchableFields = {
          name: e.name.toLowerCase(),
          type: e.entityType.toLowerCase(),
          subdomain: e.subdomain?.toLowerCase() || '',
          observations: e.observations.map(o => o.toLowerCase())
        };
        
        console.error(`[Debug] Checking entity: ${e.name}`);
        console.error(`[Debug] Searchable fields:`, searchableFields);
        
        // Check each keyword against all fields (OR condition)
        const keywordMatches = keywords.map(keyword => {
          const nameMatch = searchableFields.name.includes(keyword);
          const typeMatch = searchableFields.type.includes(keyword);
          const subdomainMatch = searchableFields.subdomain.includes(keyword);
          const observationMatch = searchableFields.observations.some(o => o.includes(keyword));
          
          const matches = {
            keyword,
            nameMatch,
            typeMatch,
            subdomainMatch,
            observationMatch,
            anyMatch: nameMatch || typeMatch || subdomainMatch || observationMatch
          };
          
          if (matches.anyMatch) {
            console.error(`[Debug] Keyword "${keyword}" matched:`, {
              name: nameMatch ? searchableFields.name : false,
              type: typeMatch ? searchableFields.type : false,
              subdomain: subdomainMatch ? searchableFields.subdomain : false,
              observations: observationMatch ? searchableFields.observations.filter(o => o.includes(keyword)) : false
            });
          } else {
            console.error(`[Debug] Keyword "${keyword}" did not match any fields`);
          }
          
          return matches.anyMatch;
        });
        
        // Entity matches if ANY keyword matches (OR condition)
        const hasMatch = keywordMatches.some(match => match);
        console.error(`[Debug] Entity "${e.name}" final result: ${hasMatch} (matched ${keywordMatches.filter(m => m).length}/${keywords.length} keywords)`);
        
        return hasMatch;
      });
      
      console.error(`[Debug] Total entities after filter: ${filteredEntities.length}`);
      if (filteredEntities.length > 0) {
        console.error(`[Debug] Matched entities:`, filteredEntities.map(e => ({
          name: e.name,
          type: e.entityType,
          subdomain: e.subdomain,
          observations: e.observations
        })));
      } else {
        console.error(`[Debug] No entities matched the search criteria`);
        console.error(`[Debug] Available entities:`, graph.entities.map(e => ({
          name: e.name,
          type: e.entityType,
          subdomain: e.subdomain,
          observations: e.observations
        })));
      }
      
      const filteredEntityNames = new Set(filteredEntities.map(e => e.name));
      const filteredRelations = graph.relations.filter(r => 
        filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to)
      );
      
      return {
        entities: filteredEntities,
        relations: filteredRelations
      };
    }
  • The input schema for the 'search_nodes' tool, defining a required 'query' string parameter with description explaining the OR keyword matching behavior.
    inputSchema: {
      type: "object",
      properties: {
        query: { 
          type: "string", 
          description: "Space-separated keywords to match against entity fields. Any keyword must match (OR condition). Example: 'budget management' will find entities where either 'budget' or 'management' appears in any field." 
        },
      },
      required: ["query"],
    },
  • index.ts:508-521 (registration)
    Registration of the 'search_nodes' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: "search_nodes",
      description: "Search for nodes in the knowledge graph based on one or more keywords. The search covers entity names, types, subdomains, and observation content. Multiple keywords are treated as OR conditions, where any keyword must match somewhere in the entity's fields.",
      inputSchema: {
        type: "object",
        properties: {
          query: { 
            type: "string", 
            description: "Space-separated keywords to match against entity fields. Any keyword must match (OR condition). Example: 'budget management' will find entities where either 'budget' or 'management' appears in any field." 
          },
        },
        required: ["query"],
      },
    },
  • index.ts:570-572 (registration)
    Dispatch case in the CallToolRequestSchema handler that invokes the searchNodes handler with the query argument and returns JSON response.
    case "search_nodes":
      return createResponse(JSON.stringify(await knowledgeGraphManager.searchNodes(args.query as string), null, 2));
    case "open_nodes":
  • Output type definition for the search_nodes tool, representing the returned knowledge graph structure with entities and relations.
    interface KnowledgeGraph {
      entities: Entity[];
      relations: Relation[];
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: the search covers multiple fields (entity names, types, subdomains, observation content), uses OR logic for multiple keywords, and matches keywords anywhere in fields. However, it lacks details on response format, pagination, or error handling, which are important for a search tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with two sentences that efficiently convey purpose, scope, and behavior without redundancy. Every sentence adds value, such as specifying search fields and keyword logic, making it concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (search operation with one parameter) and no annotations or output schema, the description is moderately complete. It covers what the tool does and how keywords are handled, but lacks details on return values, limitations, or error cases, which would be helpful for an agent to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the 'query' parameter thoroughly. The description adds minimal value beyond the schema by reiterating the OR condition and field coverage, but does not provide additional syntax, examples, or constraints. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('search for nodes') and resource ('knowledge graph'), and distinguishes it from siblings by specifying it searches based on keywords across multiple entity fields. It explicitly mentions what fields are searched (entity names, types, subdomains, observation content), which differentiates it from tools like 'open_nodes' or 'read_graph'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool: when searching for nodes by keywords across specific entity fields. It does not explicitly state when not to use it or name alternatives among siblings, but the context is sufficient for an agent to infer this is for keyword-based searches rather than other operations like creation or deletion.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/yodakeisuke/mcp-memory-domain-knowledge'

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