Skip to content

Commit 31f5bb4

Browse files
feat(memory): sharpen MCP tool descriptions for reliable invocation (#399)
1 parent 05aa14e commit 31f5bb4

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎packages/memory/src/server.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ type ToolResponse = {
2525
const STORE_TOOL = {
2626
name: "memory_storeKnowledge",
2727
description:
28-
"Persist verified, reusable knowledge for future sessions. After completing meaningful work, store decisions, conventions, gotchas, or fixes that a future agent would otherwise rediscover the hard way (e.g. 'This repo pins better-sqlite3 to 12.x; native builds fail on newer versions'). Prefer updating an existing item over storing a near-duplicate.",
28+
"AFTER completing a task — and especially right after fixing an error, discovering a gotcha, or making a decision a future agent would otherwise rediscover the hard way — persist it as verified, reusable knowledge for future sessions (e.g. 'This repo pins better-sqlite3 to 12.x; native builds fail on newer versions'). Before storing, run memory_searchKnowledge on what you learned; if a matching item exists, use memory_updateKnowledge instead of creating a near-duplicate. Do not store secrets, raw logs, task progress, or one-off details.",
2929
inputSchema: {
3030
type: "object" as const,
3131
properties: {
3232
title: {
3333
type: "string",
34-
description: "Short, explicit description of the rule (5-12 words, 10-100 chars)",
34+
description:
35+
"Short, explicit description of the rule, written so a future agent knows when it applies (5-12 words, 10-100 chars)",
3536
},
3637
content: {
3738
type: "string",
@@ -56,7 +57,7 @@ const STORE_TOOL = {
5657
const UPDATE_TOOL = {
5758
name: "memory_updateKnowledge",
5859
description:
59-
"Correct an existing knowledge item by ID when you learn it is outdated or inaccurate — update it instead of storing a duplicate. First run memory_searchKnowledge to find the item and its ID; pass only the fields that change.",
60+
"Correct an existing knowledge item by ID when you learn it is outdated, inaccurate, or incomplete — update it instead of storing a duplicate. First run memory_searchKnowledge to find the item and its ID; pass only the fields that change.",
6061
inputSchema: {
6162
type: "object" as const,
6263
properties: {
@@ -90,14 +91,14 @@ const UPDATE_TOOL = {
9091
const SEARCH_TOOL = {
9192
name: "memory_searchKnowledge",
9293
description:
93-
"Call BEFORE starting any non-trivial task to check for prior knowledge — this is cheap and prevents redoing solved work. Pass a short description of what you are about to do (e.g. 'wire MCP server into Gemini CLI settings' or 'fix vitest flaky teardown in cli package') and apply relevant results. Also call it when a task reveals a convention worth remembering later.",
94+
"Call BEFORE starting ANY task — trivial or not — and again IMMEDIATELY when you hit an error, test failure, or surprising behavior during work. This check is cheap and prevents re-solving already-solved problems. Pass a short description of what you are about to do or the error you hit (e.g. 'wire MCP server into Gemini CLI settings', 'vitest flaky teardown in cli package', 'EPERM on npm ci in worktree'). Skip only for pure conversation with no action. Apply relevant results, and prefer them over re-deriving from scratch.",
9495
inputSchema: {
9596
type: "object" as const,
9697
properties: {
9798
query: {
9899
type: "string",
99100
description:
100-
"Natural language task description to search for relevant knowledge (3-500 chars)",
101+
"Natural language task description — or paste the error text you just hit — to search for relevant knowledge (3-500 chars)",
101102
},
102103
contextTags: {
103104
type: "array",

‎packages/memory/tests/unit/server.descriptions.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ describe("memory MCP tool descriptions (always-loaded prompt surface)", () => {
2121
]);
2222
});
2323

24-
it("instructs the agent to search BEFORE non-trivial tasks, with an example", () => {
25-
expect(SEARCH.description).toMatch(/BEFORE starting any non-trivial task/i);
24+
it("instructs the agent to search BEFORE any task and on errors, with an example", () => {
25+
expect(SEARCH.description).toMatch(/BEFORE starting any task/i);
26+
expect(SEARCH.description).toMatch(/IMMEDIATELY when you hit an error/i);
2627
expect(SEARCH.description).toMatch(/e\.g\.|example|such as/i);
2728
expect(SEARCH.description!.length).toBeGreaterThan(80);
2829
});
@@ -32,6 +33,8 @@ describe("memory MCP tool descriptions (always-loaded prompt surface)", () => {
3233
/after completing|when you (have )?(just )?(verified|learned|solved)/i,
3334
);
3435
expect(STORE.description).toMatch(/reusable/i);
36+
expect(STORE.description).toMatch(/memory_updateKnowledge/i);
37+
expect(STORE.description).toMatch(/instead of creating a near-duplicate/i);
3538
});
3639

3740
it("instructs the agent to update instead of duplicating when knowledge is wrong", () => {

0 commit comments

Comments
 (0)