feat(view): save 2D board view to file instead of base64 (#161)

* Feat: save 2D board view to file instead of returning base64

The 2D view was returning base64-encoded image data in JSON, which
often exceeded token/message size limits. Now saves the rendered
image (PNG/JPG/SVG) next to the PCB file and returns the file path.
This makes the output usable by tools that can read image files
directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(board): add opt-in responseMode param to get_board_2d_view

Add a responseMode string parameter (enum: inline | file, default inline)
so callers can choose how the rendered image is delivered.

- inline (default, pre-PR behavior): image bytes are base64-encoded
  and returned in the imageData response field -- backward-compatible.
- file: image is written next to the .kicad_pcb as
  <board>_2d_view.<ext> and filePath is returned -- resolves the
  MCP message-size limit problem on large boards.

Rendering logic is shared between both modes; only response packaging
differs. Updated tool schema (Python + TypeScript) and replaced the
existing test file with 5 focused unit tests covering inline/file modes
for PNG and SVG formats plus the default-is-inline contract.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gavin Colonese
2026-05-18 14:29:00 -04:00
committed by GitHub
parent c2c77f5995
commit b69a4eb88b
4 changed files with 256 additions and 26 deletions

View File

@@ -228,7 +228,16 @@ BOARD_TOOLS = [
{
"name": "get_board_2d_view",
"title": "Render Board Preview",
"description": "Generates a 2D visual representation of the current board state as a PNG image.",
"description": (
"Generates a 2D visual representation of the current board state as a PNG, JPG, or SVG image. "
"Use responseMode to control how the image is returned. "
'responseMode="inline" (default) returns the image bytes as a base64-encoded imageData '
"string in the JSON response — convenient for small boards but may exceed message-size limits on "
"large designs. "
'responseMode="file" writes the image next to the .kicad_pcb file as '
"<board>_2d_view.<ext> and returns a filePath; callers that can open local files should "
"prefer this mode for large boards."
),
"inputSchema": {
"type": "object",
"properties": {
@@ -244,6 +253,27 @@ BOARD_TOOLS = [
"minimum": 100,
"default": 600,
},
"format": {
"type": "string",
"enum": ["png", "jpg", "svg"],
"description": "Output image format (default: png)",
"default": "png",
},
"layers": {
"type": "array",
"items": {"type": "string"},
"description": "Optional list of layer names to include; all enabled layers if omitted",
},
"responseMode": {
"type": "string",
"enum": ["inline", "file"],
"default": "inline",
"description": (
"How to return the image. "
'"inline" (default): base64-encoded bytes in the imageData response field. '
'"file": write to <board>_2d_view.<ext> next to the PCB and return filePath.'
),
},
},
},
},