delete_relations
Remove multiple connections between entities in the Obsidian knowledge graph to maintain accurate relationship data.
Instructions
Delete multiple relations from the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes | An array of relations to delete |
Implementation Reference
- The primary handler implementing the deletion logic by updating source entity Markdown files.async deleteRelations(relations: Relation[]): Promise<void> { for (const relation of relations) { const fromPath = getEntityPath(relation.from); try { const content = await fs.readFile(fromPath, 'utf-8'); const updatedContent = removeRelationFromContent(content, relation); await fs.writeFile(fromPath, updatedContent, 'utf-8'); } catch (error) { if (error instanceof Error && 'code' in error && (error as any).code !== 'ENOENT') { throw new Error(`Failed to delete relation from ${relation.from}: ${error}`); } } } }
- utils/markdownUtils.ts:202-209 (helper)Core utility that removes the specific relation wiki-link from Markdown content using regex.export function removeRelationFromContent(content: string, relation: Relation): string { const linkPattern = new RegExp( `^[\\s\\-\\*]*\\[\\[${escapeRegExp(relation.relationType)}::${escapeRegExp(relation.to)}\\]\\]\\s*$`, 'gm' ); return content.replace(linkPattern, ''); }
- index.ts:223-225 (handler)MCP server-side tool handler dispatching to storage manager.case "delete_relations": await storageManager.deleteRelations(args.relations as Relation[]); return { content: [{ type: "text", text: "Relations deleted successfully" }] };
- index.ts:142-164 (registration)Registers the tool in the MCP server's tool list with description and input 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"], }, },
- index.ts:145-162 (schema)Defines the input schema for the delete_relations tool, specifying the structure of relations array.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"],