Describe the bug
When using either search_nodes or open_nodes tools from the memory graph MCP, an unintuitive behaviour arises regarding relation search. For a relation to be included in the results, it needs to relate entities present in the search query in both ends (from and to). Arguably, this makes relations very hard to be discovered by an agent and the graph nearly impossible to explore.
I open this as a bug suspecting that this is not the intended behavior, but I apologize in advance if it is. If that's the case, instead I would suggest this as an enhancement.
To Reproduce
Steps to reproduce the behavior:
- Create the knowledge graph described later.
- Ask an agent to use the open_nodes tool directly to open the
Zero Cool node.
Knowledge graph:
{"type":"entity","entityType":"person","name":"Zero Cool"}
{"type":"entity","entityType":"Person","name":"Dade Murphy"}
{"type":"relation","from":"Zero Cool","relationType":"is","to":"Dade Murphy"}
{"type":"relation","from":"Dade Murphy","relationType":"is","to":"Zero Cool"}
Expected behavior
What I expected was to obtain both the Zero Cool entity and all it's relations so it'd be possible for the agent to traverse the graph and research the existing information. Instead the response is the following:
{
"text": "{\n \"entities\": [\n {\n \"type\": \"entity\",\n \"entityType\": \"person\",\n \"name\": \"Zero Cool\"\n }\n ],\n \"relations\": []\n}",
"type": "text"
}
Notice the empty relations array. Instead, it should include all of "Zero Cools" relations.
The cause for this seems to be the following lines:
https://github.com/modelcontextprotocol/servers/blob/220987921bc72409d35d1a5775597782ae688556/src/memory/index.ts#L172C1-L175C7
These are present in both open_nodes and search_nodes functions and require that both to and from sides be present in the search entity results to include a relation. This could potentially be resolved by changing the condition to include relations where either endpoint is present in the search result (i.e., using an || instead of &&).
Although the current behavior might be advantageous in queries involving many entities, for a single entity query, it makes relations completely inaccesible. For agents exploring the knowledge graph starting from a single node, this restriction hides all useful relational context, breaking graph traversal. This diminishes the usefulness of both tools.
Furthermore, if this is indeed the intended behavior then it might make sense to make an exception when there's only a single entity in the results.
Happy to clarify or send a PR if this seems like a desirable fix. Please let me know how I can help!
Describe the bug
When using either
search_nodesoropen_nodestools from the memory graph MCP, an unintuitive behaviour arises regarding relation search. For a relation to be included in the results, it needs to relate entities present in the search query in both ends (fromandto). Arguably, this makes relations very hard to be discovered by an agent and the graph nearly impossible to explore.I open this as a bug suspecting that this is not the intended behavior, but I apologize in advance if it is. If that's the case, instead I would suggest this as an enhancement.
To Reproduce
Steps to reproduce the behavior:
Zero Coolnode.Knowledge graph:
Expected behavior
What I expected was to obtain both the Zero Cool entity and all it's relations so it'd be possible for the agent to traverse the graph and research the existing information. Instead the response is the following:
Notice the empty relations array. Instead, it should include all of "Zero Cools" relations.
The cause for this seems to be the following lines:
https://github.com/modelcontextprotocol/servers/blob/220987921bc72409d35d1a5775597782ae688556/src/memory/index.ts#L172C1-L175C7
These are present in both
open_nodesandsearch_nodesfunctions and require that bothtoandfromsides be present in the search entity results to include a relation. This could potentially be resolved by changing the condition to include relations where either endpoint is present in the search result (i.e., using an||instead of&&).Although the current behavior might be advantageous in queries involving many entities, for a single entity query, it makes relations completely inaccesible. For agents exploring the knowledge graph starting from a single node, this restriction hides all useful relational context, breaking graph traversal. This diminishes the usefulness of both tools.
Furthermore, if this is indeed the intended behavior then it might make sense to make an exception when there's only a single entity in the results.
Happy to clarify or send a PR if this seems like a desirable fix. Please let me know how I can help!