apply_modularity_weighted_layout
Apply modularity-based weighted layouts to graphs using the Graphistry MCP server. Optimizes visualization by grouping nodes based on modularity, enhancing analysis of complex network structures. Provides a URL to the updated graph view.
Instructions
Apply modularity weighted layout to the graph using Graphistry's modularity_weighted_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_modularity_weighted_layout(graph_id)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graph_id | Yes |
Implementation Reference
- The handler function for the 'apply_modularity_weighted_layout' tool. It is decorated with @mcp.tool() which registers it as an MCP tool. The function retrieves the graph from cache, applies Graphistry's modularity_weighted_layout(), updates the cache, and returns the updated graph ID and URL.@mcp.tool() async def apply_modularity_weighted_layout(graph_id: str) -> Dict[str, Any]: """ Apply modularity weighted layout to the graph using Graphistry's modularity_weighted_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_modularity_weighted_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.modularity_weighted_layout() graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}
- src/graphistry_mcp_server/server.py:535-535 (registration)The @mcp.tool() decorator registers the function as an MCP tool named 'apply_modularity_weighted_layout'.@mcp.tool()
- The docstring provides the input schema (graph_id: str) and output format (dict with graph_id and url).""" Apply modularity weighted layout to the graph using Graphistry's modularity_weighted_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_modularity_weighted_layout(graph_id) """