Skip to content

Commit 3f5a1ff

Browse files
authored
Merge pull request #5349 from modelcontextprotocol/v2/feat/5153-memory-idempotent-hints
feat(memory): declare idempotentHint on create_entities, create_relations and add_observations
2 parents 163be11 + a41492e commit 3f5a1ff

3 files changed

Lines changed: 35 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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ const statusOutputSchema = {
101101
additionalProperties: false,
102102
};
103103

104+
// create_entities, create_relations and add_observations skip what is already
105+
// stored, so repeating a call with the same arguments changes nothing (#5153).
104106
const writeAnnotations = {
105107
readOnlyHint: false,
106108
destructiveHint: false,
107-
idempotentHint: false,
109+
idempotentHint: true,
108110
openWorldHint: false,
109111
};
110112
const deleteAnnotations = {
@@ -446,6 +448,30 @@ describe("memory tools over the protocol", () => {
446448
expect(tools).toEqual(expectedTools);
447449
});
448450

451+
// The idempotentHint the three write tools declare: a repeat of the same
452+
// call leaves the graph as the first call left it (#5153).
453+
it("changes nothing when a write tool is repeated with the same arguments (#5153)", async () => {
454+
const calls: [string, Record<string, unknown>][] = [
455+
["create_entities", { entities: [alice, bob] }],
456+
["create_relations", { relations: [aliceKnowsBob] }],
457+
[
458+
"add_observations",
459+
{ observations: [{ entityName: "Bob", contents: ["plays chess"] }] },
460+
],
461+
];
462+
for (const [name, args] of calls) {
463+
expect((await call(client, name, args)).isError).toBeUndefined();
464+
}
465+
// Compare around each repeat on its own, so a later repeat cannot mask
466+
// a change an earlier one made.
467+
for (const [name, args] of calls) {
468+
const before = await readGraph();
469+
const repeat = await call(client, name, args);
470+
expect(repeat.isError).toBeUndefined();
471+
expect(await readGraph()).toEqual(before);
472+
}
473+
});
474+
449475
it("offers no prompts", async () => {
450476
// A raw request: SDK v2's listPrompts() answers an empty list without
451477
// 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
@@ -968,7 +968,7 @@ export function createServer(
968968
annotations: {
969969
readOnlyHint: false,
970970
destructiveHint: false,
971-
idempotentHint: false,
971+
idempotentHint: true,
972972
openWorldHint: false,
973973
},
974974
},
@@ -1013,7 +1013,7 @@ export function createServer(
10131013
annotations: {
10141014
readOnlyHint: false,
10151015
destructiveHint: false,
1016-
idempotentHint: false,
1016+
idempotentHint: true,
10171017
openWorldHint: false,
10181018
},
10191019
},
@@ -1059,7 +1059,7 @@ export function createServer(
10591059
annotations: {
10601060
readOnlyHint: false,
10611061
destructiveHint: false,
1062-
idempotentHint: false,
1062+
idempotentHint: true,
10631063
openWorldHint: false,
10641064
},
10651065
},

0 commit comments

Comments
 (0)