fix: update templates to KiCAD 9 format + remove corrupt _TEMPLATE_ blocks

Verified by live test: created a fresh schematic via MCP, result shows
format version 20250114, 0 _TEMPLATE_ hits, 0 (lib_id -100) hits, 24
real components placed cleanly.

--- Format version bump (20230121 KiCAD 7 -> 20250114 KiCAD 9) ---
Files: python/templates/*.kicad_sch, python/commands/project.py,
       python/commands/schematic.py

Root cause: the MCP server targets KiCAD 9 exclusively - pcbnew.pyd is
compiled for KiCAD 9.0 / Python 3.11.5, and server.ts explicitly selects
the KiCAD 9 bundled Python on Windows. Generating new schematics with a
2-year-old format tag caused a spurious 'This file was created with an
older KiCAD version' warning on every newly created schematic.

--- Remove corrupt _TEMPLATE_* placed-symbol blocks ---
File: python/templates/template_with_symbols_expanded.kicad_sch

Root cause: the expanded template was generated by the old sexpdata
serializer (same corruption PR #40 fixed for DynamicSymbolLoader add-path).
The serializer converted the string 'Device:R' to integer -100, producing
(lib_id -100) instead of (lib_id Device:R). KiCAD cannot resolve an
integer as a library reference and crashes with a null-pointer when the
user attempts to select these symbols. They appeared as grey _TEMPLATE_R?,
_TEMPLATE_C?, _TEMPLATE_U_REG? etc. ~5000mm off-sheet - invisible during
normal work but triggering a crash on accidental box-select.

Discovered via live testing on a real JLCPCB/KiCAD 9 project.
This commit is contained in:
Tom
2026-02-28 14:40:32 +01:00
parent 9dbabeb0a5
commit ce78fb4111
7 changed files with 155 additions and 307 deletions

View File

@@ -2,6 +2,49 @@
All notable changes to the KiCAD MCP Server project are documented here.
## [2.2.1-alpha] - 2026-02-28
### Bug Fixes
- `templates/*.kicad_sch`, `project.py`, `schematic.py`: Update KiCAD schematic format
version from `20230121` (KiCAD 7) to `20250114` (KiCAD 9).
**Root cause:** The MCP server targets KiCAD 9 exclusively `pcbnew.pyd` is compiled
for KiCAD 9.0 / Python 3.11.5, and the server explicitly selects the KiCAD 9 bundled
Python on Windows. Generating new schematics with a 2-year-old format tag caused a
spurious "This file was created with an older KiCAD version, it will be updated on
save" dialog on every newly created schematic, which confused users into thinking
something was broken.
**Fix:** Updated header in all 4 template files and both inline schematic generators
(`project.py`, `schematic.py`) to emit `(version 20250114)`.
- `template_with_symbols_expanded.kicad_sch`: Remove 13 corrupt `_TEMPLATE_*`
placed-symbol blocks containing `(lib_id -100)`.
**Root cause:** The expanded template was generated by the old sexpdata serializer
(the same corruption PR #40 fixed for the DynamicSymbolLoader add-path). The serializer
converted the string `"Device:R"` to the integer `-100`, producing `(lib_id -100)`
instead of `(lib_id "Device:R")`. KiCAD cannot resolve an integer as a library
reference and crashes with a null-pointer when the user attempts to select or box-select
these symbols. They appeared as grey `_TEMPLATE_R?`, `_TEMPLATE_C?`, `_TEMPLATE_U_REG?`
etc. labels ~5000 mm outside the sheet boundary invisible during normal work but
triggering a crash when accidentally selected.
**Discovered via:** Live testing on a real JLCPCB/KiCAD 9 project where Claude Desktop
(via MCP) created a schematic from the expanded template.
**Fix:** Removed all 13 `_TEMPLATE_*` placed-symbol blocks using parenthesis-depth
tracking (same text-manipulation approach as PR #40). The `lib_symbols` section
(symbol definitions) is unchanged only the corrupt placed instances were removed.
**Affected users:** Any schematic created from `template_with_symbols_expanded.kicad_sch`
before this fix contains the same corrupt blocks. To clean an existing schematic,
remove all `(symbol (lib_id -100) ...)` blocks whose `Reference` property starts
with `_TEMPLATE_`.
---
## [2.2.0-alpha] - 2026-02-27
### New MCP Tools (TypeScript layer previously Python-only)
@@ -36,7 +79,7 @@ All notable changes to the KiCAD MCP Server project are documented here.
- `library.py`: Fix loop variable shadowing `Path` object (mypy)
- `design_rules.py`: Add type annotation for `violation_counts` (mypy)
### Pending additions (not yet committed)
### New MCP Tools (cont.)
**Datasheet tools:**
- `get_datasheet_url` - Return LCSC datasheet PDF URL and product page URL for a given
@@ -53,7 +96,7 @@ All notable changes to the KiCAD MCP Server project are documented here.
- `delete_schematic_component` - Remove a placed symbol from a `.kicad_sch` file by
reference designator (e.g. `R1`, `U3`).
### Bug Fixes (pending)
### Bug Fixes (cont.)
- `schematic.ts` / `kicad_interface.py`: Fix missing `delete_schematic_component` MCP tool.
@@ -75,7 +118,7 @@ All notable changes to the KiCAD MCP Server project are documented here.
- Error message explicitly guides the user when the wrong tool is used:
*"note: this tool removes schematic symbols, use delete_component for PCB footprints"*
### Pending fixes (not yet committed)
### Additional Bug Fixes
- `connection_schematic.py` / `kicad_interface.py`: Fix `generate_netlist` missing
`schematic_path` parameter without it `get_net_connections` always fell back to