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

@@ -614,7 +614,8 @@ class KiCADInterface:
"message": "Schematic name is required. Provide 'name', 'projectName', or 'filename' parameter.",
}
schematic = SchematicManager.create_schematic(project_name, metadata)
sch_path = path if path and path != "." else None
schematic = SchematicManager.create_schematic(project_name, path=sch_path, metadata=metadata)
file_path = f"{path}/{project_name}.kicad_sch"
success = SchematicManager.save_schematic(schematic, file_path)