Skip to main content
Glama
j3k0

Elasticsearch Knowledge Graph for MCP

by j3k0

delete_relations

Remove specified relationships between entities in a knowledge graph to maintain accurate and relevant data connections. Supports optional memory zone targeting for precise deletions.

Instructions

Delete relationships from knowledge graph (memory)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_zoneNoOptional memory zone specifier. If provided, relations will be deleted from this zone.
relationsYesList of relations to delete

Implementation Reference

  • Core handler implementation in KnowledgeGraphClient that deletes the Elasticsearch document for the specified relation using its constructed ID.
    async deleteRelation(
      from: string, 
      to: string, 
      relationType: string, 
      fromZone?: string, 
      toZone?: string
    ): Promise<boolean> {
      await this.initialize();
      
      const actualFromZone = fromZone || this.defaultZone;
      const actualToZone = toZone || this.defaultZone;
      
      try {
        const relationId = `relation:${actualFromZone}:${from}:${relationType}:${actualToZone}:${to}`;
        
        await this.client.delete({
          index: KG_RELATIONS_INDEX,
          id: relationId,
          refresh: true
        });
        
        return true;
      } catch (error) {
        if (error.statusCode === 404) {
          return false;
        }
        throw error;
      }
    }
  • MCP server tool dispatch handler that loops over input relations and calls the core deleteRelation method.
    else if (toolName === "delete_relations") {
      const relations = params.relations;
      const zone = params.memory_zone;
      const results = [];
      
      // Delete each relation individually
      for (const relation of relations) {
        const success = await kgClient.deleteRelation(
          relation.from, 
          relation.to, 
          relation.type,
          zone,
          zone
        );
        results.push({ 
          from: relation.from, 
          to: relation.to, 
          type: relation.type,
          deleted: success 
        });
      }
      
      return formatResponse({
        success: true,
        results
      });
    }
  • src/index.ts:297-323 (registration)
    Tool registration including name, description, and input schema in the ListToolsRequestSchema response.
    name: "delete_relations",
    description: "Delete relationships from knowledge graph (memory)",
    inputSchema: {
      type: "object",
      properties: {
        relations: {
          type: "array",
          description: "List of relations to delete",
          items: {
            type: "object",
            properties: {
              from: {type: "string", description: "Source entity name"},
              to: {type: "string", description: "Target entity name"},
              type: {type: "string", description: "Relationship type"}
            },
            required: ["from", "to", "type"]
          }
        },
        memory_zone: {
          type: "string",
          description: "Optional memory zone specifier. If provided, relations will be deleted from this zone."
        }
      },
      required: ["relations"],
      additionalProperties: false,
      "$schema": "http://json-schema.org/draft-07/schema#"
    }
  • Legacy file-based handler in KnowledgeGraphManager that filters and removes matching relations from the in-memory graph and persists to file.
    async deleteRelations(relations: Relation[]): Promise<void> {
      const graph = await this.loadGraph();
      graph.relations = graph.relations.filter(r => !relations.some(delRelation => 
        r.from === delRelation.from && 
        r.to === delRelation.to && 
        r.relationType === delRelation.relationType
      ));
      await this.saveGraph(graph);
    }
  • Legacy tool registration and schema.
    {
      name: "delete_relations",
      description: "Delete multiple relations from the knowledge graph",
      inputSchema: {
        type: "object",
        properties: {
          relations: { 
            type: "array", 
            items: {
              type: "object",
              properties: {
                from: { type: "string", description: "The name of the entity where the relation starts" },
                to: { type: "string", description: "The name of the entity where the relation ends" },
                relationType: { type: "string", description: "The type of the relation" },
              },
              required: ["from", "to", "relationType"],
            },
            description: "An array of relations to delete" 
          },
        },
        required: ["relations"],
      },
    },
Install Server

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/j3k0/mcp-brain-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server