Getting Started with Flux
rDfwCH4uowGEVeiVfrB1Eg
Last modified 1mo ago
kicad-cli ne fixed commands aape chhe. Tran tools: kicad_version, list_boards, run_drc. PCB input edit thatu nathi; JSON reports alag folder ma lakhay chhe. Autorouting, schematic edits, component placement ke pcbnew bindings aa starter ma nathi.kicad-cli.exe jaruri chhe. Installed CLI ma pcb drc --format json support hovu joie (KiCad 9 documented; Linux KiCad 10.0.6 help pan verify karyu).py -3.11 vapare chhe; 3.12 install hoy to py -3.12 karo. py na male to installer/launcher check karo athva installed Python no absolute exe path vaparo.Powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\kicad-mcp" | Out-Null New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\kicad-workspace" | Out-Null Set-Location "$env:USERPROFILE\kicad-mcp" py -3.11 --version py -3.11 -m venv .venv & ".\.venv\Scripts\python.exe" -m pip install --upgrade pip & ".\.venv\Scripts\python.exe" -m pip install "mcp==1.26.0" & ".\.venv\Scripts\python.exe" -m pip check
Activate.ps1 run karvani jarur nathi: sidhu venv Python vapariye chhiye. mcp==1.26.0 official Python MCP SDK v1 FastMCP mate pin chhe; standalone fastmcp package nathi. SDK main branch have v2 API batavi shake chhe, etle unpinned upgrade aa code mate na karo. Transitive dependencies fully locked nathi; tamari working install record karva:Powershell
& ".\.venv\Scripts\python.exe" -m pip freeze | Set-Content -Encoding utf8 requirements-lock.txt
Powershell
Get-ChildItem -LiteralPath 'C:\Program Files\KiCad' -Filter 'kicad-cli.exe' -Recurse -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName $env:KICAD_CLI = Read-Host 'Paste the full kicad-cli.exe path (without surrounding quotes)' $env:KICAD_CLI = (Resolve-Path -LiteralPath $env:KICAD_CLI).Path $env:KICAD_WORKSPACE = (Resolve-Path -LiteralPath "$env:USERPROFILE\kicad-workspace").Path & $env:KICAD_CLI version & $env:KICAD_CLI pcb drc --help
Get-ChildItem karo. Ek karta vadhu exe male to je installed version tame use karo cho te select karo. Help ma --format, --output, --exit-code-violations check karo..kicad_pcb files kicad-workspace ma mukho. DRC mate related .kicad_pro/.kicad_dru hoy to board ni sathe rakho; otherwise project rules missing hoy shake. KiCad GUI ma save thayeli copy par check thashe, unsaved GUI state par nahi.kicad-mcp\kicad_mcp_server.py tarike save karo, .py.txt nahi. Download ne pan inspect karo. Reports automatic kicad-mcp\reports ma banashe, workspace ma nahi.Python
import json import os from pathlib import Path import subprocess import tempfile import uuid from mcp.server.fastmcp import FastMCP def configured(name: str) -> Path: p = Path(os.environ[name]) if not p.is_absolute(): raise ValueError(f"{name} must be an absolute path") return p.resolve(strict=True) WORKSPACE = configured("KICAD_WORKSPACE") CLI = configured("KICAD_CLI") if not WORKSPACE.is_dir() or not CLI.is_file(): raise ValueError("Workspace must be a directory; CLI must be a file") REPORTS = Path(__file__).resolve().parent / "reports" REPORTS.mkdir(exist_ok=True) REPORTS = REPORTS.resolve(strict=True) if REPORTS.is_relative_to(WORKSPACE) or WORKSPACE.is_relative_to(REPORTS): raise ValueError("Keep workspace and report directory separate") mcp = FastMCP("KiCad Read-Only Starter") def board_path(relative_path: str) -> Path: if len(relative_path) > 1000 or ":" in relative_path: raise ValueError("Use a relative board path without colon") p = Path(relative_path) if p.is_absolute() or ".." in p.parts: raise ValueError("Absolute paths and parent traversal are forbidden") p = (WORKSPACE / p).resolve(strict=True) if not p.is_relative_to(WORKSPACE): raise ValueError("Board escapes configured workspace") if p.suffix.lower() != ".kicad_pcb" or not p.is_file(): raise ValueError("Expected an existing .kicad_pcb file") return p def run_cli(args: list[str], timeout: int) -> dict: # Disk-backed output avoids unbounded captured stdout in memory. with tempfile.TemporaryFile() as out, tempfile.TemporaryFile() as err: try: result = subprocess.run( [str(CLI), *args], shell=False, stdin=subprocess.DEVNULL, stdout=out, stderr=err, cwd=str(REPORTS), timeout=timeout, check=False, ) except subprocess.TimeoutExpired: return {"ok": False, "error": f"KiCad timed out after {timeout}s"} except OSError as exc: return {"ok": False, "error": str(exc)[:1000]} out.seek(0) err.seek(0) return {"returncode": result.returncode, "stdout": out.read(4096).decode("utf-8", errors="replace"), "stderr": err.read(4096).decode("utf-8", errors="replace"), "output_limit_bytes_per_stream": 4096} @mcp.tool() def kicad_version() -> dict: """Read the configured KiCad CLI version.""" return run_cli(["version"], 15) @mcp.tool() def list_boards() -> dict: """List up to 100 board files under the configured workspace.""" boards = [] visited = 0 for root, dirs, names in os.walk(WORKSPACE, followlinks=False): visited += 1 dirs[:] = [d for d in sorted(dirs) if (Path(root) / d).resolve().is_relative_to(WORKSPACE)] if visited > 2000: return {"boards": boards, "truncated": True} for name in sorted(names): p = Path(root) / name if p.suffix.lower() == ".kicad_pcb": try: checked = board_path(str(p.relative_to(WORKSPACE))) except (ValueError, OSError): continue relative = checked.relative_to(WORKSPACE).as_posix() if len(relative) <= 1000: boards.append(relative) if len(boards) >= 100: return {"boards": boards, "truncated": True} return {"boards": boards, "truncated": False} @mcp.tool() def run_drc(relative_path: str) -> dict: """Read a board and write a JSON DRC report outside its workspace.""" board = board_path(relative_path) report = REPORTS / f"drc-{uuid.uuid4().hex}.json" result = run_cli(["pcb", "drc", "--format", "json", "--output", str(report), "--exit-code-violations", str(board)], 120) result["report_path"] = str(report) result["report_exists"] = report.is_file() result["meaning"] = "0 = no violations; 5 = violations; other = CLI failure" if report.is_file(): with report.open("rb") as f: preview = f.read(12001) result["report_preview"] = preview[:12000].decode("utf-8", errors="replace") result["report_preview_truncated"] = len(preview) > 12000 return result if __name__ == "__main__": mcp.run(transport="stdio")
print() stdout par na umero: stdout MCP protocol mate reserved chhe. Debugging hoy to stderr par lakho. Input trusted rakho: aa OS security sandbox nathi; malicious local process path/symlink badle to race possible chhe. Related KiCad files par CLI potani permissions thi read kari shake chhe. Model arbitrary command, CLI flags ke output path choose kari shaktu nathi. Temporary output disk par chhe; returned output bounded chhe, pan full report ane temp logs disk space vapare chhe. Reports manually clean karo; automated deletion tool nathi.Powershell
& ".\.venv\Scripts\python.exe" -m py_compile .\kicad_mcp_server.py & ".\.venv\Scripts\python.exe" -c "import kicad_mcp_server as s; print(s.kicad_version()); print(s.list_boards())"
returncode: 0 ane installed version aavvu joie; empty boards hoy to workspace ma board copy karo. Paths manually escape karva karta PowerShell thi tamara actual absolute paths nu Cline JSON banavo:Powershell
$python = (Resolve-Path -LiteralPath '.\.venv\Scripts\python.exe').Path $script = (Resolve-Path -LiteralPath '.\kicad_mcp_server.py').Path $config = @{ mcpServers = @{ 'kicad-readonly' = @{ command = $python args = @($script) env = @{ KICAD_CLI = $env:KICAD_CLI; KICAD_WORKSPACE = $env:KICAD_WORKSPACE } disabled = $false autoApprove = @() } } } $config | ConvertTo-Json -Depth 8 | Set-Content -Encoding utf8 .\cline-kicad-config.json Get-Content .\cline-kicad-config.json
Student ane CLI major tamara actual values hova joie, generated file vaparo):JSON
{ "mcpServers": { "kicad-readonly": { "command": "C:\\Users\\Student\\kicad-mcp\\.venv\\Scripts\\python.exe", "args": ["C:\\Users\\Student\\kicad-mcp\\kicad_mcp_server.py"], "env": { "KICAD_CLI": "C:\\Program Files\\KiCad\\9.0\\bin\\kicad-cli.exe", "KICAD_WORKSPACE": "C:\\Users\\Student\\kicad-workspace" }, "disabled": false, "autoApprove": [] } } }
\\ escape thay chhe; PowerShell generated JSON aa automatic kare chhe. Command string ma extra quote characters na umero. Cline launch mate env config ma explicitly aapiye chhiye, etle terminal env inherit thavani assumption nathi.kicad-readonly entry existing mcpServers andar merge karo. Bija servers delete/replace na karo; existing config no backup rakho. Empty settings hoy to full generated object paste karo. JSON ma comments/trailing commas na rakho..vscode/mcp.json alag system/schema chhe, tya aa object mukvathi Cline configure nahi thay. Global settings path versions pramane badlai shake chhe, etle Cline UI thi correct file kholo.autoApprove: [] rakho; global Use MCP servers auto-approve ane YOLO off rakho, calls review kari approve karo. DRC 120 seconds sudhi chale chhe; jarur pade to Cline server request timeout UI ma 150 seconds ke vadhu rakho. Manual Python script run karo to te stdin MCP messages ni rah joshe; blank terminal normal chhe, Ctrl+C thi bandh karo. Cline ene potane launch kare chhe, permanent terminal server separately start karvani jarur nathi.Text
Use the kicad-readonly MCP server to check the KiCad version. Use the kicad-readonly MCP server to list board files. Use run_drc on the relative board path returned by list_boards. Do not edit any files or use terminal commands.
{"relative_path":"flight-controller.kicad_pcb"}; subfolder mate boards/flight-controller.kicad_pcb. Absolute path, .., colon ane workspace escape reject thashe. Cline na built-in terminal/edit tools aa server ni restrictions thi control thata nathi; tenu approval alag review karo.No module named mcp: correct .venv\Scripts\python.exe ma mcp==1.26.0 install karo; global Python sathe mix na karo.KeyError KICAD_CLI/KICAD_WORKSPACE: import karta pehla env set karo; Cline config ma banne env entries rakho..py.txt extension check karo, selected CLI executable actually installed chhe te check karo..kicad_pcb workspace ma rakho, fakt Flux URL nahi.mcp==1.26.0 install, compile/import, exact three-tool registration, real stdio initialize/list/call/shutdown lifecycle; actual KiCad version tool returned 10.0.6; mock subprocess DRC report writing/exit 5 and timeout; traversal/absolute/colon/outside-symlink rejection; pip check no broken requirements. Mock board input was a test fixture, not this project PCB. Real PCB DRC was not run.IncompleteFieldDefinitionWarning for SDK lifespan annotations to stderr; tested tool registration and stdio lifecycle still passed. Windows/Python 3.11 environment not tested; dependency resolution may differ. Pinning SDK alone is not a complete dependency lock.mcpServers with command, args, env, disabled, autoApprove.kicad-cli version, pcb drc --format json --output ... --exit-code-violations INPUT_FILE; violation exit 5. Installed Linux KiCad 10.0.6 help independently checked these flags.Shu banavishu?
1. Jaruri software
2. Folder ane Python venv
3. Tamaro actual KiCad CLI shodho
4. Server code save karo
5. PowerShell smoke test ane config generate
6. Cline ma connect karo
7. Common problems
Verification ane limitations
Official evidence (checked 2026-10-09)