Repository navigation
Development and Testing
Keep contributions in the project's spirit: clear over clever, and reuse the existing patterns (see Architecture). CONTRIBUTING.md is the canonical guide; this page expands on it.
git clone https://github.com/farzadnadiri/peykan.git
cd peykan
python -m venv .venv
.venv\Scripts\activate # Linux/macOS: source .venv/bin/activate
pip install -e ".[dev]"ruff check .
mypy src
pytest -qAll three must pass. CI (.github/workflows/ci.yml) runs them on Python 3.10–3.13, and a package job builds the sdist and wheel, runs twine check, installs the wheel in a clean environment and runs peykan from outside the checkout (this catches files missing from the package).
requirements.txt pins the dependencies CI and the Docker image install. Every pin must install on Python 3.10, the minimum supported version; regenerate it with 3.10, or check each pin's Requires-Python.
-
Protocol logic in plain modules (
obd.py,j1939.py,uds.py,logs.py,diagnostics.py), with no MCP or CLI awareness, so it's testable without a bus. -
Tools in
server/mcp_server.py, result models inserver/schemas.py. -
Anything that sends on the bus goes through the guard:
bus = guard.wrap(raw_bus, "purpose", write=...), withwrite=Truefor anything that changes ECU or bus state, andshutdown_bus(raw_bus)infinally. Never call a raw bus'ssendfrom a tool or CLI command. Returnstatus="blocked"onTransmitBlocked. -
Listener threads each get their own
make_bus()instance. -
Simulator behaviour in
simulator/: driving/cabin state instate.py, faults infaults.py. -
CLI in
cli.py; mirror new tools there where it makes sense. Print data to stdout; logs go to stderr.
- Protocol logic in a plain module, with unit tests.
- A result model in
server/schemas.pywith astatusfield. - The tool in
create_app(): passive tools readlive_state.frames_since(...); request/response tools use a guarded bus as above. Capduration_s/timeout_swith_capped_duration. Accept IDs asIntLikeand parse them withparse_int(orj1939.resolve_pgn), so models can pass hex strings. - If it's useful from the terminal, a matching CLI command.
- Tests: unit tests for the logic; for the tool,
tests/test_server_app.pycalls tools in-process via_call(app, name, args), and the end-to-end UDS tests show how to run a simulated ECU on a private virtual channel.
| File | Covers |
|---|---|
test_dbc.py, test_decode_roundtrip.py
|
DBC loading and encode/decode |
test_state.py |
Driving and cabin model; every broadcast signal is modelled and encodable |
test_faults.py, test_fault_scenarios.py
|
Presets, activation, state effects across protocols |
test_obd.py |
OBD encode/decode, live PIDs, reply matching |
test_diagnostics.py |
DBC diagnostic protocol; service IDs match the DBC; read/write classification |
test_j1939*.py |
IDs, catalog, simulator, CLI, BAM transport, multi-ECU DM1 |
test_uds.py |
ECU protocol logic and end-to-end ISO-TP over a virtual bus |
test_logs.py |
All log formats, analysis, signals, path confinement, replay, recording |
test_safety.py |
Transmit policy, allowlist, audit log, simulator refusal on hardware |
test_server_app.py |
Tools, prompts, routes, CORS, DNS-rebinding protection, transports |
test_cli.py, test_cli_features.py
|
CLI commands |
test_parsing.py |
ID and payload parsing |
test_logging.py, test_rename_compat.py
|
Logs on stderr; old MCP_CAN_* / mcp-can compatibility |
Unit tests use fake or virtual buses in-process. Before a release it's worth a real run: peykan demo, then connect MCP Inspector (npx @modelcontextprotocol/inspector → http://localhost:6278/sse) or ollmcp and call a few tools.
Open a GitHub issue with your OS, Python version, peykan version, and whether you're on the virtual bus or a real adapter (PEYKAN_CAN_INTERFACE). For hardware issues, a transmit log (PEYKAN_TRANSMIT_LOG_PATH) helps.
Getting started
Reference
Protocols
Features
Operating it
Contributing