get_related_nodes
Find connected nodes in a Hebbian neural memory graph by specifying a starting node and minimum edge weight threshold.
Instructions
Get nodes connected to a given node by Hebbian edges.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| node | Yes | Node name to find related nodes for | |
| min_weight | No | Minimum edge weight (default: 0.1) |
Implementation Reference
- src/hebbian_mind/server.py:856-872 (handler)Implementation of the get_related_nodes method which queries the database for nodes connected by Hebbian edges.
def get_related_nodes(self, node_id: int, min_weight: float = 0.1) -> List[Dict]: """Get nodes connected via Hebbian edges.""" cursor = self.read_conn.cursor() cursor.execute( """ SELECT n.*, e.weight FROM edges e JOIN nodes n ON (e.target_id = n.id OR e.source_id = n.id) WHERE (e.source_id = ? OR e.target_id = ?) AND n.id != ? AND e.weight >= ? ORDER BY e.weight DESC """, (node_id, node_id, node_id, min_weight), ) return [dict(row) for row in cursor.fetchall()] - src/hebbian_mind/server.py:1066-1083 (registration)Registration of the get_related_nodes tool schema in the MCP server.
types.Tool( name="get_related_nodes", description="Get nodes connected to a given node by Hebbian edges.", inputSchema={ "type": "object", "properties": { "node": { "type": "string", "description": "Node name to find related nodes for", }, "min_weight": { "type": "number", "description": "Minimum edge weight (default: 0.1)", }, }, "required": ["node"], }, ), - src/hebbian_mind/server.py:1328-1365 (handler)Handling logic for the get_related_nodes tool in the MCP server's call_tool function.
elif name == "get_related_nodes": node_name = _validate_string(arguments.get("node", ""), "node", max_length=500) min_weight = _validate_number(arguments.get("min_weight", 0.1), "min_weight", 0.0, 10.0) node = db.get_node_by_name(node_name) if not node: return [ types.TextContent( type="text", text=json.dumps( {"success": False, "message": f"Node not found: {node_name}"}, indent=2 ), ) ] related = db.get_related_nodes(node["id"], min_weight) return [ types.TextContent( type="text", text=json.dumps( { "success": True, "source_node": node["name"], "related_count": len(related), "related_nodes": [ { "name": r["name"], "category": r["category"], "weight": round(r["weight"], 3), } for r in related ], }, indent=2, ), ) ]