|
| 1 | +// What the delete_entities and delete_relations descriptions tell a model |
| 2 | +// (#5071). Both tools are destructive and share the same annotations, so the |
| 3 | +// description is the only place the difference between them lives: each one |
| 4 | +// names its sibling, and delete_relations states the exact-match rule that |
| 5 | +// otherwise turns a guessed relationType into "Deleted 0 of 1". These tests |
| 6 | +// read the descriptions through tools/list, check that every tool they point |
| 7 | +// to is registered, and check the behavior each one states. |
| 8 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
| 9 | +import type { Tool } from "@modelcontextprotocol/client"; |
| 10 | +import { call, connect, makeTempGraph } from "./helpers.js"; |
| 11 | +import type { Connection } from "./helpers.js"; |
| 12 | + |
| 13 | +let conn: Connection; |
| 14 | +let cleanup: () => Promise<void>; |
| 15 | +let tools: Tool[]; |
| 16 | + |
| 17 | +beforeEach(async () => { |
| 18 | + const graph = await makeTempGraph(); |
| 19 | + cleanup = graph.cleanup; |
| 20 | + conn = await connect(graph.filePath); |
| 21 | + ({ tools } = await conn.client.listTools()); |
| 22 | +}); |
| 23 | + |
| 24 | +afterEach(async () => { |
| 25 | + await conn.close(); |
| 26 | + await cleanup(); |
| 27 | +}); |
| 28 | + |
| 29 | +function descriptionOf(name: string): string { |
| 30 | + const description = tools.find((t) => t.name === name)?.description; |
| 31 | + if (description === undefined) throw new Error(`no description: ${name}`); |
| 32 | + return description; |
| 33 | +} |
| 34 | + |
| 35 | +async function seed(): Promise<void> { |
| 36 | + await call(conn.client, "create_entities", { |
| 37 | + entities: [ |
| 38 | + { name: "Alice", entityType: "person", observations: ["likes tea"] }, |
| 39 | + { name: "Acme", entityType: "company", observations: [] }, |
| 40 | + ], |
| 41 | + }); |
| 42 | + await call(conn.client, "create_relations", { |
| 43 | + relations: [{ from: "Alice", to: "Acme", relationType: "works at" }], |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +describe("delete tool descriptions (#5071)", () => { |
| 48 | + it("delete_entities names delete_relations and delete_observations", () => { |
| 49 | + const description = descriptionOf("delete_entities"); |
| 50 | + expect(description).toContain("use delete_relations"); |
| 51 | + expect(description).toContain("use delete_observations"); |
| 52 | + expect(description).toContain( |
| 53 | + "every relation that points to or from them and all their observations", |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it("delete_relations names delete_entities and states the exact-match rule", () => { |
| 58 | + const description = descriptionOf("delete_relations"); |
| 59 | + expect(description).toContain("use delete_entities"); |
| 60 | + expect(description).toContain("keep the entities they connect"); |
| 61 | + expect(description).toContain("exactly on all three fields"); |
| 62 | + expect(description).toContain("call open_nodes (or search_nodes) first"); |
| 63 | + }); |
| 64 | + |
| 65 | + it("names only tools the server registers", () => { |
| 66 | + const names = new Set(tools.map((t) => t.name)); |
| 67 | + for (const tool of ["delete_entities", "delete_relations"]) { |
| 68 | + for (const named of descriptionOf(tool).match(/\b[a-z]+_[a-z_]+\b/g) ?? |
| 69 | + []) { |
| 70 | + expect(names, `${tool} names ${named}`).toContain(named); |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + it("delete_entities removes the entity's relations too", async () => { |
| 76 | + await seed(); |
| 77 | + await call(conn.client, "delete_entities", { entityNames: ["Acme"] }); |
| 78 | + const graph = await call(conn.client, "read_graph"); |
| 79 | + expect(graph.structuredContent).toMatchObject({ |
| 80 | + entities: [{ name: "Alice" }], |
| 81 | + relations: [], |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it("delete_relations deletes only an exact match and keeps the entities", async () => { |
| 86 | + await seed(); |
| 87 | + const miss = await call(conn.client, "delete_relations", { |
| 88 | + relations: [{ from: "Alice", to: "Acme", relationType: "works_at" }], |
| 89 | + }); |
| 90 | + expect(miss.structuredContent).toMatchObject({ success: true }); |
| 91 | + expect( |
| 92 | + (await call(conn.client, "read_graph")).structuredContent, |
| 93 | + ).toMatchObject({ relations: [{ relationType: "works at" }] }); |
| 94 | + |
| 95 | + await call(conn.client, "delete_relations", { |
| 96 | + relations: [{ from: "Alice", to: "Acme", relationType: "works at" }], |
| 97 | + }); |
| 98 | + expect( |
| 99 | + (await call(conn.client, "read_graph")).structuredContent, |
| 100 | + ).toMatchObject({ |
| 101 | + entities: [{ name: "Alice" }, { name: "Acme" }], |
| 102 | + relations: [], |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
0 commit comments