Commit Graph

96 Commits

Author SHA1 Message Date
Tom
d8fe139917 fix: replace placeholder LICENSE with standard MIT text 2026-03-05 15:15:16 +01:00
mixelpixx
385711b3b0 Merge pull request #53 from Kletternaut/fix/inline-extends-symbols-in-lib-symbols-v2
fix(dynamic-loader): inline extends symbols for lib_symbols compatibility
2026-03-04 18:45:34 -05:00
Tom
2340afe9a4 fix(dynamic-loader): inline extends symbols for lib_symbols compatibility
KiCad 9 refuses to load any schematic whose lib_symbols section contains
an (extends ...) clause, because the extends mechanism is only valid
inside .kicad_sym library files - not inside schematics.

The previous implementation kept the (extends ...) clause and prepended
the parent symbol block with a qualified name, but left the child's
extends referring to the unqualified parent name, causing:
  'Error loading schematic: No parent for extended symbol Q_NMOS_GSD'

Fix: add _iter_top_level_items() and _inline_extends_symbol() helpers.
When a library symbol uses extends, the parent's content (pins, graphics,
sub-symbols) is now merged directly into the child definition:
- Parent properties are overridden by child property values
- Sub-symbol names are renamed from ParentName_X_Y to ChildName_X_Y
- The (extends ...) clause is removed entirely
- Only the fully-resolved child symbol is injected into lib_symbols

Affected symbols include Transistor_FET:2N7002, Transistor_BJT:*,
Regulator_Linear:*, Regulator_Switching:* and many others (~30% of the
KiCad standard library uses extends).

Fixes #52
2026-03-04 15:27:59 +01:00
mixelpixx
d8568fff12 Merge pull request #50 from pasrom/fix/mcp-server-bugs
Fix 6 bugs discovered during end-to-end MCP workflow testing
2026-03-02 08:09:57 -05:00
mixelpixx
688bebdf0c Merge pull request #51 from Kletternaut/fix/remove-invalid-comments-in-templates
fix: remove invalid ;; comments from template (KiCAD parse error, regression from b98c94b)
2026-03-02 08:09:31 -05:00
Tom
53014b9733 fix: remove invalid ;; comments from template_with_symbols_expanded.kicad_sch
PROBLEM
-------
Upstream commit b98c94b added 7 comment lines (;; PASSIVES, ;; SEMICONDUCTORS,
;; INTEGRATED CIRCUITS, ;; CONNECTORS, ;; POWER/REGULATORS, ;; MISC,
;; TEMPLATE INSTANCES) to template_with_symbols_expanded.kicad_sch.

KiCAD's S-expression parser does NOT support any comment syntax.
It expects every non-empty line to begin with '('. These comments caused
KiCAD 9 to refuse opening any schematic generated from this template:

  Expecting '(' in <file>.kicad_sch, line 8, offset 5

AFFECTED USERS
--------------
Any project whose .kicad_sch was generated by the MCP server after upstream
commit b98c94b and before this fix contains the same invalid lines. Those
files must be repaired manually: open the .kicad_sch in a text editor and
delete every line beginning with ';;'.

FIX
---
Remove all 7 ;; lines from the template. No functional change — the comments
provided no information that is not already evident from the symbol names.

ALSO
----
CHANGELOG: add critical bug-fix entry for this regression under v2.2.2-alpha
2026-03-01 21:12:51 +01:00
Roman PASSLER
2dd9de6a52 style: apply black formatting to changed files 2026-03-01 19:15:32 +01:00
Roman PASSLER
61356d42cb fix(schematic): rewrite component lookup to handle single-line files
The previous line-based parser (split("\n") + line-by-line regex)
failed when the MCP server itself generates .kicad_sch files as a
single line. The new implementation works directly on the raw content
string using parenthesis-depth matching to find symbol blocks,
making it independent of formatting/whitespace.
2026-03-01 18:43:20 +01:00
Roman PASSLER
a018575bbc fix(mounting-hole): generate unique references MH1, MH2, etc.
All mounting holes were assigned the same reference "MH", violating
PCB conventions and causing conflicts. Now queries existing footprints
to find the next available MH number.
2026-03-01 18:41:39 +01:00
Roman PASSLER
4e70342eae fix(drc): extract violation coordinates from kicad-cli JSON items
kicad-cli DRC JSON output stores coordinates in items[].pos.x/y,
not at the violation top level. The code was reading violation.x/y
which don't exist, falling back to (0, 0) for every violation.
Now correctly reads the position from the first item in each
violation entry.
2026-03-01 18:40:45 +01:00
Roman PASSLER
ec1939bef4 fix(copper-pour): add outline parameter and fallback to board outline
Two issues fixed:
1. TypeScript schema was missing the outline parameter entirely,
   so MCP clients couldn't send pour boundary points.
2. Python code read "points" key but schema defined "outline" key.

Now accepts "outline" (with "points" as fallback for backwards
compatibility). When no outline is provided, automatically uses
the board edge bounding box as the pour boundary.
2026-03-01 18:40:24 +01:00
Roman PASSLER
246050001a fix(nets): use GetNetClassName() instead of GetClassName() on NETINFO_ITEM
NETINFO_ITEM objects don't have a GetClassName() method, causing
an AttributeError crash when listing nets. The correct method is
GetNetClassName() which returns the net class name string.
2026-03-01 18:37:55 +01:00
Roman PASSLER
c7d6d0126f fix(bom): use GetUniStringLibId() instead of str() for footprint in BOM export
str(module.GetFPID()) returns the Swig proxy representation like
"<pcbnew.LIB_ID; proxy of ...>" instead of the actual footprint name.
GetUniStringLibId() returns the proper "Library:Footprint" string.
2026-03-01 18:37:35 +01:00
Tom
820097a570 docs: update CHANGELOG for v2.2.2-alpha (PR #49) 2026-03-01 17:40:40 +01:00
mixelpixx
e348ed1811 Merge pull request #49 from Kletternaut/feat/footprint-symbol-tools
fix: project-local library resolution + copy_routing_pattern geometric fallback + TypeScript tool
2026-03-01 10:47:15 -05:00
Tom
16f795c214 chore: update .gitignore - add KiCAD backup file patterns 2026-03-01 15:36:17 +01:00
Tom
d9c296f586 fix: restore KiCAD 9 format version in templates (regression from upstream 2b38796)
Upstream commit 2b38796 downgraded template_with_symbols.kicad_sch and
template_with_symbols_expanded.kicad_sch from version 20250114 to 20240101.

KiCAD 9 requires version 20250114 - files with older versions cause parse
errors or are rejected. This was originally fixed in ce78fb4.
2026-03-01 15:05:36 +01:00
Tom
f0d738fff1 feat: add route_pad_to_pad tool
Convenience wrapper around route_trace that eliminates the need for
separate get_pad_position calls before routing.

- Accepts fromRef/fromPad/toRef/toPad instead of raw coordinates
- Automatically looks up pad positions from board footprints
- Auto-detects net from pad assignment (overridable via net param)
- Returns fromPad/toPad position info in response
- Saves ~2 tool calls (64+ calls for a full TMC2209 board) vs 3-step flow

Registered in: routing.py, kicad_interface.py (dispatch), routing.ts (MCP)
2026-03-01 15:03:52 +01:00
Tom
b33d6e22fd fix: project-local library resolution + copy_routing_pattern geometric fallback + TypeScript tool
- fix: DynamicSymbolLoader reads project sym-lib-table before global dirs
  add_schematic_component now finds symbols from project-local .kicad_sym files
  project_path derived automatically from schematic file path

- fix: place_component reloads FootprintLibraryManager with project_path
  new boardPath parameter passed to place_component tool (TypeScript + Python)
  _handle_place_component wrapper recreates LibraryManager per project

- fix: copy_routing_pattern geometric fallback when pads have no nets
  primary filter: net-based (when pads are assigned to nets)
  fallback: bounding box of source footprint pads +5mm tolerance
  filterMethod field in response indicates which mode was used

- feat: register copy_routing_pattern as MCP tool in routing.ts
  sourceRefs, targetRefs, includeVias, traceWidth parameters

Live tested: ESP32 + 2x TMC2209 in Test3 project
  13 traces U2 routed, copy_routing_pattern copied all 13 to U3
  offset Y+30mm correct, 26 total traces verified
2026-03-01 15:03:52 +01:00
KiCAD MCP Bot
2b38796409 fix: Update schematic format to KiCAD 9 and fix invalid UUIDs (#37)
- Update schematic version from 20230121 (KiCAD 7) to 20240101 (KiCAD 9)
- Replace invalid all-zeros UUIDs in template files with valid UUIDs
- Add post-copy UUID regeneration to ensure each project gets unique UUID
- Add UTF-8 encoding and Unix line endings for cross-platform compatibility

Fixes the root cause where templates were copied with invalid UUIDs and
outdated version format, causing KiCAD 9.0.x to reject the schematic files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 08:02:52 -05:00
KiCAD MCP Bot
b98c94be42 docs: Update macOS installation, JLCPCB database size, and part counts (#45, #43)
- Add macOS venv setup using KiCAD's bundled Python (fixes #45)
- Update JLCPCB database size from 1-2 GB to 3-5 GB (accurate for 2.5M+ parts)
- Update all "100k+" references to "2.5M+" for consistency
- Update jlcpcb-api.ts tool description (JLCSearch API, no auth required)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 07:57:37 -05:00
mixelpixx
00e72f49b1 Update print statement from 'Hello' to 'Goodbye' 2026-03-01 07:43:38 -05:00
mixelpixx
7a7f8524ec Update print statement from 'Hello' to 'Goodbye' 2026-03-01 07:42:53 -05:00
mixelpixx
b9af05e125 Merge pull request #48 from Kletternaut/feat/footprint-symbol-tools
feat: footprint + symbol creator tools (create_footprint, create_symbol + 6 more)
2026-02-28 20:27:07 -05:00
Tom
914c4fa1e3 feat: add footprint + symbol creator tools
Footprint tools:
- create_footprint: generates .kicad_mod via f-string (SMD/THT, courtyard, silkscreen, fab)
- edit_footprint_pad: updates size/position/drill/shape in-place
- list_footprint_libraries: scans .pretty directories
- register_footprint_library: adds entry to fp-lib-table

Symbol tools:
- create_symbol: generates .kicad_sym with pins, rectangles, polylines
- delete_symbol: removes symbol from library
- list_symbols_in_library: lists all symbols in a .kicad_sym file
- register_symbol_library: adds entry to sym-lib-table

Also:
- Fix footprint format version: 20250114 (schematic) -> 20241229 (footprint)
- Two MCP prompts: create_footprint_guide + footprint_ipc_checklist

Live tested: TMC2209 footprint (19 pads), R_0603_Test, edit_footprint_pad,
TMC2209_Custom symbol with pins all confirmed in KiCAD 9
2026-02-28 22:42:27 +01:00
Tom
66066005d0 Merge pull request #1 from Kletternaut/fix/template-kicad9-format
Bug fixes + new tool, discovered via live testing on a real JLCPCB/KiCAD 9 project.

### Changes

1. **Format version bump**: KiCAD 7 → KiCAD 9 (`20230121` → `20250114`)
   MCP server targets KiCAD 9 exclusively. Every newly created schematic showed spurious "older version" warning.

2. **Remove corrupt `_TEMPLATE_*` placed-symbol blocks** (`lib_id -100` crash)
   13 blocks with `(lib_id -100)` caused KiCAD null-pointer crash on box-select.
   Same sexpdata serializer root cause as PR #40.

3. **Fix footprint param silently ignored** in `add_schematic_component`
   The `footprint` field was never passed through the call chain to the f-string in `DynamicSymbolLoader`.

4. **Fix `delete_schematic_component` only deleting first duplicate**
   `break` after first match replaced with full scan + back-to-front deletion. Response now includes `deleted_count`.

5. **New tool: `edit_schematic_component`**
   Update `footprint`, `value`, and/or `reference` in-place on an existing placed symbol.
2026-02-28 15:32:41 +01:00
Tom
b1eb570183 fix: footprint param ignored, delete duplicates, add edit_schematic_component
Bug 1 - add_schematic_component: footprint parameter silently ignored
  The footprint value from MCP params was never passed through to
  DynamicSymbolLoader.add_component() / create_component_instance().
  Every placed symbol had an empty Footprint field regardless of input.
  Fix: added footprint: str='' to both functions, passed through all
  call sites, added footprint to schematic.ts tool schema.

Bug 2 - delete_schematic_component: only deleted first duplicate
  When a reference appeared multiple times (e.g. after a failed
  add attempt), only the first instance was removed due to break
  after first match. Fix: collect all matching blocks first, then
  delete back-to-front to preserve indices. Response now includes
  deleted_count.

New tool - edit_schematic_component
  Update footprint, value or reference of a placed symbol in-place.
  More efficient than delete+re-add: preserves position and UUID.
  Accepts: schematicPath, reference, footprint?, value?, newReference?

All 3 fixes verified by live tests on a real JLCPCB/KiCAD 9 project:
  - R_TEST1: footprint Resistor_SMD:R_0603_1608Metric written correctly
  - J1 duplicate: deleted_count=2 with single call
  - J2 edit: PinSocket footprint assigned in-place, no delete+add needed
  - PCB update (F8) confirmed: only components with footprint imported
2026-02-28 15:21:07 +01:00
Tom
ce78fb4111 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.
2026-02-28 14:40:32 +01:00
mixelpixx
9dbabeb0a5 Merge pull request #44 from Kletternaut/feat/routing-component-tools-and-bugfixes
feat: Add missing routing/component tools and fix SWIG/UUID bugs
2026-02-28 07:58:05 -05:00
Tom
1ba86f7769 feat: datasheet tools + fix missing delete_schematic_component
New tools - datasheet:
- get_datasheet_url: construct LCSC datasheet PDF URL + product page URL
  without any API key (URL schema: https://www.lcsc.com/datasheet/<C#>.pdf)
- enrich_datasheets: scan .kicad_sch, write LCSC datasheet URL into every
  symbol that has an LCSC property but an empty Datasheet field; supports
  dry_run=true for preview; text-based implementation (no skip writes)
  Implementation: python/commands/datasheet_manager.py

New tool - schematic:
- delete_schematic_component: remove a placed symbol from a .kicad_sch file
  by reference designator (e.g. R1, U3)

Bug fix - delete_schematic_component (two separate root causes):
1. No MCP tool named delete_schematic_component was registered at all.
   Any delete-symbol request fell through to the PCB-only delete_component
   tool which searches pcbnew.BOARD and always returned 'Component not found'
   for schematic symbols.
2. component_schematic.py::remove_component() still used skip for writes.
   PR #40 rewrote DynamicSymbolLoader (add path) to avoid skip-induced
   schematic corruption, but the delete path was not touched by that PR.

Fix: _handle_delete_schematic_component in kicad_interface.py uses direct
text manipulation with parenthesis-depth tracking (same technique as PR #40),
bypassing component_schematic.py entirely. Error message explicitly guides
users: 'use delete_component for PCB footprints'.

Files changed:
- python/commands/datasheet_manager.py (new)
- src/tools/datasheet.ts (new)
- python/kicad_interface.py: 3 new handlers + dispatch entries
- src/tools/schematic.ts: delete_schematic_component tool
- src/server.ts: registerDatasheetTools import + call
- src/tools/index.ts: export registerDatasheetTools
- CHANGELOG.md: document all above
2026-02-28 13:48:35 +01:00
Tom
76503b144c fix: generate_netlist schematic_path, PinLocator cache, server.ts Python detection
- connection_schematic.py: generate_netlist() now accepts schematic_path param,
  threaded through to get_net_connections() so PinLocator is actually invoked
  (previously only 1 connection per component was returned due to fallback break)
- kicad_interface.py: pass schematic_path to generate_netlist()
- pin_locator.py: add _schematic_cache to avoid loading Schematic() once per pin
  (was causing timeout: O(nets x components x pins) Schematic() calls)
- server.ts: remove fragile PYTHONPATH?.includes('KiCad') condition,
  always prefer KiCAD bundled Python on Windows when executable exists
- CHANGELOG.md: document fixes under v2.2.0-alpha
2026-02-28 01:23:36 +01:00
Tom
2945b52eae feat: Add missing routing/component tools and fix SWIG/UUID bugs
New MCP tools added (TypeScript layer):
- Routing: delete_trace, query_traces, get_nets_list, modify_trace,
  create_netclass, route_differential_pair, refill_zones (with SWIG warning)
- Component: get_component_pads, get_component_list, get_pad_position,
  place_component_array, align_components, duplicate_component

Bug fixes:
- routing.py: Fix SwigPyObject UUID comparison (str() -> m_Uuid.AsString())
- routing.py: Fix SWIG iterator invalidation after board.Remove()
  by converting board.Tracks() to list() before iteration
- routing.py: Add board.SetModified() and clear Python refs after Remove()
  to prevent dangling SWIG pointers crashing subsequent calls
- routing.py: Wrap each track access in try/except in query_traces()
  to gracefully skip invalid track objects after bulk delete
- routing.py: Add missing return statement (mypy fix)
- library.py: Fix search_footprints param mapping search_term->pattern
- library.py: Fix fp.name -> fp.full_name field access
- library.py: Accept both 'pattern' and 'search_term' parameter names
- library.py: Add library filter support in search_footprints
- library.py: Fix loop variable shadowing Path object (mypy fix)
- design_rules.py: Add type annotation for violation_counts (mypy fix)

Contribution guidelines followed (CONTRIBUTING.md):
- black python/ applied (3 touched files pass without changes)
- mypy python/ passes with 0 errors on all changed files
- npx prettier --write applied to changed TypeScript files
- npm run build passes (tsc --noEmit: 0 errors)
- Commit messages follow feat:/fix: convention

Note on diff size: The large insertion/deletion count in the changed files
is due to black and prettier reformatting previously unformatted code
(missing trailing commas, quote style, line length). The actual logic
changes are limited to the 6 files listed above.

Note: refill_zones has known SWIG segfault risk (see KNOWN_ISSUES.md).
Prefer IPC backend (KiCAD open) or zone fill via KiCAD UI.
2026-02-27 18:15:46 +01:00
KiCAD MCP Bot
b5a1483fc2 docs: Update KNOWN_ISSUES.md - schematic support now fully working
Issue #26 fixed in PR #40 - DynamicSymbolLoader rewritten to use text
manipulation instead of sexpdata, preserving KiCAD file formatting.
2026-02-26 11:02:33 -05:00
FlowSync0
a69d288251 fix: Rewrite DynamicSymbolLoader to prevent schematic file corruption (#40)
Fixes Issue #26 - add_schematic_component corrupts .kicad_sch files

Complete rewrite of DynamicSymbolLoader to use text manipulation instead of sexpdata:
- Preserves KiCAD file formatting perfectly
- Correctly handles KiCAD 9 symbol naming conventions (library prefix for top-level, no prefix for sub-symbols)
- Resolves parent-child symbol dependencies with (extends)
- Adds symbol caching for performance
- Simplifies component addition workflow

Tested on KiCAD 9.0.7 with R, C, LED, ESP32, and transistor components.
Compatible with recent Windows fixes (UUID generation, IPC, JLCPCB).

Co-authored-by: FlowSync0 <249798311+FlowSync0@users.noreply.github.com>
2026-02-26 11:02:10 -05:00
KiCAD MCP Bot
e4fa774eda fix: Phase 2 - DRC API fix and JLCPCB documentation restructure (#33, #34, #43)
Phase 2 medium-priority fixes addressing three issues:

Issue #33 - DRC violations API broken in KiCAD 9.0:
- Reimplemented get_drc_violations() to use run_drc() internally
- run_drc uses kicad-cli which is stable across KiCAD versions
- Maintains backward compatibility while fixing GetDRCMarkers() issue
- Added documentation to KNOWN_ISSUES.md
- Returns violations in original format by parsing kicad-cli JSON output

Issue #34 - JLCPCB API documentation misleading:
- Restructured README and JLCPCB_USAGE_GUIDE.md
- Now leads with JLCSearch public API (no authentication required)
- Moved official JLCPCB API to "Advanced" section with clear requirements
- Clarified that official API requires enterprise account + order history
- Makes it easier for new users to get started

Issue #43 - JLCPCB part count documentation inaccurate:
- Updated all "100k+" references to "2.5M+" (accurate catalog size)
- Updated download time estimates to 40-60 minutes
- Updated expected database size to 1-2 GB
- Clarified 100-part pagination limit in JLCSearch API

Documentation changes:
- README.md: Updated JLCPCB integration section
- docs/JLCPCB_USAGE_GUIDE.md: Complete restructure with 3 approaches
- docs/KNOWN_ISSUES.md: Added DRC fix documentation

All changes improve user experience and documentation accuracy.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-26 10:11:55 -05:00
KiCAD MCP Bot
b4d114ac74 fix: Address critical Windows compatibility and JLCPCB issues (#36, #37, #35)
Phase 1 critical fixes addressing three high-priority issues:

Issue #36 - Windows IPC backend crash (os.getuid not available):
- Add platform detection to skip Unix-specific socket paths on Windows
- Use hasattr check before calling os.getuid()
- Windows now uses auto-detect fallback (named pipes)
- Maintains full Unix socket support on Linux/macOS

Issue #37 - Windows schematic file creation broken:
- Generate unique UUIDs instead of invalid all-zeros UUID
- Add explicit UTF-8 encoding for cross-platform compatibility
- Force Unix line endings (LF) to prevent Windows CRLF issues
- Update template file with valid placeholder UUID
- Fix hardcoded /tmp/ paths in wire_manager.py and pin_locator.py

Issue #35 - JLCPCB download limited to 100 parts:
- Change batch_size from 1000 to 100 to match tscircuit API limit
- Remove premature loop termination when batch < batch_size
- Add documentation explaining API limitation
- Expected result: Full ~2.5M part catalog download (40-60 minutes)

All changes maintain backward compatibility and include detailed comments.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-26 10:03:20 -05:00
KiCAD MCP Bot
b9bd401b11 feat: Add routing replication commands for Issue #30 Phase 2
Implements advanced trace manipulation and routing pattern copying:
- Enhanced delete_trace with net-based bulk deletion and layer filtering
- Added modify_trace to change width, layer, or net by UUID/position
- Added copy_routing_pattern to replicate routing between component groups

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 19:24:59 -05:00
KiCAD MCP Bot
04db774a2b feat: Address multiple open issues (#32, #30, #26, #19)
Issue #32 - Unknown command errors:
- Register get_board_extents in command_routes (was implemented but not registered)
- Implement find_component command with pattern matching on reference/value/footprint
- Add schemas for both commands

Issue #30 - PCB routing replication (Phase 1):
- Implement get_component_pads: returns all pads with positions, nets, shapes
- Implement get_pad_position: returns specific pad coordinates and properties
- Implement query_traces: query traces by net, layer, or bounding box
- Add schemas for all new commands

Issue #26 - Schematic workflow:
- Add missing schemas for add_schematic_connection, add_schematic_net_label,
  connect_to_net, get_net_connections, and generate_netlist

Issue #19 - macOS Python path detection:
- Add Python 3.13 to version detection
- Add alternative KiCAD installation paths (user Applications, capitalization variants)
- Add Homebrew Python fallback paths for Apple Silicon and Intel Macs
- Expand platform_helper.py with same improvements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 19:17:35 -05:00
KiCAD MCP Bot
d2723bc292 fix: Resolve Python executable validation failure on Linux (Issue #29)
This commit fixes the critical bug where the MCP server fails to start on
Linux with "Python executable not found: python3" even when python3 is
correctly installed and available in PATH.

Root Cause:
- findPythonExecutable() returned 'python3' (command name) on Linux
- validatePrerequisites() used existsSync('python3') which checks current
  directory, not PATH
- Validation failed even though spawn() would resolve 'python3' via PATH

Changes Made:

1. Enhanced findPythonExecutable() for Linux (src/server.ts:42-126):
   - Added Linux platform detection
   - Check KiCad bundled Python paths first (/usr/lib/kicad/bin/python3, etc.)
   - Use 'which python3' to resolve system python3 to absolute path
   - Fallback to common system paths (/usr/bin/python3, /bin/python3)
   - Import execSync for 'which' command execution

2. Improved validatePrerequisites() (src/server.ts:214-266):
   - Distinguish between absolute paths and command names
   - Use existsSync for absolute paths
   - Use --version execution test for command names
   - Added Linux-specific error messages and troubleshooting

3. Documentation Updates (README.md:409-444):
   - Added "Linux Python Detection" section
   - Documented detection priority order
   - Added troubleshooting steps for KICAD_PYTHON
   - Clarified that no manual config needed for standard installations

Testing:
- Build completed successfully (npm run build)
- Python detection now resolves /usr/bin/python3 on Ubuntu/Debian
- Maintains backward compatibility with Windows/macOS
- KICAD_PYTHON override still works

Fixes #29

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 22:23:54 -05:00
KiCAD MCP Bot
aa18486359 fix: Replace SetFootprintName with SetFPID for KiCAD 9.x compatibility
Fixes issue #28 where place_component fails on KiCAD 9.0.5 with:
'FOOTPRINT' object has no attribute 'SetFootprintName'

KiCAD 9.x API changed from SetFootprintName() to SetFPID(LIB_ID).

Changes:
- place_component: Parse footprint string and use SetFPID with LIB_ID
- update_component: Parse footprint string or preserve existing library
- duplicate_component: Use source.GetFPID() directly

All three methods now use the KiCAD 9.x API while maintaining backward
compatibility with the footprint parameter format.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 11:43:54 -05:00
KiCAD MCP Bot
6fffb39bc7 docs: Document Phase 2 power net and wire connectivity completion
Comprehensive documentation of Phase 2 achievements including power symbol support, wire graph analysis for net connectivity, critical bug fixes (template mapping, special character handling), and 100% passing integration tests. Removes emoji per style guidelines.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 11:14:18 -05:00
KiCAD MCP Bot
a5a542b1e9 feat: Implement wire graph analysis for net connectivity (Phase 2)
Major Feature: Wire Graph Analysis
- Rewrote get_net_connections() with geometric wire tracing
- Added points_coincide() helper for coordinate matching
- Implemented multi-step connectivity algorithm:
  1. Find all labels with target net name
  2. Trace wires connected to label positions
  3. Find component pins at wire endpoints using PinLocator
  4. Return accurate component/pin connections

Technical Implementation:
- Tolerance-based point matching (0.5mm for grid alignment)
- Wire polyline support (traces multi-segment paths)
- Accurate pin location matching with rotation support
- Fallback proximity matching when schematic_path unavailable

Testing Results:  100% PASSING
- VCC: 2 connections (R1_/1, D1_/1) ✓
- GND: 4 connections (R1_/2, R2_/2, C1_/2, D1_/2) ✓
- +3V3: 1 connection (R2_/1) ✓
- +5V: 1 connection (C1_/1) ✓
- Netlist generation: 4 nets detected ✓
- Comprehensive power circuit test: PASSED ✓

Updates:
- get_net_connections() now accepts optional schematic_path parameter
- generate_netlist() automatically uses improved connectivity analysis
- Full integration with PinLocator for accurate pin matching

Addresses: Phase 2 net connectivity analysis requirements

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:52:20 -05:00
KiCAD MCP Bot
b77f0081d6 fix: Resolve template mapping bug in dynamic symbol loading
Critical Bug Fixes:
1. Changed get_or_create_template() return type to tuple (template_ref, needs_reload)
2. Added automatic schematic reload after dynamic loading
3. Replaced hasattr() checks with symbol iteration (handles special characters like +)
4. Added template_exists() helper function
5. Fixed template lookup to check multiple potential reference formats

Issues Resolved:
- Multiple components of same type can now be added after dynamic loading
- Power symbols with special characters (+3V3, +5V) work correctly
- Template references with library prefix are properly detected
- Schematic object stays in sync with file after dynamic injections

Testing:
-  Power symbols: 4/4 loaded (VCC, GND, +3V3, +5V)
-  Components: 4/4 placed (R, R, C, LED)
-  Connections: 8/8 created
-  Special character handling (+3V3, +5V) working

Technical Details:
- hasattr() fails with attribute names containing special characters
- Must iterate symbols and check Reference.value directly
- Schematic reload required after S-expression injection
- Template name formats: _TEMPLATE_R, _TEMPLATE_power_VCC, _TEMPLATE_Device_R

Addresses template mapping issues found during Phase 2 power net testing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:49:08 -05:00
KiCAD MCP Bot
c67f400383 feat: Update connect_to_net to use WireManager (Phase 2)
Updates:
- ConnectionManager.connect_to_net() now uses PinLocator + WireManager
- Accepts Path parameter instead of Schematic object
- Creates wire stub (2.54mm) from pin to label position
- Uses WireManager.add_wire() and WireManager.add_label()
- Updated MCP handler _handle_connect_to_net()

Testing:
-  connect_to_net test: 100% passing
-  R1/1 → VCC wire stub + label
-  D1/2 → GND wire stub + label
-  Verified with kicad-skip: 5 wires, 4 labels

Part of Phase 2: Net Labels & Named Nets (Issue #26)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:40:56 -05:00
KiCAD MCP Bot
d396ccd61f docs: Update README and CHANGELOG with wiring implementation
Documentation Updates:
- README: Updated Schematic Design section from 6 to 9 tools
- Added "Wiring & Connections" subsection highlighting new capabilities
- Documented automatic pin discovery with rotation support
- Listed smart routing options (direct, orthogonal)
- Added net label management features
- CHANGELOG: Added Phase 1 wiring system entry with complete feature list

New Features Documented:
- add_schematic_connection with auto pin discovery
- add_schematic_net_label with orientation control
- WireManager and PinLocator implementation
- S-expression precision and format compliance

Part of Issue #26 schematic wiring implementation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:39:07 -05:00
KiCAD MCP Bot
16703e28f9 feat: Integrate WireManager and PinLocator into MCP interface handlers
Updates MCP handlers to use the new wiring infrastructure:

Handler Updates:
- _handle_add_schematic_wire: Uses WireManager.add_wire() with S-expression manipulation
- _handle_add_schematic_connection: Uses ConnectionManager with automatic pin discovery and routing options (direct, orthogonal_h, orthogonal_v)
- _handle_add_schematic_net_label: Uses WireManager.add_label() with support for label types and orientation

Features:
- Automatic pin location discovery with rotation support
- Professional wire routing (direct, orthogonal horizontal-first, orthogonal vertical-first)
- Net label placement with customizable types (label, global_label, hierarchical_label)
- Comprehensive error handling and logging

Testing:
- All MCP handlers tested and verified working
- Integration test: 100% passing (2 wires, 1 label created successfully)
- Verified with kicad-skip that wires and labels are correctly formed

Part of Issue #26 schematic wiring implementation (Phase 1)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:35:16 -05:00
KiCAD MCP Bot
203572cd1a docs: Create comprehensive schematic wiring implementation plan
Created detailed 500+ line implementation plan for schematic wiring tools
addressing user questions from Issue #26.

## Plan Overview

**Phases:**
1. Core Wire Functionality (Week 1) - 26 hours
   - Research kicad-skip wire API
   - Fix wire creation
   - Implement pin discovery
   - Fix add_schematic_connection

2. Net Labels & Named Nets (Week 1-2) - 28 hours
   - Net label creation
   - connect_to_net implementation
   - Net connection discovery
   - Power symbol support

3. Advanced Features (Week 2-3) - 28 hours
   - Junction support
   - No-connect flags
   - Orthogonal routing
   - Bus and hierarchical labels

4. Validation & Polish (Week 3-4) - 28 hours
   - ERC integration
   - Comprehensive testing
   - Error handling
   - Documentation

**Total Timeline:** 5 weeks (110 hours)
**Accelerated:** 2-3 weeks (core features only)

## Technical Approach

**Option A:** Use kicad-skip native API (preferred)
**Option B:** S-expression manipulation (fallback, like dynamic loading)
**Recommended:** Hybrid approach

## Key Challenges Identified

1. kicad-skip wire API uncertainty - needs research
2. Pin location calculation with rotation
3. Smart wire routing (orthogonal preferred)
4. Net label attachment to wires

## Current State

- ConnectionManager class exists with methods
- MCP handlers registered (6 tools)
- Basic implementation present but untested
- User reported add_schematic_wire fails

## Next Steps

1. Research kicad-skip wire API (TODAY)
2. Create test environment (TOMORROW)
3. Implement basic wire (THIS WEEK)
4. Fix pin discovery (THIS WEEK)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:24:25 -05:00
KiCAD MCP Bot
60d19e5235 docs: Update README with dynamic symbol loading breakthrough
Updated README.md to highlight the major dynamic loading feature:

 Updated 'What's New' section
- Added Phase 2: Dynamic Symbol Loading breakthrough
- Documented access to all ~10,000 KiCad symbols
- Added technical architecture explanation
- Example usage with STM32 microcontroller

 Updated Schematic Design tools section
- Changed from 'template-based' to 'dynamic loading'
- Explained automatic library search and injection
- Noted fallback to 13 static templates

 Updated Project Status
- Added 'DYNAMIC SYMBOL LOADING' as key feature
- Highlighted access to full KiCad symbol libraries
- Noted automatic dynamic injection capability

This brings the README in line with the breakthrough achieved in
commits 1d9e92a and 148f3ef.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:20:44 -05:00
KiCAD MCP Bot
148f3ef401 docs: Update dynamic loading status - Phase C COMPLETE!
Updated DYNAMIC_LOADING_STATUS.md to reflect:

 Phase C (MCP Integration) - COMPLETE
- Full MCP interface integration done
- Save → inject → reload → clone orchestration working
- Smart detection and automatic fallback
- 100% test pass rate (5/5 components)

Added comprehensive integration test results section showing:
- Test matrix with 5 components
- 3 successful dynamic loads (Battery, Fuse, Transformer)
- Zero configuration required for users
- Access to ~10,000 KiCad symbols now available

Status: PRODUCTION READY! 🚀

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:16:47 -05:00
KiCAD MCP Bot
1d9e92a165 feat: Complete MCP integration for dynamic symbol loading! 🎉
MAJOR MILESTONE: Dynamic symbol loading is now fully integrated through the MCP interface!

## What's Working

 **Full MCP Integration**
- Modified _handle_add_schematic_component to orchestrate dynamic loading
- Detects when symbols need dynamic loading (not in static templates)
- Automatically saves → injects → reloads → clones → saves workflow

 **ComponentManager Integration**
- Added schematic_path parameter to add_component() and get_or_create_template()
- Seamlessly switches between static templates and dynamic loading
- Proper error handling and fallback mechanisms

 **Smart Detection**
- Checks if component type is in static template map
- Verifies template exists in current schematic
- Only triggers dynamic loading when truly needed

 **Reload Orchestration**
- Saves schematic before dynamic loading (preserves changes)
- Calls DynamicSymbolLoader.load_symbol_dynamically()
- Reloads schematic to get newly injected symbols
- Clones from reloaded templates

## Test Results

End-to-end integration test:  **100% PASSING**

Components tested:
- R (resistor) - static template, dynamically loaded
- C (capacitor) - static template, dynamically loaded
- Battery - pure dynamic loading 
- Fuse - pure dynamic loading 
- Transformer_1P_1S - pure dynamic loading 

All 5 components added successfully!

## Impact

Users can now add **ANY symbol from KiCad's ~10,000 symbol libraries** through the MCP interface!
No more limitation to 13 pre-configured templates!

## Technical Details

1. MCP handler detects dynamic loading need
2. Saves current schematic state
3. Calls dynamic loader (injects symbol + creates template)
4. Reloads schematic (kicad-skip sees new template)
5. Clones template to create component
6. Saves final result

Response includes:
- success status
- dynamic_loading_used flag
- symbol_source (library:symbol)
- template_reference

## Files Modified

- python/kicad_interface.py: _handle_add_schematic_component - full orchestration
- python/commands/component_schematic.py: add_component() and get_or_create_template() - schematic_path support

## Time Estimate vs Actual

Estimated: 2-3 hours
Actual: ~2 hours
Status:  ON TARGET!

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 10:16:07 -05:00