Skip to main content
Glama
README.md
# hardware-formal-mcp

[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-3776ab.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![MCP 2024-11-05](https://img.shields.io/badge/MCP-2024--11--05-7c3aed)](https://modelcontextprotocol.io)
[![Code Style: Ruff](https://img.shields.io/badge/code%20style-ruff-261230.svg)](https://github.com/astral-sh/ruff)

**Deterministic Model Context Protocol (MCP) Server bridging AI Coding Agents (Claude Code, Claude Desktop, Cursor) with Physical Hardware EDA (KiCad 8/9/10), RF/IPC-2221 Signal Integrity, Embedded C Formal Verification (`CBMC`), and ISO-14229 UDS / CAN-Bus Diagnostics.**

---

## Why This Exists

While the Model Context Protocol ecosystem has rich coverage for web APIs, databases, and SaaS workflows, **hardware electronics, PCB layout verification, and safety-critical embedded C/C++ firmware** remain largely disconnected from agentic coding loops. When an LLM modifies a KiCad board, a bare-metal microcontroller driver, or an automotive CAN/UDS diagnostic stack without deterministic physical and mathematical gates, subtle failures slip through:

- **PCB Copper & Signal Integrity:** Uncaught DRC/ERC violations, excessive USB/CAN/Ethernet differential pair skew, under-sized power traces violating IPC-2221 thermal rise limits, or 2.4 GHz RF microstrip impedance mismatches.
- **Safety-Critical Embedded C:** Integer overflows, out-of-bounds LUT indexing, division-by-zero in fixed-point sensor math, or violated actuator safety interlocks that unit tests miss on edge cases.
- **Automotive & Industrial Protocols:** Multi-frame ISO 15765-2 (ISO-TP) segmentation bugs, ISO 14229 (UDS) negative response handling (`NRC 0x31`), and unbalanced ASAM MCD-2 MC (`.A2L`) calibration definitions.

`hardware-formal-mcp` exposes **12 zero-hallucination, deterministic verification tools** over stdio JSON-RPC 2.0 with **zero required core runtime dependencies** (pure Python standard library core, with modular extras for `kiutils`, `scikit-rf`, `wireviz`, `python-can`/`udsoncan`, and `diffblue/cbmc`).

---

## Architecture

```mermaid
flowchart LR
    Agent["Claude Code / MCP Client"] <-->|"JSON-RPC 2.0 (stdio)"| Server["hardware-formal-mcp"]
    Server --> EDA["KiCad 10 CLI & pcbnew API"]
    Server --> RF["Hammerstad-Jensen & scikit-rf 2.4GHz"]
    Server --> CBMC["CBMC SAT/SMT Bounded Model Checker"]
    Server --> SAST["Flawfinder CWE & Lizard CCN"]
    Server --> UDS["Virtual CAN + ISO-TP + UDS + ASAM .A2L"]
```

---

## Quickstart with Claude Code

Install from source or PyPI-compatible Git URL and register directly with **Claude Code**:

```bash
pip install "git+https://github.com/DjohnHK/hardware-formal-mcp.git#egg=hardware-formal-mcp[eda,automotive,sast]"

# Register with Claude Code CLI:
claude mcp add hardware-formal -- hardware-formal-mcp
```

Or add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "hardware-formal": {
      "command": "python",
      "args": ["-m", "hardware_formal_mcp"]
    }
  }
}
```

---

## Exposed MCP Tools (12 Tools)

| Tool Name | Domain | Underlying Engine / Math | What It Verifies |
| :--- | :--- | :--- | :--- |
| `embedded_toolchain_doctor` | Diagnostics | Cross-platform discovery | Detects installed KiCad CLI, CBMC, Cppcheck, ARM/RISC-V GCC, Graphviz & Python stacks |
| `kicad_discover_boards` | KiCad EDA | Filesystem AST scan | Locates `.kicad_pcb` & `.kicad_sch` hardware designs |
| `kicad_run_erc_and_drc` | KiCad EDA | `kicad-cli pcb drc` & `sch erc` | Runs zone-refilled DRC & schematic ERC returning structured JSON violations |
| `kicad_pcbnew_net_trace` | High-Speed PCB | KiCad C++ `pcbnew` SWIG | Exact copper net lengths (mm), USB/CAN/ETH differential skew, min trace width, vias |
| `kicad_ipc2221_ampacity_audit` | Power Electronics | IPC-2221 + `pcbnew` | Trace current capacity $I_{\max}$, DC resistance ($m\Omega$), copper pours & neckdowns |
| `kicad_rf_and_pdn_audit` | RF / PDN | Hammerstad-Jensen + `scikit-rf` | Microstrip $Z_0$, $\varepsilon_{eff}$, $S_{11}$, $S_{21}$, VSWR & 10 MHz decoupling PDN impedance |
| `kicad_dfm_bom_audit` | PCBA / DFM | `kiutils` S-Expr AST | SMD/THT breakdown, IC-to-decoupling capacitor distance (mm), 3D model & LCSC BOM coverage |
| `wireviz_harness_audit` | Cable Harnesses | `WireViz` + `Graphviz` | Connector pinout continuity, wire gauge validation & SVG/TSV BOM generation |
| `cbmc_formal_model_check` | Formal Methods | `diffblue/cbmc` SAT/SMT | Proves zero buffer overflow, div-by-zero, signed overflow & `__CPROVER_assert` invariants in C |
| `c_flawfinder_and_lizard_gate` | Embedded SAST | `flawfinder` + `lizard` | C/C++/`.ino` CWE memory-safety scan & cyclomatic complexity hotspots |
| `uds_isotp_virtual_can_verifier` | Automotive HIL | `python-can` + `can-isotp` + `udsoncan` | Live multi-frame ISO-TP (`0x22 0xF190` 17-byte VIN) & UDS session/NRC `0x31` loopback |
| `asam_a2l_validator` | Calibration | ASAM MCD-2 MC parser | Validates `.A2L` block balance, `CHARACTERISTIC`, `MEASUREMENT` & `COMPU_METHOD` nodes |

---

## Running Tests Locally

```bash
pip install -e ".[automotive,sast,dev]"
ruff check src tests
pytest -v
```

---

## License

Released under the [MIT License](LICENSE).