Skip to main content
Glama

update_relation

Modify existing relationships in a knowledge graph by adjusting properties like strength, confidence, metadata, or temporal validity to maintain accurate and current connections between entities.

Instructions

Update an existing relation with enhanced properties in your Memento MCP knowledge graph memory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relationYes

Implementation Reference

  • Registration of the 'update_relation' tool including its name, description, and input schema
    {
      name: 'update_relation',
      description:
        'Update an existing relation with enhanced properties in your Memento MCP knowledge graph memory',
      inputSchema: {
        type: 'object',
        properties: {
          relation: {
            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',
              },
              strength: {
                type: 'number',
                description: 'Optional strength of relation (0.0 to 1.0)',
              },
              confidence: {
                type: 'number',
                description: 'Optional confidence level in relation accuracy (0.0 to 1.0)',
              },
              metadata: {
                type: 'object',
                description:
                  'Optional metadata about the relation (source, timestamps, tags, etc.)',
                additionalProperties: true,
              },
              // Temporal fields - optional
              id: { type: 'string', description: 'Optional relation ID' },
              version: { type: 'number', description: 'Optional relation version' },
              createdAt: { type: 'number', description: 'Optional creation timestamp' },
              updatedAt: { type: 'number', description: 'Optional update timestamp' },
              validFrom: { type: 'number', description: 'Optional validity start timestamp' },
              validTo: { type: 'number', description: 'Optional validity end timestamp' },
              changedBy: { type: 'string', description: 'Optional user/system identifier' },
            },
            required: ['from', 'to', 'relationType'],
          },
        },
        required: ['relation'],
      },
    },
  • Handler logic for executing the 'update_relation' tool by delegating to KnowledgeGraphManager.updateRelation
    case 'update_relation':
      await knowledgeGraphManager.updateRelation(args.relation);
      return { content: [{ type: 'text', text: 'Relation updated successfully' }] };
  • Core updateRelation method in KnowledgeGraphManager that delegates to storage provider or uses file-based fallback
    async updateRelation(relation: Relation): Promise<Relation> {
      if (this.storageProvider && hasUpdateRelation(this.storageProvider)) {
        // Cast to the extended interface to access the method
        const provider = this.storageProvider as unknown as StorageProviderWithUpdateRelation;
        return provider.updateRelation(relation);
      }
    
      // Fallback implementation
      const graph = await this.loadGraph();
    
      // Find the relation to update
      const index = graph.relations.findIndex(
        (r) =>
          r.from === relation.from && r.to === relation.to && r.relationType === relation.relationType
      );
    
      if (index === -1) {
        throw new Error(
          `Relation from '${relation.from}' to '${relation.to}' of type '${relation.relationType}' not found`
        );
      }
    
      // Update the relation
      graph.relations[index] = relation;
    
      // Save the updated graph
      await this.saveGraph(graph);
    
      return relation;
    }

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/gannonh/memento-mcp'

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