Skip to main content
Glama

apply_layout

Apply a chosen layout algorithm (force_directed, radial, circle, grid) to a graph for visualization and analysis within Graphistry MCP, optimizing structure and clarity for complex network data.

Instructions

Apply a layout algorithm to a graph.

Args: graph_id: ID of the graph to apply layout to layout: Layout algorithm to apply (force_directed, radial, circle, grid)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graph_idYes
layoutYes

Implementation Reference

  • The handler function for the 'apply_layout' tool. It applies one of several layout algorithms (force_directed, radial, circle, grid) to the specified graph using Graphistry settings and updates the cached graph object with the new visualization URL.
    @mcp.tool() async def apply_layout(graph_id: str, layout: str) -> Dict[str, Any]: """Apply a layout algorithm to a graph. Args: graph_id: ID of the graph to apply layout to layout: Layout algorithm to apply (force_directed, radial, circle, grid) """ try: if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") graph_data = graph_cache[graph_id] g = graph_data["graph"] # Apply layout using Graphistry's url_params settings if layout == "force_directed": g = g.settings(url_params={'play': 5000, 'strongGravity': True}) elif layout == "radial": g = g.settings(url_params={'play': 0, 'layout': 'radial'}) elif layout == "circle": g = g.settings(url_params={'play': 0, 'layout': 'circle'}) elif layout == "grid": g = g.settings(url_params={'play': 0, 'layout': 'grid'}) else: raise ValueError(f"Unsupported layout: {layout}") graph_cache[graph_id]["graph"] = g return { "graph_id": graph_id, "url": g.plot(render=False) } except Exception as e: logger.error(f"Error in apply_layout: {e}") raise
  • The @mcp.tool() decorator registers the apply_layout function as an MCP tool.
    @mcp.tool()

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/graphistry/graphistry-mcp'

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