Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

add_observations

Add new observations to existing entities in a knowledge graph to maintain updated information for enhanced conversation memory and query capabilities.

Instructions

Add new observations to existing entities in the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
observationsYesAn array of observations to add

Implementation Reference

  • Main handler function that executes the tool logic: adds new observations to existing entities, filters duplicates, uses database transactions, and updates 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 'add_observations' tool with MCP server, defining schema and delegating to KnowledgeGraphManager.
    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 for Observation used in the tool input (array of this). Defines input validation for entityName and contents.
    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>;
  • TypeScript interface definition for the addObservations method in KnowledgeGraphManagerInterface.
    addObservations(observations: Array<Observation>): Promise<Observation[]>;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. It states the tool adds observations to existing entities, implying a mutation operation, but lacks critical details: whether it requires specific permissions, if it's idempotent, what happens on errors (e.g., invalid entity names), or rate limits. For a mutation 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.

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without redundancy. It's front-loaded with the core action and target, making it easy to parse. Every word earns its place, with no wasted verbiage.

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 mutation tool (adding observations to a knowledge graph) with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what constitutes a valid observation, how duplicates are handled, error conditions, or the return format. For a tool that modifies data, more context is needed to ensure safe and correct usage.

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?

Schema description coverage is 100%, with clear documentation for the 'observations' array and its nested 'entityName' and 'contents' fields. The description adds no additional parameter semantics beyond what the schema provides (e.g., no examples of valid observation formats or entity naming conventions). Baseline 3 is appropriate since the schema does the heavy lifting.

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 action ('Add new observations') and target ('to existing entities in the knowledge graph'), which is specific and unambiguous. It distinguishes from siblings like 'create_entities' (creates new entities) and 'delete_observations' (removes observations). However, it doesn't explicitly contrast with 'search_nodes' or 'open_nodes', leaving some sibling differentiation incomplete.

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 prerequisites (e.g., entities must exist), exclusions (e.g., cannot create new entities), or compare to siblings like 'create_entities' for new entities or 'search_nodes' for querying. Without such context, an agent might misuse it.

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