Skip to main content
Glama

modify_diagram

Modify an existing Excalidraw diagram by adding or removing nodes, updating labels, and rewiring connections without recreating the entire diagram.

Instructions

Modify an existing Excalidraw diagram created by this tool.

Supports iterative editing: add components, remove nodes, update labels, and rewire connections - without recreating the entire diagram.

IMPORTANT: Call get_diagram_info first to understand the current diagram state before making modifications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the existing .excalidraw file.
operationsYesOrdered list of operations. Each dict has: - op: "add_node" | "remove_node" | "update_node" | "add_connection" | "remove_connection" For add_node: - id (str): New node identifier - label (str): Display text - component_type (str, optional): Technology for auto-styling - shape (str, optional): Shape override - near (str, optional): Place near this existing node id For remove_node: - id (str): Node to remove (also removes its connections) For update_node: - id (str): Node to update - label (str, optional): New label - component_type (str, optional): New component type For add_connection: - from_id (str): Source node id - to_id (str): Target node id - label (str, optional): Edge label For remove_connection: - from_id (str): Source node id - to_id (str): Target node id
themeNoColor theme for re-rendering. Default: "default"default

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The modify_diagram tool handler function registered with @mcp.tool. Parses raw operation dicts into typed ModifyOperation objects (AddNodeOp, RemoveNodeOp, etc.) then delegates to apply_modifications().
    def modify_diagram(
        file_path: str,
        operations: list[dict[str, Any]],
        theme: str = "default",
    ) -> str:
        """Modify an existing Excalidraw diagram created by this tool.
    
        Supports iterative editing: add components, remove nodes, update labels,
        and rewire connections - without recreating the entire diagram.
    
        IMPORTANT: Call get_diagram_info first to understand the current diagram
        state before making modifications.
    
        Args:
            file_path: Path to the existing .excalidraw file.
            operations: Ordered list of operations. Each dict has:
                - op: "add_node" | "remove_node" | "update_node" |
                      "add_connection" | "remove_connection"
    
                For add_node:
                  - id (str): New node identifier
                  - label (str): Display text
                  - component_type (str, optional): Technology for auto-styling
                  - shape (str, optional): Shape override
                  - near (str, optional): Place near this existing node id
    
                For remove_node:
                  - id (str): Node to remove (also removes its connections)
    
                For update_node:
                  - id (str): Node to update
                  - label (str, optional): New label
                  - component_type (str, optional): New component type
    
                For add_connection:
                  - from_id (str): Source node id
                  - to_id (str): Target node id
                  - label (str, optional): Edge label
    
                For remove_connection:
                  - from_id (str): Source node id
                  - to_id (str): Target node id
    
            theme: Color theme for re-rendering. Default: "default"
    
        Returns:
            Summary of applied modifications.
        """
        parsed_ops: list[ModifyOperation] = []
        for op_dict in operations:
            op_type = op_dict.get("op", "")
            match op_type:
                case "add_node":
                    parsed_ops.append(
                        AddNodeOp(
                            id=op_dict["id"],
                            label=op_dict.get("label", op_dict["id"]),
                            component_type=op_dict.get("component_type"),
                            shape=(
                                ShapeType(op_dict["shape"])
                                if "shape" in op_dict
                                else ShapeType.RECTANGLE
                            ),
                            near=op_dict.get("near"),
                        )
                    )
                case "remove_node":
                    parsed_ops.append(RemoveNodeOp(id=op_dict["id"]))
                case "update_node":
                    parsed_ops.append(
                        UpdateNodeOp(
                            id=op_dict["id"],
                            label=op_dict.get("label"),
                            component_type=op_dict.get("component_type"),
                        )
                    )
                case "add_connection":
                    parsed_ops.append(
                        AddConnectionOp(
                            from_id=op_dict["from_id"],
                            to_id=op_dict["to_id"],
                            label=op_dict.get("label"),
                        )
                    )
                case "remove_connection":
                    parsed_ops.append(
                        RemoveConnectionOp(
                            from_id=op_dict["from_id"],
                            to_id=op_dict["to_id"],
                        )
                    )
                case _:
                    return f"Error: Unknown operation type '{op_type}'"
    
        return apply_modifications(file_path, parsed_ops, theme=theme)
  • Defines the typed operation models (AddNodeOp, RemoveNodeOp, UpdateNodeOp, AddConnectionOp, RemoveConnectionOp) and the ModifyOperation union type used by the modify_diagram tool.
    class AddNodeOp(BaseModel):
        """Operation to add a new node to an existing diagram."""
    
        op: str = "add_node"
        id: str
        label: str
        component_type: str | None = None
        shape: ShapeType = ShapeType.RECTANGLE
        near: str | None = None
    
    
    class RemoveNodeOp(BaseModel):
        """Operation to remove a node and its connections."""
    
        op: str = "remove_node"
        id: str
    
    
    class UpdateNodeOp(BaseModel):
        """Operation to update an existing node's properties."""
    
        op: str = "update_node"
        id: str
        label: str | None = None
        component_type: str | None = None
    
    
    class AddConnectionOp(BaseModel):
        """Operation to add a new connection between existing nodes."""
    
        op: str = "add_connection"
        from_id: str
        to_id: str
        label: str | None = None
    
    
    class RemoveConnectionOp(BaseModel):
        """Operation to remove a connection."""
    
        op: str = "remove_connection"
        from_id: str
        to_id: str
    
    
    ModifyOperation = AddNodeOp | RemoveNodeOp | UpdateNodeOp | AddConnectionOp | RemoveConnectionOp
  • Registration of modify_diagram as an MCP tool via the @mcp.tool decorator on line 186.
    @mcp.tool
    def modify_diagram(
  • The apply_modifications function that reads existing diagram metadata, applies each operation (add/remove/update nodes and connections), recomputes layout, and saves the updated .excalidraw file.
    def apply_modifications(
        file_path: str | Path,
        operations: list[ModifyOperation],
        theme: ThemeName | str = ThemeName.DEFAULT,
    ) -> str:
        """Apply a list of modification operations to an existing diagram.
    
        Returns a summary string describing what was changed.
        """
        meta = read_diagram_metadata(file_path)
        if meta is None:
            return (
                "Error: No excalidraw-architect-mcp metadata found in the file. "
                "Cannot modify a diagram not created by this tool."
            )
    
        changes: list[str] = []
    
        for op in operations:
            match op:
                case AddNodeOp():
                    _apply_add_node(meta, op)
                    changes.append(f"Added node '{op.id}' ({op.label})")
    
                case RemoveNodeOp():
                    _apply_remove_node(meta, op)
                    changes.append(f"Removed node '{op.id}'")
    
                case UpdateNodeOp():
                    _apply_update_node(meta, op)
                    changes.append(f"Updated node '{op.id}'")
    
                case AddConnectionOp():
                    _apply_add_connection(meta, op)
                    label_str = f" with label '{op.label}'" if op.label else ""
                    changes.append(f"Added connection {op.from_id} -> {op.to_id}{label_str}")
    
                case RemoveConnectionOp():
                    _apply_remove_connection(meta, op)
                    changes.append(f"Removed connection {op.from_id} -> {op.to_id}")
    
        graph = _metadata_to_graph(meta)
        layout = compute_layout(graph)
        doc = build_excalidraw_file(layout, theme_name=theme, direction=meta.direction)
        save_excalidraw(doc, file_path)
    
        summary = f"Applied {len(changes)} operation(s) to {Path(file_path).name}:\n"
        summary += "\n".join(f"  - {c}" for c in changes)
        return summary
Behavior4/5

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

With no annotations provided, the description carries full burden. It explains iterative editing without recreating, details operation effects (e.g., removing node also removes connections), and warns about necessary prior call. Lacks disclosure of side effects like persistence or authorization, but is above average.

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

Conciseness5/5

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

Three sentences: first sets purpose, second explains capability, third warns about prerequisite. No fluff, well front-loaded, every sentence earns its place.

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

Completeness4/5

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

Given the presence of an output schema (so return values are documented) and full schema coverage, the description provides adequate context. It could mention that the file must exist and be created by this tool, but the warning to get info first partially covers that. Overall reasonably complete.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters in detail. The description does not add new meaning beyond what the schema provides, such as additional constraints or usage tips, so baseline score of 3 is appropriate.

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

Purpose5/5

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

The description clearly states the tool modifies an existing Excalidraw diagram, with specific verb (modify) and resource (diagram). It distinguishes from siblings like create_diagram (creation) and get_diagram_info (read-only).

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

Usage Guidelines4/5

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

The description explicitly advises calling get_diagram_info first, providing clear context for use. It does not explicitly state when not to use, but the sibling tools naturally cover alternatives.

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/BV-Venky/excalidraw-architect-mcp'

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