Skip to main content
Glama

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
NameRequiredDescriptionDefault
nodeYesNode name to find related nodes for
min_weightNoMinimum edge weight (default: 0.1)

Implementation Reference

  • 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()]
  • 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"],
        },
    ),
  • 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,
                ),
            )
        ]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/For-Sunny/hebbian-mind-enterprise'

If you have feedback or need assistance with the MCP directory API, please join our Discord server