Skip to main content
Glama

validate_diagram_spec

Read-onlyIdempotent

Validate diagram specifications before generation to check node validity, connection references, and cluster memberships, returning validation results with any errors or warnings.

Instructions

Validate diagram before generation (dry-run).

Checks: node validity, connection references, cluster memberships. Returns: {"valid": true/false, "errors": [...], "warnings": [...]}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodesYesNodes to validate
connectionsYesConnections to validate
clustersNoClusters to validate

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main asynchronous handler function that executes the tool's validation logic: checks node references, connection validity, cluster memberships, collects errors and warnings, and formats the output.
    async def validate_diagram_spec(
        nodes: Annotated[List[NodeDef], Field(description="Nodes to validate")],
        connections: Annotated[List[ConnectionDef], Field(description="Connections to validate")],
        clusters: Annotated[
            Optional[List[ClusterDef]], Field(description="Clusters to validate")
        ] = None,
    ) -> str:
        """Validate diagram specification."""
        errors = []
        warnings = []
    
        try:
            # Validate nodes
            node_ids = {node.id for node in nodes}
    
            for node in nodes:
                try:
                    validate_node_reference(node.provider, node.category, node.type)
                except ValueError as e:
                    errors.append(f"Node '{node.id}': {str(e)}")
    
            # Validate connections
            for conn in connections:
                if conn.from_node not in node_ids:
                    errors.append(f"Connection references unknown source node '{conn.from_node}'")
    
                targets = [conn.to_node] if isinstance(conn.to_node, str) else conn.to_node
                for target in targets:
                    if target not in node_ids:
                        errors.append(f"Connection references unknown target node '{target}'")
    
            # Validate clusters
            if clusters:
                cluster_names = {cluster.name for cluster in clusters}
    
                for cluster in clusters:
                    # Check node references
                    for node_id in cluster.node_ids:
                        if node_id not in node_ids:
                            errors.append(
                                f"Cluster '{cluster.name}' references unknown node '{node_id}'"
                            )
    
                    # Check parent cluster exists
                    if cluster.parent_cluster and cluster.parent_cluster not in cluster_names:
                        errors.append(
                            f"Cluster '{cluster.name}' references unknown parent '{cluster.parent_cluster}'"
                        )
    
                    # Check for empty clusters
                    if not cluster.node_ids:
                        warnings.append(f"Cluster '{cluster.name}' is empty")
    
            # Determine if valid
            valid = len(errors) == 0
    
            # Build metadata
            metadata = {
                "node_count": len(nodes),
                "edge_count": len(connections),
                "cluster_count": len(clusters) if clusters else 0,
            }
    
            return format_validation_result(valid, errors, warnings, metadata)
    
        except Exception as e:
            return format_error(f"Validation failed: {str(e)}")
  • The MCP tool decorator that registers the 'validate_diagram_spec' function as a tool with name, description, input schema via annotations, and execution hints.
    @mcp.tool(
        name="validate_diagram_spec",
        description="""Validate diagram before generation (dry-run).
    
    Checks: node validity, connection references, cluster memberships.
    Returns: {"valid": true/false, "errors": [...], "warnings": [...]}""",
        annotations={
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
        },
    )
  • Pydantic input schema definitions using Annotated types (NodeDef, ConnectionDef, ClusterDef) with Field descriptions for validation and documentation.
        nodes: Annotated[List[NodeDef], Field(description="Nodes to validate")],
        connections: Annotated[List[ConnectionDef], Field(description="Connections to validate")],
        clusters: Annotated[
            Optional[List[ClusterDef]], Field(description="Clusters to validate")
        ] = None,
    ) -> str:
Behavior4/5

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

While annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, the description adds valuable context about what specific checks are performed ('node validity, connection references, cluster memberships') and the exact return format. This goes beyond the safety profile provided by annotations and gives the agent concrete expectations about validation behavior.

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?

The description is extremely concise and well-structured: a clear purpose statement, specific validation checks listed, and exact return format specified - all in just three lines. Every sentence earns its place with zero wasted words, and the information is front-loaded effectively.

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

Completeness5/5

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

Given the tool's validation purpose, comprehensive annotations, 100% schema coverage, and explicit output format description, the description is complete enough. It provides the necessary context about what's validated, when to use it, and what to expect in return, making it fully functional for an AI agent to understand and invoke correctly.

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?

With 100% schema description coverage, the input schema already thoroughly documents all parameters (nodes, connections, clusters). The description doesn't add any additional parameter semantics beyond what's in the schema. The baseline score of 3 is appropriate since the schema does the heavy lifting for parameter documentation.

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 specific action ('validate diagram before generation') and resource ('diagram'), distinguishing it from sibling tools like 'create_diagram' or 'list_available_nodes'. It explicitly mentions this is a 'dry-run' operation, which clarifies it's a validation check rather than actual generation.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: 'before generation' as a 'dry-run' validation step. This clearly positions it as a pre-check alternative to the sibling 'create_diagram' tools, helping the agent understand this should be used to validate specifications before attempting actual diagram creation.

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/apetta/diagrams-mcp'

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