fix: create_schematic now respects the path parameter

Previously the path argument to create_schematic() was accepted by the
tool schema but silently ignored in SchematicManager.create_schematic()
(python/commands/schematic.py). The schematic file was always written
using only the bare filename, resolving to the MCP server's working
directory.

On systems where that directory is not writable (e.g. Program Files,
OneDrive-synced folders) this caused:
  [Errno 13] Permission denied: 'myproject.kicad_sch'

Fix:
- Add path: Optional[str] = None parameter to SchematicManager.create_schematic()
- Compute output_path as os.path.join(path, base_name) when path is given
- Forward the resolved path from _handle_create_schematic() into create_schematic()

Tests: added tests/test_create_schematic_path.py with three unit tests
covering: path respected, no-path fallback, and no double-suffix on .kicad_sch names.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Parment
2026-04-08 10:27:53 +02:00
parent f79a3d6435
commit b3ca93a98d
3 changed files with 94 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ class SchematicManager:
"""Core schematic operations using kicad-skip"""
@staticmethod
def create_schematic(name, metadata=None):
def create_schematic(name, path=None, metadata=None):
"""Create a new empty schematic from template"""
try:
# Determine template path (use template_with_symbols for component cloning support)
@@ -24,7 +24,8 @@ class SchematicManager:
)
# Determine output path
output_path = name if name.endswith(".kicad_sch") else f"{name}.kicad_sch"
base_name = name if name.endswith(".kicad_sch") else f"{name}.kicad_sch"
output_path = os.path.join(path, base_name) if path else base_name
if os.path.exists(template_path):
# Copy template to target location