Skip to main content
Glama
modelcontextprotocol

Knowledge Graph Memory Server

search_nodes

Find nodes in the knowledge graph by matching names, types, or content with your search query, enabling precise information retrieval across chats.

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

  • Core handler function implementing the search_nodes tool logic in KnowledgeGraphManager. Filters knowledge graph entities matching the query in name, type, or observations (case-insensitive), and includes relations connecting those entities.
    async searchNodes(query: string): Promise<KnowledgeGraph> {
      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: KnowledgeGraph = {
        entities: filteredEntities,
        relations: filteredRelations,
      };
    
      return filteredGraph;
    }
  • Registration of the search_nodes MCP tool, including schema definition and thin wrapper handler that invokes the core searchNodes method and formats the output.
    server.registerTool(
      "search_nodes",
      {
        title: "Search Nodes",
        description: "Search for nodes in the knowledge graph based on a query",
        inputSchema: {
          query: z.string().describe("The search query to match against entity names, types, and observation content")
        },
        outputSchema: {
          entities: z.array(EntitySchema),
          relations: z.array(RelationSchema)
        }
      },
      async ({ query }) => {
        const graph = await knowledgeGraphManager.searchNodes(query);
        return {
          content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }],
          structuredContent: { ...graph }
        };
      }
    );
  • Schema for search_nodes tool: input is a query string, output is a KnowledgeGraph with arrays of entities and relations using shared EntitySchema and RelationSchema.
    {
      title: "Search Nodes",
      description: "Search for nodes in the knowledge graph based on a query",
      inputSchema: {
        query: z.string().describe("The search query to match against entity names, types, and observation content")
      },
      outputSchema: {
        entities: z.array(EntitySchema),
        relations: z.array(RelationSchema)
      }
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states it 'searches for nodes' but doesn't disclose behavioral traits like whether this is a read-only operation, what happens with no matches, performance characteristics, or return format. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 a single, efficient sentence with zero wasted words. It's appropriately sized for a simple search tool and front-loads the core functionality. Every word earns its place in conveying the essential purpose.

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

Completeness2/5

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

Given no annotations, no output schema, and multiple sibling tools with overlapping functionality, the description is incomplete. It doesn't explain what constitutes a 'node', what search results look like, how results are ranked/limited, or when to choose this over other graph access tools. For a search operation in a knowledge graph context, more contextual information would be helpful.

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 fully documents the single 'query' parameter. The description mentions 'based on a query' but adds no additional meaning beyond what the schema provides about what the query matches against. Baseline 3 is appropriate when the schema does all the parameter documentation work.

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

Purpose4/5

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

The description clearly states the verb ('search') and resource ('nodes in the knowledge graph') with the purpose being 'based on a query'. It's specific about what the tool does but doesn't explicitly differentiate from sibling tools like 'open_nodes' or 'read_graph' that might also retrieve node information.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'open_nodes' and 'read_graph' that likely also access node data, there's no indication of when search is appropriate versus other retrieval methods. No prerequisites, exclusions, or comparative context is mentioned.

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

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/modelcontextprotocol/knowledge-graph-memory-server'

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