Skip to content

fix(memory): guard against undefined observations in searchNodes - #4731

Open
CryoThrust wants to merge 1 commit into
modelcontextprotocol:mainfrom
CryoThrust:fix/memory-search-nodes-undefined-observations
Open

fix(memory): guard against undefined observations in searchNodes#4731
CryoThrust wants to merge 1 commit into
modelcontextprotocol:mainfrom
CryoThrust:fix/memory-search-nodes-undefined-observations

Conversation

@CryoThrust

Copy link
Copy Markdown
Contributor

Closes #1818

Problem

search_nodes throws TypeError: Cannot read properties of undefined (reading 'some') when an entity in the JSONL file has a missing observations field. This can happen with older data files or malformed entries.

Fix

Use nullish coalescing (??) to default observations to an empty array before calling .some():

(e.observations ?? []).some(o => o.toLowerCase().includes(query.toLowerCase()))

Tests

All 50 existing tests pass. The fix is backward-compatible — entities with properly defined observations arrays are unaffected.

Entities loaded from JSONL files may have missing observations fields
(e.g., from older data or malformed entries). Calling .some() on
undefined throws TypeError: Cannot read properties of undefined.

Use nullish coalescing to default to an empty array.

Fixes modelcontextprotocol#1818
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search_nodes fails with non-empty query

1 participant