Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

open_nodes

Retrieve specific knowledge graph entities by their names, enabling precise data access and enhanced query capabilities for conversation-based memory systems.

Instructions

Open specific nodes in the knowledge graph by their names

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namesYesAn array of entity names to retrieve

Implementation Reference

  • The core handler function for the 'open_nodes' tool. It queries the database to retrieve entities by names, their observations, and bidirectional relations involving those entities, constructing and returning a KnowledgeGraph object.
    async openNodes(names: string[]): Promise<KnowledgeGraph> { if (names.length === 0) { return { entities: [], relations: [] }; } try { using conn = await this.getConn(); // Create placeholders const placeholders = names.map(() => "?").join(","); // Retrieve entities and observations at once using LEFT JOIN const reader = await conn.executeAndReadAll( ` SELECT e.name, e.entityType, o.content FROM entities e LEFT JOIN observations o ON e.name = o.entityName WHERE e.name IN (${placeholders}) `, names ); const rows = reader.getRows(); // Group results by entity const entitiesMap = new Map<string, Entity>(); for (const row of rows) { const name = row[0] as string; const entityType = row[1] as string; const content = row[2] as string | null; if (!entitiesMap.has(name)) { // Create a new entity entitiesMap.set(name, { name, entityType, observations: content ? [content] : [], }); } else if (content) { // Add observation to existing entity entitiesMap.get(name)!.observations.push(content); } } const entities = Array.from(entitiesMap.values()); // Create a set of entity names const entityNames = entities.map((entity) => entity.name); // Get related relations if (entityNames.length > 0) { const placeholders = entityNames.map(() => "?").join(","); 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, }; } else { return { entities, relations: [], }; } } catch (error: unknown) { this.logger.error("Error opening nodes", extractError(error)); return { entities: [], relations: [] }; } }
  • src/server.ts:184-204 (registration)
    Registers the 'open_nodes' MCP tool, including its name, description, input schema (array of strings for names), and handler invocation via knowledgeGraphManager.openNodes, returning JSON-formatted KnowledgeGraph.
    server.tool( "open_nodes", "Open specific nodes in the knowledge graph by their names", { names: z .array(z.string()) .describe("An array of entity names to retrieve"), }, async ({ names }) => ({ content: [ { type: "text", text: JSON.stringify( await knowledgeGraphManager.openNodes(names), null, 2 ), }, ], }) );
  • TypeScript interface definition for the KnowledgeGraphManager, specifying the openNodes method signature with input (string[]) and output (Promise<KnowledgeGraph>).
    openNodes(names: string[]): Promise<KnowledgeGraph>;
  • Zod input schema validation for the 'open_nodes' tool parameters: an array of strings representing entity names.
    names: z .array(z.string()) .describe("An array of entity names to retrieve"),

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