Skip to main content
Glama
knowall-ai

Neo4j Agent Memory MCP Server

by knowall-ai

delete_connection

Remove a specific relationship between two stored memories in a Neo4j graph database, permanently deleting the connection when it's no longer needed or incorrect.

Instructions

Delete a specific connection between two memories (use with caution - this permanently removes the relationship)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromMemoryIdYesID of the source memory
toMemoryIdYesID of the target memory
typeYesExact relationship type to delete (e.g. WORKS_AT, KNOWS, MANAGES)

Implementation Reference

  • Main handler logic for the delete_connection tool: validates arguments using isDeleteConnectionArgs and calls neo4j.deleteRelationship to perform the deletion.
    case 'delete_connection': {
      if (!isDeleteConnectionArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid delete_connection arguments');
      }
      const result = await neo4j.deleteRelationship(args.fromMemoryId, args.toMemoryId, args.type);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
  • Core implementation in Neo4jClient that executes the Cypher query to delete the specific relationship between two memory nodes.
    async deleteRelationship(fromNodeId: number, toNodeId: number, relationType: string): Promise<any> {
      const result = await this.executeQuery(
        `MATCH (a)-[r:${relationType}]->(b)
         WHERE id(a) = $fromId AND id(b) = $toId
         DELETE r
         RETURN count(r) as deletedCount`,
        {
          fromId: neo4j.int(fromNodeId),
          toId: neo4j.int(toNodeId),
        }
      );
      return result[0];
    }
  • Tool registration defining the name, description, and JSON input schema for the MCP protocol.
      name: 'delete_connection',
      description: 'Delete a specific connection between two memories (use with caution - this permanently removes the relationship)',
      inputSchema: {
        type: 'object',
        properties: {
          fromMemoryId: {
            type: 'number',
            description: 'ID of the source memory',
          },
          toMemoryId: {
            type: 'number',
            description: 'ID of the target memory',
          },
          type: {
            type: 'string',
            description: 'Exact relationship type to delete (e.g. WORKS_AT, KNOWS, MANAGES)',
          },
        },
        required: ['fromMemoryId', 'toMemoryId', 'type'],
      },
    },
  • TypeScript interface defining the expected arguments for delete_connection.
    export interface DeleteConnectionArgs {
      fromMemoryId: number;
      toMemoryId: number;
      type: string;
    }
  • Type guard function for validating delete_connection arguments before execution.
    export function isDeleteConnectionArgs(args: unknown): args is DeleteConnectionArgs {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof (args as DeleteConnectionArgs).fromMemoryId === 'number' &&
        typeof (args as DeleteConnectionArgs).toMemoryId === 'number' &&
        typeof (args as DeleteConnectionArgs).type === 'string'
      );
    }

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/knowall-ai/mcp-neo4j-agent-memory'

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