Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

create_entities

Add multiple entities to a knowledge graph with specified names, types, and associated observations to enhance memory and query capabilities in DuckDB-based systems.

Instructions

Create multiple new entities in the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entitiesYes

Implementation Reference

  • The inline asynchronous handler function for the 'create_entities' MCP tool. It receives the entities input, calls knowledgeGraphManager.createEntities, stringifies the result as JSON, and returns it formatted as MCP text content.
    async ({ entities }) => ({ content: [ { type: "text", text: JSON.stringify( await knowledgeGraphManager.createEntities(entities), null, 2 ), }, ], })
  • Zod schema definition for EntityObject, used in the input schema for the create_entities tool (entities: z.array(EntityObject)).
    export const EntityObject = z.object({ name: z.string().describe("The name of the entity"), entityType: z.string().describe("The type of the entity"), observations: z .array(z.string()) .describe("An array of observation contents associated with the entity"), });
  • src/server.ts:20-40 (registration)
    MCP server.tool registration for the 'create_entities' tool, including name, description, input schema, and handler.
    server.tool( "create_entities", "Create multiple new entities in the knowledge graph", { entities: z .array(EntityObject) .describe("An array of entities to create"), }, async ({ entities }) => ({ content: [ { type: "text", text: JSON.stringify( await knowledgeGraphManager.createEntities(entities), null, 2 ), }, ], }) );
  • Core implementation of createEntities in DuckDBKnowledgeGraphManager class. Filters new entities, performs transactional inserts into entities and observations tables, updates Fuse.js search index, with error handling and rollback.
    async createEntities(entities: Entity[]): Promise<Entity[]> { const createdEntities: Entity[] = []; using conn = await this.getConn(); try { // Begin transaction await conn.execute("BEGIN TRANSACTION"); // Get existing entity names const existingEntitiesReader = await conn.executeAndReadAll( "SELECT name FROM entities" ); const existingEntitiesData = existingEntitiesReader.getRows(); const nameColumnIndex = 0; // name column is the first column const existingNames = new Set( existingEntitiesData.map((row: any) => row[nameColumnIndex] as string) ); // Filter new entities const newEntities = entities.filter( (entity) => !existingNames.has(entity.name) ); // Insert new entities for (const entity of newEntities) { // Insert entity await conn.execute( "INSERT INTO entities (name, entityType) VALUES (?, ?)", [entity.name, entity.entityType] ); // Insert observations for (const observation of entity.observations) { await conn.execute( "INSERT INTO observations (entityName, content) VALUES (?, ?)", [entity.name, observation] ); } createdEntities.push(entity); } // Commit transaction await conn.execute("COMMIT"); // Update Fuse.js index const allEntities = await this.getAllEntities(); this.fuse.setCollection(allEntities); return createdEntities; } catch (error: unknown) { // Rollback in case of error await conn.execute("ROLLBACK"); this.logger.error("Error creating entities", extractError(error)); throw error; } }

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