Skip to content

Memory - Fix: Update relation filter logic to use OR condition instead of AND #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dimalo
Copy link

@dimalo dimalo commented Apr 15, 2025

Description

This PR updates the relation filtering logic in the memory server's searchNodes and openNodes methods to correctly include relations connected to at least one filtered entity.

Server Details

  • Server: memory
  • Changes to: searchNodes and openNodes tools

Motivation and Context

The current implementation filters relations using an && condition, meaning a relation is only included if both its source and destination entities are present in the filtered entity list. This is incorrect behavior as it excludes relations that connect a filtered entity to an unfiltered one. The expected behavior is to include any relation where either the source or destination entity is in the filtered list.

How Has This Been Tested?

  • Manually tested with the openNodes tool to verify correct relation inclusion
  • Verified that relations are now included when connected to at least one filtered entity

Breaking Changes

None. This is a bug fix that maintains backward compatibility.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

The change replaces the && condition with an || condition in both searchNodes and openNodes methods:

const filteredRelations = graph.relations.filter(r => 
  filteredEntityNames.has(r.from) || filteredEntityNames.has(r.to)
);

@olaservo olaservo added server-memory Reference implementation for the Memory MCP server - src/memory bug Something isn't working labels Apr 18, 2025
@undecidedapollo
Copy link

This PR fixed an issue I was having. I wanted it to find the children of a node and open_node would show no relationships so it reverted to read_graph instead. What steps are required to get this merged or is there a reason it is currently set to &&?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server-memory Reference implementation for the Memory MCP server - src/memory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants