Skip to content

Commit d7ebd6f

Browse files
cliffhallclaude
andcommitted
feat(memory): declare idempotentHint on the three create/add tools
create_entities, create_relations and add_observations already skip what is stored, so repeating a call with the same arguments has no additional effect on the graph. Declare idempotentHint: true, as the delete tools do, update the annotations fixture, and add a protocol-level test that a repeat of each call leaves the graph unchanged. Closes #5153 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 446be48 commit d7ebd6f

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-memory": patch
3+
---
4+
5+
`create_entities`, `create_relations` and `add_observations` now declare `idempotentHint: true`. Each already skips what is stored, so repeating a call with the same arguments has no additional effect on the graph, as with the delete tools.

‎src/memory/__tests__/tools.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ const statusOutputSchema = {
6868
additionalProperties: false,
6969
};
7070

71+
// create_entities, create_relations and add_observations skip what is already
72+
// stored, so repeating a call with the same arguments changes nothing (#5153).
7173
const writeAnnotations = {
7274
readOnlyHint: false,
7375
destructiveHint: false,
74-
idempotentHint: false,
76+
idempotentHint: true,
7577
openWorldHint: false,
7678
};
7779
const deleteAnnotations = {
@@ -392,6 +394,28 @@ describe("memory tools over the protocol", () => {
392394
expect(tools).toEqual(expectedTools);
393395
});
394396

397+
// The idempotentHint the three write tools declare: a repeat of the same
398+
// call leaves the graph as the first call left it (#5153).
399+
it("changes nothing when a write tool is repeated with the same arguments (#5153)", async () => {
400+
const calls: [string, Record<string, unknown>][] = [
401+
["create_entities", { entities: [alice, bob] }],
402+
["create_relations", { relations: [aliceKnowsBob] }],
403+
[
404+
"add_observations",
405+
{ observations: [{ entityName: "Bob", contents: ["plays chess"] }] },
406+
],
407+
];
408+
for (const [name, args] of calls) {
409+
await call(client, name, args);
410+
}
411+
const once = await readGraph();
412+
for (const [name, args] of calls) {
413+
const repeat = await call(client, name, args);
414+
expect(repeat.isError).toBeUndefined();
415+
}
416+
expect(await readGraph()).toEqual(once);
417+
});
418+
395419
it("offers no prompts", async () => {
396420
// A raw request: SDK v2's listPrompts() answers an empty list without
397421
// asking a server that does not advertise prompts.

‎src/memory/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ export function createServer(
853853
annotations: {
854854
readOnlyHint: false,
855855
destructiveHint: false,
856-
idempotentHint: false,
856+
idempotentHint: true,
857857
openWorldHint: false,
858858
},
859859
},
@@ -898,7 +898,7 @@ export function createServer(
898898
annotations: {
899899
readOnlyHint: false,
900900
destructiveHint: false,
901-
idempotentHint: false,
901+
idempotentHint: true,
902902
openWorldHint: false,
903903
},
904904
},
@@ -944,7 +944,7 @@ export function createServer(
944944
annotations: {
945945
readOnlyHint: false,
946946
destructiveHint: false,
947-
idempotentHint: false,
947+
idempotentHint: true,
948948
openWorldHint: false,
949949
},
950950
},

0 commit comments

Comments
 (0)