Skip to main content
Glama

Inspect D2 Diagram Structure

d2_inspect
Read-onlyIdempotent

Parse D2 source code and get a reliable structural summary of shapes, containers, connections, and boards without rendering. Use for accurate diagram previews instead of ASCII rendering.

Instructions

Parse and summarize the structure of D2 source code without rendering.

Returns a human-readable text summary of all shapes, containers, connections, and boards (layers/steps/scenarios) in the diagram. Uses the compile step only — no rendering occurs, so this is fast (~100ms) regardless of diagram complexity.

Use this INSTEAD of d2_render(ascii=true) for structural previews. The ASCII renderer has known bugs with cross-container connections and reverse edges. This tool produces reliable output for all diagram types.

Args:

  • d2_code (string): D2 source code to inspect

Returns: Structured text summary, e.g.: Shapes (4): - cp [rectangle] "Control Plane" - cp.listener [rectangle] "API Gateway" - cp.grpc [rectangle] "gRPC Server" - agent [rectangle] "Data Plane Agent"

Connections (2):
  cp.grpc -> agent.stream : "mirror request"
  agent.stream -> cp.grpc : "response"

Works correctly for all diagram types:

  • Architecture diagrams with nested containers and cross-container connections

  • Sequence diagrams (filters out internal lifeline-end nodes)

  • ER diagrams (sql_table shapes, FK connections shown at table level)

  • UML class diagrams

  • Layered/stepped/scenario diagrams (each board summarized)

  • State machines, flowcharts, grid dashboards

Error handling:

  • Returns compile errors if D2 code is invalid (same as d2_validate)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
d2_codeYesThe D2 diagram source code to inspect

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.0.0

TDQS

A4.7/5.0
Behavior5/5

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

With annotations already declaring readOnly, idempotent, and non-destructive behavior, the description adds meaningful context beyond them: it uses only the compile step (no rendering), is fast (~100ms), filters lifeline-end nodes in sequence diagrams, and returns compile errors. No contradiction exists.

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 organized into clear sections (overview, usage guidance, args, return example, supported diagram types, error handling) with no filler. While longer than minimal, every sentence contributes unique information such as example output and type-specific behavior.

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?

For a single-parameter tool with no output schema, the description is complete: it defines the input, gives a concrete return example, lists supported diagram types, explains error handling, and covers behavioral nuances. An agent has everything needed to invoke it 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?

The input schema already documents d2_code with 100% coverage ('The D2 diagram source code to inspect'). The description's Args section repeats the same semantics without adding new detail, so the baseline of 3 applies.

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 opens with a specific verb phrase ('Parse and summarize the structure of D2 source code without rendering') and clearly states the deliverable: a human-readable summary of shapes, containers, connections, and boards. It explicitly distinguishes itself from d2_render, so an agent can select it correctly.

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 gives direct usage guidance: 'Use this INSTEAD of d2_render(ascii=true) for structural previews' and explains why the alternative is unreliable for cross-container connections and reverse edges. This is explicit, actionable routing information.

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

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/ItsJooL/d2-mcp'

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