fix(memory): return relations connected to requested nodes in openNodes/searchNodes#3297
Open
DukeDeSouth wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…es/searchNodes Previously, `openNodes` and `searchNodes` only returned relations where BOTH endpoints were in the result set (using `&&`). This silently dropped all relations to/from nodes outside the set — making it impossible to discover a node's connections without calling `read_graph` and filtering the entire dataset client-side. Changed the filter from `&&` to `||` so that any relation with at least one endpoint in the result set is included. This matches the expected graph-query semantics: when you open a node, you should see all its edges, not just edges to other opened nodes. Fixes modelcontextprotocol#3137 Tests updated and new cases added covering: - Outgoing relations to nodes not in the open set - Incoming relations from nodes not in the open set - Relations connected to a single opened node - searchNodes returning outgoing relations to unmatched entities Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3137 —
open_nodesreturns empty relations array despite entity having relations in graph.Root cause: Both
openNodes()andsearchNodes()filter relations using&&(require BOTH endpoints to be in the result set). This means if you callopen_nodes(["A"])and there's a relationA → B, it gets silently dropped becauseBisn't in the filtered set.Fix: Changed the relation filter from
&&to||— include any relation where at least one endpoint is in the result set. This matches standard graph-query semantics: opening a node should reveal all its edges, not just edges to other opened nodes.Before (broken)
After (fixed)
Changes
src/memory/index.ts: Changed&&→||in relation filtering for bothopenNodes()andsearchNodes()src/memory/__tests__/knowledge-graph.test.ts: Updated existing tests and added new cases:searchNodesreturning outgoing relations to unmatched entitiesTest plan
vitest run)read_graphbehavior unchanged (returns all relations)Made with Cursor