Skip to content

Add get_node_relations function for efficient graph traversal #2310

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

enthali
Copy link

@enthali enthali commented Jul 8, 2025

Summary

This PR adds a new get_node_relations function to the MCP memory server that enables efficient graph traversal by retrieving all incoming and outgoing relations for a specific node without loading the entire graph.

Changes

  • New function: getNodeRelations in KnowledgeGraphManager class
  • New MCP tool: get_node_relations exposed via the server API
  • Documentation: Updated README.md with API documentation for the new function
  • Tool registration: Added to .github/mcp.json for discoverability

Implementation Details

Input

  • nodeName (string): The name of the entity to get relations for

Output

  • outgoing (array): Relations where this node is the source
  • incoming (array): Relations where this node is the target
  • connected_entities (string[]): Names of all connected entities

Use Cases

  • Graph traversal without loading entire graph
  • Finding connected entities efficiently
  • Building relationship maps for specific nodes
  • Performance optimization for large knowledge graphs

Testing

The implementation has been tested locally with:

  • Existing nodes with multiple relations
  • Nodes with no relations (returns empty arrays)
  • Non-existent nodes (returns empty structure)

Files Changed

  • src/memory/index.ts: Core implementation
  • src/memory/README.md: API documentation

This enhancement maintains backward compatibility and follows existing code patterns in the memory server.

- Implements new get_node_relations tool that returns incoming/outgoing relations for a specific node
- Enables efficient graph traversal without loading entire knowledge graph
- Returns connected entity names for further exploration
- Solves limitation where search_nodes and open_nodes only show relations between filtered results
- Updated README with comprehensive API documentation
@olaservo olaservo added server-memory Reference implementation for the Memory MCP server - src/memory enhancement New feature or request labels Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server-memory Reference implementation for the Memory MCP server - src/memory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants