apply_tree_layout
Apply a tree layout to visualize hierarchical network data in Graphistry, organizing nodes in layered structures for clearer analysis.
Instructions
Apply a tree (layered hierarchical) layout to the graph using Graphistry's tree_layout API.
Args:
graph_id (str): The ID of the graph to modify.
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
apply_tree_layout(graph_id)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graph_id | Yes |
Implementation Reference
- The main handler function for the 'apply_tree_layout' tool. It is registered via the @mcp.tool() decorator. Retrieves the graph from cache, applies Graphistry's tree_layout(), updates the cache, and returns the graph ID and updated visualization URL.@mcp.tool() async def apply_tree_layout(graph_id: str) -> Dict[str, Any]: """ Apply a tree (layered hierarchical) layout to the graph using Graphistry's tree_layout API. Args: graph_id (str): The ID of the graph to modify. Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: apply_tree_layout(graph_id) """ if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") g = graph_cache[graph_id]["graph"] g = g.tree_layout() graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}