Skip to main content
Glama

Format D2 Code

d2_format
Read-onlyIdempotent

Format D2 diagram source code into canonical style, normalizing whitespace, indentation, and syntax while preserving semantics. Use to clean up hand-written diagrams and ensure consistent formatting.

Instructions

Format D2 diagram source code using the d2 binary formatter.

Normalizes whitespace, indentation, and syntax to D2's canonical style. The formatted output is semantically equivalent to the input.

NOTE: This tool requires the d2 binary to be installed (unlike d2_render and d2_validate which use WASM). Install from https://d2lang.com or set D2_PATH env var.

Args:

  • d2_code (string): D2 source code to format

Returns: Formatted D2 source code string.

Examples:

  • Clean up: format "a->b:label" to "a -> b: label"

  • Normalize after editing: run on any hand-written D2 code

Error Handling:

  • Returns error if d2 binary is not found (d2_render still works without it)

  • Returns error if code has syntax errors (format requires valid syntax)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
d2_codeYesThe D2 diagram source code to format

Schema Changelog

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

  1. First observedv1.0.0

TDQS

A4.3/5.0
Behavior4/5

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

Annotations already declare readOnlyHint, idempotentHint, and non-destructive behavior. The description adds valuable context beyond those hints: it normalizes formatting, preserves semantic meaning, requires the d2 binary, and fails if the binary is missing or syntax is invalid. This is consistent with the annotations and gives the agent realistic expectations.

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 well organized with clear sections: purpose, behavior, binary requirement, args, returns, examples, and error handling. Every section contributes useful information and there is no filler. The most important scoping detail (requiring the d2 binary) is front-loaded early.

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 tool with one simple parameter, no output schema, and rich annotations, the description fully covers the calling context: what it does, what it returns, when it fails, and how it differs from siblings. Nothing an agent needs to invoke it correctly is missing.

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% and the single parameter d2_code is already well described in the schema. The description's Args section repeats the same meaning without adding constraints like minLength or maxLength. Baseline 3 is appropriate because the schema carries the parameter documentation burden.

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 and resource: 'Format D2 diagram source code using the d2 binary formatter.' It goes on to state the canonicalization goal and semantic equivalence, and it explicitly contrasts with d2_render and d2_validate regarding the WASM vs binary backend, which differentiates it from siblings.

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 provides clear context for when to use the tool ('Clean up', 'Normalize after editing') and explicitly distinguishes it from siblings by noting the d2 binary requirement, saying 'unlike d2_render and d2_validate which use WASM.' It does not explicitly say 'use d2_validate for validation' but the context is sufficient.

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