Skip to main content
Glama

MCP DuckDB Knowledge Graph Memory Server

search_nodes

Query the knowledge graph to find nodes matching specific names, types, or content, enabling efficient retrieval of structured information stored in DuckDB.

Instructions

Search for nodes in the knowledge graph based on a query

Input Schema

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "query": { "description": "The search query to match against entity names, types, and observation content", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • The core handler function `searchNodes` that performs fuzzy search using Fuse.js on all entities, extracts unique matching entities, and retrieves their related relations from the database.
    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:158-181 (registration)
    Registers the 'search_nodes' tool with server.tool, providing description, input schema, and a thin handler that delegates to knowledgeGraphManager.searchNodes and formats the response as JSON text.
    // Search nodes tool 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 ), }, ], }) );
  • Zod input schema defining the 'query' parameter as a string with description.
    { query: z .string() .describe( "The search query to match against entity names, types, and observation content" ), },
  • TypeScript interface definition for KnowledgeGraphManager, including the searchNodes method signature.
    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>; };

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

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