Skip to main content
Glama
IzumiSy

MCP DuckDB Knowledge Graph Memory Server

create_relations

Adds multiple connections between entities in a knowledge graph using active voice relations to enhance data relationships and query capabilities.

Instructions

Create multiple new relations between entities in the knowledge graph. Relations should be in active voice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relationsYesAn array of relations to create

Implementation Reference

  • The core handler function in DuckDBKnowledgeGraphManager that implements the logic for creating relations: validates entity existence, deduplicates against existing relations, and inserts new ones into the DuckDB 'relations' table using transactions.
    async createRelations(relations: Relation[]): Promise<Relation[]> {
      using conn = await this.getConn();
    
      try {
        // Begin transaction
        await conn.execute("BEGIN TRANSACTION");
    
        // Get the set of entity names
        const entityNamesReader = await conn.executeAndReadAll(
          "SELECT name FROM entities"
        );
        const entityNamesData = entityNamesReader.getRows();
        const nameColumnIndex = 0; // name column is the first column
        const entityNames = new Set(
          entityNamesData.map((row: any) => row[nameColumnIndex] as string)
        );
    
        // Filter valid relations (both from and to entities must exist)
        const validRelations = relations.filter(
          (relation) =>
            entityNames.has(relation.from) && entityNames.has(relation.to)
        );
    
        // Get existing relations
        const existingRelationsReader = await conn.executeAndReadAll(
          'SELECT from_entity as "from", to_entity as "to", relationType FROM relations'
        );
        const existingRelationsData = existingRelationsReader.getRows();
    
        // Convert results to an array of Relation objects
        const existingRelations = existingRelationsData.map((row: any) => {
          return {
            from: row[0] as string,
            to: row[1] as string,
            relationType: row[2] as string,
          };
        });
    
        // Filter new relations
        const newRelations = validRelations.filter(
          (newRel) =>
            !existingRelations.some(
              (existingRel: any) =>
                existingRel.from === newRel.from &&
                existingRel.to === newRel.to &&
                existingRel.relationType === newRel.relationType
            )
        );
    
        // Insert new relations
        for (const relation of newRelations) {
          await conn.execute(
            "INSERT INTO relations (from_entity, to_entity, relationType) VALUES (?, ?, ?)",
            [relation.from, relation.to, relation.relationType]
          );
        }
    
        // Commit transaction
        await conn.execute("COMMIT");
    
        return newRelations;
      } catch (error: unknown) {
        // Rollback in case of error
        await conn.execute("ROLLBACK");
        this.logger.error("Error creating relations", extractError(error));
        throw error;
      }
    }
  • src/server.ts:43-63 (registration)
    Registers the MCP tool 'create_relations' with input schema validation using Zod (array of RelationObject) and a handler that delegates to the knowledgeGraphManager.createRelations method.
    server.tool(
      "create_relations",
      "Create multiple new relations between entities in the knowledge graph. Relations should be in active voice",
      {
        relations: z
          .array(RelationObject)
          .describe("An array of relations to create"),
      },
      async ({ relations }) => ({
        content: [
          {
            type: "text",
            text: JSON.stringify(
              await knowledgeGraphManager.createRelations(relations),
              null,
              2
            ),
          },
        ],
      })
    );
  • Zod schema (RelationObject) and TypeScript type (Relation) definitions for the input parameter used in create_relations tool.
    export const RelationObject = z.object({
      from: z.string().describe("The name of the entity where the relation starts"),
      to: z.string().describe("The name of the entity where the relation ends"),
      relationType: z.string().describe("The type of the relation"),
    });
    export type Relation = {
      from: string;
      to: string;
      relationType: string;
    };
  • Interface definition in KnowledgeGraphManagerInterface for the createRelations method signature.
    createRelations(relations: Relation[]): Promise<Relation[]>;
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states this is a creation operation ('Create multiple new relations'), implying mutation, but doesn't disclose behavioral traits like permissions needed, whether it's idempotent, error handling, or what happens on conflicts. The 'active voice' note is minor and doesn't address core behavioral aspects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. The 'active voice' note is arguably extraneous but doesn't significantly detract. It's appropriately sized for a tool with a clear primary function.

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 no annotations and no output schema, the description is incomplete for a mutation tool. It doesn't explain what the tool returns, error conditions, or side effects. For creating multiple relations in a knowledge graph—a potentially complex operation—more context is needed to guide an agent effectively.

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 the single parameter 'relations' and its nested properties well-documented in the schema. The description adds no parameter semantics beyond what the schema provides, such as examples or constraints on 'relationType'. 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 ('Create multiple new relations') and the target resource ('between entities in the knowledge graph'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'create_entities' or 'delete_relations', though the 'multiple new relations' phrasing hints at its scope.

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 mentions 'relations should be in active voice', which is a stylistic constraint but not a usage guideline. There's no indication of prerequisites, when not to use it, or how it relates to siblings like 'create_entities' or 'delete_relations'.

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