Skip to content

fix(memory): return relations connected to requested nodes in openNodes/searchNodes#3297

Merged
olaservo merged 1 commit intomodelcontextprotocol:mainfrom
DukeDeSouth:fix/memory-open-nodes-relations
Mar 7, 2026
Merged

fix(memory): return relations connected to requested nodes in openNodes/searchNodes#3297
olaservo merged 1 commit intomodelcontextprotocol:mainfrom
DukeDeSouth:fix/memory-open-nodes-relations

Conversation

@DukeDeSouth
Copy link
Contributor

@DukeDeSouth DukeDeSouth commented Feb 7, 2026

Human View

Summary

Fixes #3137open_nodes returns empty relations array despite entity having relations in graph.

Root cause: Both openNodes() and searchNodes() filter relations using && (require BOTH endpoints to be in the result set). This means if you call open_nodes(["A"]) and there's a relation A → B, it gets silently dropped because B isn'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)

open_nodes(["2025-12-17"])
→ entities: [2025-12-17], relations: []  // relations silently dropped!

After (fixed)

open_nodes(["2025-12-17"])
→ entities: [2025-12-17], relations: [{from: "2025-12-17", to: "incident/example", ...}]

Changes

  • src/memory/index.ts: Changed &&|| in relation filtering for both openNodes() and searchNodes()
  • src/memory/__tests__/knowledge-graph.test.ts: Updated existing tests and added new cases:
    • 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 (both directions)
    • searchNodes returning outgoing relations to unmatched entities

Test plan

  • All 45 existing tests pass (vitest run)
  • New tests verify outgoing/incoming relations are returned for single-node queries
  • read_graph behavior unchanged (returns all relations)
  • Empty node list still returns empty graph
  • Non-existent nodes still return empty result

AI View (DCCE Protocol v1.0)

Metadata

  • Generator: Claude (Anthropic) via Cursor IDE
  • Methodology: AI-assisted development with human oversight and review

AI Contribution Summary

  • Solution design and implementation

Verification Steps Performed

  1. Reproduced the reported issue
  2. Analyzed source code to identify root cause
  3. Implemented and tested the fix
  4. Verified lint/formatting compliance

Human Review Guidance

  • Core changes are in: src/memory/index.ts, src/memory/__tests__/knowledge-graph.test.ts

Made with M7 Cursor

…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>
Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

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

Thanks for this fix @DukeDeSouth! Reviewed with help from Claude Code.

This is a clean, correct fix for #3137. The &&|| change in both searchNodes() and openNodes() is the right call — when you open or search for a node, you should see all its connections, not just connections to other nodes that happen to also be in the result set.

Appreciated that you:

  • Fixed both affected methods (not just openNodes)
  • Added thorough tests covering incoming, outgoing, and bidirectional relations
  • Included clear comments explaining the rationale

CI is all green and there are no conflicts. Merging!

@olaservo olaservo merged commit 6d977dd into modelcontextprotocol:main Mar 7, 2026
19 checks passed
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.

Memory MCP open_nodes returns empty relations array despite entity having relations in graph

2 participants