Skip to main content
Glama

apply_layout

Apply a layout algorithm to organize graph visualizations for clearer network analysis and data interpretation.

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 main handler function for the 'apply_layout' tool. It is registered via the @mcp.tool() decorator. Modifies a cached Graphistry graph object by applying one of several layout algorithms (force_directed, radial, circle, grid) using url_params settings and returns the updated 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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Apply') but doesn't clarify if this is a destructive mutation (e.g., overwriting existing layout), requires specific permissions, has side effects, or what the expected outcome is (e.g., visual changes only). This leaves critical behavioral traits unspecified for a tool that likely modifies graph state.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear opening sentence stating the purpose, followed by a bullet-point-like 'Args' section for parameters. Every sentence adds value, and there's no redundant information. It could be slightly more front-loaded by integrating parameter hints into the main sentence, but overall it's well-organized and concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of applying layouts (likely a mutation with visual/graph state implications), no annotations, no output schema, and multiple sibling tools, the description is incomplete. It lacks information on behavioral effects, differences from other layout tools, and expected outcomes, making it inadequate for an agent to use this tool confidently in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant value beyond the input schema, which has 0% description coverage. It explains that 'graph_id' is the 'ID of the graph to apply layout to' and 'layout' is the 'Layout algorithm to apply', listing specific algorithm options (force_directed, radial, circle, grid). This compensates well for the schema's lack of descriptions, though it doesn't detail format constraints (e.g., string patterns for graph_id).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Apply a layout algorithm') and the resource ('to a graph'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling layout tools (like apply_tree_layout or apply_ring_categorical_layout), which would require specifying what makes this particular layout application distinct.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its many sibling layout tools (e.g., apply_tree_layout, apply_modularity_weighted_layout). It also doesn't mention prerequisites, such as whether the graph must exist or be in a particular state, leaving the agent with insufficient context for appropriate tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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