Skip to content

fix(mcp): add memwal_namespaces tool and empty-namespace diagnostics (#416) - #1346

Open
harrymove-ctrl wants to merge 3 commits into
devfrom
fix/issue-416-mcp-namespace-diagnostics
Open

harrymove-ctrl wants to merge 3 commits into
devfrom
fix/issue-416-mcp-namespace-diagnostics

Conversation

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator

Summary

  • Register memwal_namespaces MCP tool (readOnlyHint: true) backed by session.memwal.listNamespaces({ limit, cursor }) so agents can list populated namespaces along with their memory counts and storage usage.
  • Add close-namespace suggestion helper (editDistance, isCloseNamespaceMatch, formatNamespaceSuggestionHint, tryListNamespaces) that best-effort queries listNamespaces({ limit: 50 }) when a target namespace has 0 memories.
  • Update memwal_recall empty-result handling so an unpopulated or misspelled namespace is clearly distinguished (No matching memories found (namespace "<name>" currently holds 0 memories). Did you mean namespace "..."?) from a query with 0 semantic hits in a populated namespace, while degrading gracefully if listNamespaces is unavailable.
  • Update memwal_restore so an empty namespace (total=0, restored=0, skipped=0, failed=0, truncated=false) explicitly states Namespace "<name>" holds 0 on-chain blobs. and suggests close existing namespaces.
  • Document memwal_namespaces and namespace spelling diagnostics in docs/mcp/overview.md, docs/mcp/quickstart.md, and docs/mcp/reference.md.
  • Add unit tests in services/server/scripts/mcp/__tests__/namespace-diagnostics.test.ts and restore.test.ts.

Fixes #416

Test Plan

  • node --test --import tsx services/server/scripts/mcp/__tests__/*.test.ts (all MCP test suites pass)

@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm October 28, 2026 16:10

@ducnmm ducnmm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the actionable issue below before merging. Validation was offline; no production writes or live load tests were run.

if (namespaceContext) {
const { activeNamespace, namespaces } = namespaceContext;
const activeEntry = namespaces.find((ns) => ns.name === activeNamespace);
if (!activeEntry || activeEntry.memory_count === 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not infer an empty namespace from an incomplete first page

tryListNamespaces fetches only 50 namespaces and drops has_more/next_cursor. If the queried namespace exists on a later page and recall has no semantic matches, activeEntry is missing here and the tool incorrectly reports that namespace holds 0 memories. This occurs on accounts with more than 50 namespace rows; the exact helpers reproduce it with has_more=true. Preserve page completeness and return an unknown/generic result, or finish pagination/perform a targeted lookup before asserting emptiness.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3b6760d.

  1. Updated tryListNamespaces to preserve has_more and paginate across pages until the queried target namespace is found or pagination completes.
  2. Updated emptyRecallText so that when pagination is incomplete (has_more is true) and activeEntry is not found, the tool returns a generic 'No matching memories found in namespace "".' message instead of incorrectly asserting that the namespace holds 0 memories.
  3. Added unit tests verifying pagination traversal across pages and confirming that incomplete pages never trigger the empty-namespace diagnostic.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm Updated in commit 9a188af to address review feedback:

  1. In commit 3b6760d, tryListNamespaces was updated to walk pages via next_cursor and prevent falsely asserting an empty namespace when has_more is true or pagination is incomplete.
  2. In commit 9a188af, resolved the shared OpenClaw unit test timing issue in packages/openclaw-memory-memwal/test/plugin.test.mjs by priming relayer compatibility before the timed test turn and providing sufficient timeout headroom for the socket abort event.

Ready for re-review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants