kicad-mcp/main.py
Ryan Malloy 4ae38fed59 Rebuild on FastMCP 3 with src-layout and kicad-sch-api integration
Migrate from FastMCP 2.14.5 to 3.1.0 with complete architectural
overhaul. Adopt src-layout packaging, lazy config functions to
eliminate .env race condition, and decorator-based tool registration.

Consolidate 14 tool modules into 8 focused modules (33 tools total).
Add 9 new schematic tools via kicad-sch-api for creating and
manipulating .kicad_sch files. Drop pandas dependency (BOM uses
stdlib csv). Remove ~17k lines of stubs, over-engineering, and
dead code.

All checks pass: ruff clean, mypy 0 errors, 17/17 tests green.
2026-03-03 18:26:54 -07:00

37 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""mckicad entry point — load .env, start MCP server."""
import logging
import os
# --- Logging ---
log_file = os.path.join(os.path.dirname(__file__), "mckicad.log")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - [PID:%(process)d] - %(message)s",
handlers=[logging.FileHandler(log_file, mode="w")],
)
# --- Load .env BEFORE any mckicad imports ---
# This must happen before importing mckicad so config functions see env vars.
_dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
if os.path.exists(_dotenv_path):
with open(_dotenv_path) as _f:
for _line in _f:
_line = _line.strip()
if not _line or _line.startswith("#"):
continue
if "=" in _line:
_key, _val = _line.split("=", 1)
_key, _val = _key.strip(), _val.strip()
if (_val.startswith('"') and _val.endswith('"')) or (
_val.startswith("'") and _val.endswith("'")
):
_val = _val[1:-1]
os.environ.setdefault(_key, _val)
from mckicad.server import main # noqa: E402
if __name__ == "__main__":
main()