Inspect D2 Diagram Structure
d2_inspectParse 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
| Name | Required | Description | Default |
|---|---|---|---|
| d2_code | Yes | The D2 diagram source code to inspect |