Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

search_nodes

Find knowledge graph nodes by searching entity names, types, or observation content to retrieve relevant information from stored data.

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 core handler function for searching nodes using Fuse.js fuzzy search on entity names, types, and observations, then retrieving related relations from DuckDB.
    async searchNodes(query: string): Promise<KnowledgeGraph> {
      if (!query || query.trim() === "") {
        return { entities: [], relations: [] };
      }
    
      // Get all entities
      const allEntities = await this.getAllEntities();
    
      // Update Fuse.js collection
      this.fuse.setCollection(allEntities);
    
      // Execute search
      const results = this.fuse.search(query);
    
      // Extract entities from search results (remove duplicates)
      const uniqueEntities = new Map<string, Entity>();
      for (const result of results) {
        if (!uniqueEntities.has(result.item.name)) {
          uniqueEntities.set(result.item.name, result.item);
        }
      }
    
      const entities = Array.from(uniqueEntities.values());
    
      // Create a set of entity names
      const entityNames = entities.map((entity) => entity.name);
    
      if (entityNames.length === 0) {
        return { entities: [], relations: [] };
      }
    
      // Create placeholders
      const placeholders = entityNames.map(() => "?").join(",");
    
      using conn = await this.getConn();
    
      // Get related relations
      const relationsReader = await conn.executeAndReadAll(
        `
        SELECT from_entity as "from", to_entity as "to", relationType
        FROM relations
        WHERE from_entity IN (${placeholders})
        OR to_entity IN (${placeholders})
        `,
        [...entityNames, ...entityNames]
      );
      const relationsData = relationsReader.getRows();
    
      // Convert results to an array of Relation objects
      const relations = relationsData.map((row: any) => {
        return {
          from: row[0] as string,
          to: row[1] as string,
          relationType: row[2] as string,
        };
      });
    
      return {
        entities,
        relations,
      };
    }
  • src/server.ts:159-181 (registration)
    Registers the 'search_nodes' tool with the MCP server, defining its name, description, input schema (query string), and handler that delegates to the manager.
    server.tool(
      "search_nodes",
      "Search for nodes in the knowledge graph based on a query",
      {
        query: z
          .string()
          .describe(
            "The search query to match against entity names, types, and observation content"
          ),
      },
      async ({ query }) => ({
        content: [
          {
            type: "text",
            text: JSON.stringify(
              await knowledgeGraphManager.searchNodes(query),
              null,
              2
            ),
          },
        ],
      })
    );
  • TypeScript interface defining the KnowledgeGraphManagerInterface, including the searchNodes method signature for type safety.
    export type KnowledgeGraphManagerInterface = {
      createEntities(entities: Entity[]): Promise<Entity[]>;
      createRelations(relations: Relation[]): Promise<Relation[]>;
      addObservations(observations: Array<Observation>): Promise<Observation[]>;
      deleteEntities(entityNames: string[]): Promise<void>;
      deleteObservations(deletions: Array<Observation>): Promise<void>;
      deleteRelations(relations: Relation[]): Promise<void>;
      searchNodes(query: string): Promise<KnowledgeGraph>;
      openNodes(names: string[]): Promise<KnowledgeGraph>;
    };
  • Type definition for KnowledgeGraph, the return type of searchNodes.
    export type KnowledgeGraph = {
      entities: Entity[];
      relations: Relation[];
    };
Behavior2/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 of behavioral disclosure. It states the tool searches nodes but doesn't describe what 'search' entails—e.g., whether it returns partial matches, supports pagination, has rate limits, or requires authentication. For a search tool with zero annotation coverage, this is a significant gap in transparency.

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

Conciseness4/5

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

The description is a single, clear sentence with no wasted words, making it appropriately concise. It front-loads the core purpose effectively, though it could be slightly more structured by including usage context.

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 the complexity of a search operation with no annotations and no output schema, the description is incomplete. It doesn't explain what 'nodes' are in this context, how results are returned, or any behavioral traits like error handling. For a tool that likely returns multiple results, more context is needed to guide the agent 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?

The description mentions 'based on a query', which aligns with the single parameter 'query' in the input schema. Since schema description coverage is 100% (the schema describes the query parameter well), the description adds minimal value beyond what the schema provides. This meets the baseline score when schema coverage is high.

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 tool's purpose as 'Search for nodes in the knowledge graph based on a query', which includes a specific verb ('Search'), resource ('nodes in the knowledge graph'), and mechanism ('based on a query'). However, it doesn't explicitly differentiate from sibling tools like 'open_nodes' which might also retrieve nodes, so it doesn't reach the highest score.

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. It doesn't mention sibling tools like 'open_nodes' (which might retrieve specific nodes by ID) or 'create_entities' (which adds nodes), nor does it specify prerequisites or exclusions. This leaves the agent with minimal context for tool selection.

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/IzumiSy/mcp-duckdb-memory-server'

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