Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

add_observations

Enhance entities in the MCP DuckDB Knowledge Graph by adding new observations, allowing for enriched and updated data storage for improved query performance and conversation context.

Instructions

Add new observations to existing entities in the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
observationsYes

Implementation Reference

  • Core handler function that adds new observations to existing entities in the DuckDB database, deduplicates them, handles transactions, and updates the search index.
    async addObservations( observations: Array<Observation> ): Promise<Observation[]> { const addedObservations: Observation[] = []; using conn = await this.getConn(); try { // Begin transaction await conn.execute("BEGIN TRANSACTION"); // Process each observation for (const observation of observations) { // Check if entity exists const entityReader = await conn.executeAndReadAll( "SELECT name FROM entities WHERE name = ?", [observation.entityName as string] ); const entityRows = entityReader.getRows(); // Confirm existence by row count // If entity exists if (entityRows.length > 0) { // Get existing observations const existingObservationsReader = await conn.executeAndReadAll( "SELECT content FROM observations WHERE entityName = ?", [observation.entityName as string] ); const existingObservationsData = existingObservationsReader.getRows(); const contentColumnIndex = 0; // content column is the first column const existingObservations = new Set( existingObservationsData.map( (row: any) => row[contentColumnIndex] as string ) ); // Filter new observations const newContents = observation.contents.filter( (content) => !existingObservations.has(content) ); // Insert new observations if (newContents.length > 0) { for (const content of newContents) { await conn.execute( "INSERT INTO observations (entityName, content) VALUES (?, ?)", [observation.entityName, content] ); } addedObservations.push({ entityName: observation.entityName, contents: newContents, }); } } } // Commit transaction await conn.execute("COMMIT"); // Update Fuse.js index const allEntities = await this.getAllEntities(); this.fuse.setCollection(allEntities); return addedObservations; } catch (error: unknown) { // Rollback in case of error await conn.execute("ROLLBACK"); this.logger.error("Error adding observations", extractError(error)); throw error; } }
  • src/server.ts:66-86 (registration)
    Registers the MCP tool 'add_observations' with input schema and thin handler delegating to KnowledgeGraphManager.addObservations.
    server.tool( "add_observations", "Add new observations to existing entities in the knowledge graph", { observations: z .array(ObservationObject) .describe("An array of observations to add"), }, async ({ observations }) => ({ content: [ { type: "text", text: JSON.stringify( await knowledgeGraphManager.addObservations(observations), null, 2 ), }, ], }) );
  • Zod schema definition for the Observation input type used by the 'add_observations' tool.
    export const ObservationObject = z.object({ entityName: z .string() .describe("The name of the entity to add the observations to"), contents: z .array(z.string()) .describe("An array of observation contents to add"), }); export type Observation = z.infer<typeof ObservationObject>;

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