Metadata-Version: 2.5
Name: pnc-diag-mcp
Version: 0.1.1
Summary: Open-source thin interface, zero-deserialization bag inspector, Agent Skill, and synthetic example kit for autonomous driving PNC and LiDAR-SLAM telemetry.
Project-URL: Homepage, https://github.com/VictorLiu0725/pnc-diag-mcp
Project-URL: Repository, https://github.com/VictorLiu0725/pnc-diag-mcp
Project-URL: Issues, https://github.com/VictorLiu0725/pnc-diag-mcp/issues
Project-URL: Pro Edition, https://gumroadalbert.gumroad.com/l/pnc-diag-pro
Author-email: VictorLiu0725 <albertlw007@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
License-File: THIRD_PARTY_NOTICES.md
Keywords: autonomous-driving,autoware,mcap,mcp,model-context-protocol,nav2,robotics,ros2,rosbag,slam
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: <3.15,>=3.10
Requires-Dist: mcap>=1.1.1
Requires-Dist: mcp>=2.0.0
Requires-Dist: numpy>=1.26.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: rosbags>=0.10.0
Description-Content-Type: text/markdown

# pnc-diag-mcp — Offline ROS 2 / Nav2 / Autoware Bag Diagnostics & MCP Server

[![PyPI version](https://img.shields.io/pypi/v/pnc-diag-mcp)](https://pypi.org/project/pnc-diag-mcp/)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![pnc-diag-mcp MCP server](https://glama.ai/mcp/servers/VictorLiu0725/pnc-diag-mcp/badges/score.svg)](https://glama.ai/mcp/servers/VictorLiu0725/pnc-diag-mcp)
[![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/victorliu0725/pnc-diag-mcp)
[![Pro Edition](https://img.shields.io/badge/Pro_Edition-Root--Cause_Operators_%26_5--Panel_Plots-0ea5e9)](https://gumroadalbert.gumroad.com/l/pnc-diag-pro)

**Fast 3-second offline pre-triage & CI layer for multi-GB `.mcap`, `.db3`, and `.bag` recordings — before you dive into PlotJuggler.**
`pnc-diag-mcp` reads ROS 2 & ROS 1 bags **100% locally offline with zero ROS 2 installation**, audits topic timing without deserializing payloads, maps Nav2 / Autoware signals via declarative YAML, and exposes read-only tools for MCP-compatible AI coding assistants.

<p align="center">
  <a href="https://gumroadalbert.gumroad.com/l/pnc-diag-pro">
    <img src="https://raw.githubusercontent.com/VictorLiu0725/pnc-diag-mcp/main/docs/media/pnc_diag_pro_demo_preview.gif" alt="PNC-Diag Live MCAP Bag Playback and 5-Panel Root-Cause Diagnosis Demo" width="880" />
  </a>
</p>

<p align="center">
  <em>Above: Live offline <code>.mcap</code> telemetry playback (wheel slip @28.1s + control lag @33.0s) and cross-module First-Domino 5-panel diagnosis powered by <a href="https://gumroadalbert.gumroad.com/l/pnc-diag-pro">PNC-Diag MCP Pro</a>.</em>
</p>

---

## Try the Free Open-Source Foundation in 10 Seconds

No ROS 2 install, no Docker, no cloud uploads:

```bash
# Run the stdio MCP server directly from PyPI
env -u PYTHONPATH uvx pnc-diag-mcp

# Or install the CLI + synthetic fault-bag generator
env -u PYTHONPATH pip install pnc-diag-mcp
env -u PYTHONPATH python -m fault_sim_kit.generator
env -u PYTHONPATH pnc-diag inspect data/golden/case_01_tf_jump
```

> **Note for ROS 2 shells:** Prefix commands with `env -u PYTHONPATH` if `/opt/ros/<distro>/setup.bash` is sourced.

---

## Open-Source Thin vs. PNC-Diag MCP Pro

The open-source repository (Apache-2.0) gives you the offline multi-format reader, zero-deserialization timing auditor, Nav2/Autoware YAML signal mapper, and 10 synthetic example scenarios.

When localization, planning, and control all fire alarms in the same second, **[PNC-Diag MCP Pro](https://gumroadalbert.gumroad.com/l/pnc-diag-pro)** adds 15 compiled deterministic physics operators (`.so` Linux `x86_64` wheels for **Python 3.10–3.13**, including Ubuntu 22.04 & 24.04) to pinpoint the **First Domino**, separate mixed faults, generate 5-panel aligned PNG evidence plots, and enforce CI KPI regression gates:

<p align="center">
  <a href="https://gumroadalbert.gumroad.com/l/pnc-diag-pro">
    <img src="https://raw.githubusercontent.com/VictorLiu0725/pnc-diag-mcp/main/docs/media/cover_02_four_faults_en.png" alt="PNC-Diag MCP Pro 4 Real-World Fault Benchmarks (6/6 Accurate, 0 False Alarms)" width="880" />
  </a>
</p>

| Capability | Open-Source Thin (Apache-2.0, Free) | [PNC-Diag MCP Pro (Launch: $49 w/ `EARLYBIRD30`)](https://gumroadalbert.gumroad.com/l/pnc-diag-pro) |
|---|---|---|
| Multi-format offline reader (`.mcap`, `.db3`/`.sqlite3`, `.bag`) | ✅ | ✅ (+ schema v1–v4+ SQLite3 recovery without `metadata.yaml`) |
| Zero-deserialization timing scan & header-time audit | ✅ (`inspect_bag_summary`) | ✅ (`inspect_bag_schema` + calibrated clock checks) |
| Bounded signal mapping (`nav2` / `autoware` / custom YAML) | ✅ (`sample_mapped_signals`) | ✅ |
| Full-bag Top-K streaming anomaly anchoring | — | ✅ (`detect_anomaly_windows`) |
| Localization jump vs. wheel-odometry slip arbitration (IMU) | — | ✅ (`analyze_localization_health`) |
| Planning trajectory jumps, curvature & LiDAR obstacle clearance | — | ✅ (`analyze_planning_health`) |
| Control CTE/HE, cross-correlation actuation lag & FFT oscillation | — | ✅ (`analyze_control_health`) |
| Cross-module First-Domino causal adjudication + 5-panel PNG plot | — | ✅ (`correlate_root_cause_and_plot`) |
| CI regression KPI gates (`--assert-healthy`, `--assert-kpi`) | — | ✅ (`pnc-diag-pro diagnose`) |
| Offline field operation (no ROS 2 runtime, no cloud upload) | ✅ | ✅ (up to 3 machines + 7-day air-gapped field grace) |

**Plug-and-play upgrade:** `pnc-diag-mcp` automatically discovers `pnc-diag-pro` when installed in the same Python environment—zero MCP client reconfiguration required:

```bash
# 1. Install the compiled Pro wheel matching your Python (3.10 / 3.11 / 3.12 / 3.13)
env -u PYTHONPATH pip install ./wheels/pnc_diag_pro-0.1.0-cp312-cp312-linux_x86_64.whl

# 2. Activate once online (writes a 7-day offline cache for air-gapped field testing)
pnc-diag-pro activate "<YOUR-GUMROAD-LICENSE-KEY>"
```

👉 **Get PNC-Diag MCP Pro ($49 Early-Bird for first 20 engineers with code `EARLYBIRD30`, regular $79 one-time):** https://gumroadalbert.gumroad.com/l/pnc-diag-pro

---

## Features and Open-Source Scope

### Included and working in Apache-2.0 Thin Edition

1. **Offline multi-format discovery and timing scans without payload deserialization** (`src/pnc_diag/readers/`, `src/pnc_diag/inspector.py`)
   - Detects `.mcap`, `.db3` / `.sqlite3`, ROS 1 `.bag`, and ROS 2 bag directories; validates relative paths in `metadata.yaml`.
   - Audits each topic in its original storage order: message count, duration, mean rate, median and P95 period, P95 jitter, gaps (`heuristic_large_gap`), timestamp regressions (`monotonic_violations`), and zero timestamps (`zero_timestamps`).
   - Uses bounded early-message sampling to check for `header.stamp`, count zero header stamps, and report the neutral `observed_header_minus_log_ms` observation. It does not assume cross-topic clock synchronization.
2. **Standard signal models and declarative YAML mapping** (`src/pnc_diag/models/`, `configs/`)
   - Includes standard mappings for Nav2 ([configs/topic_map.nav2.yaml](configs/topic_map.nav2.yaml)) and Autoware Universe ([configs/topic_map.autoware.yaml](configs/topic_map.autoware.yaml)).
   - Extracts dot paths and array elements (for example, `pose.covariance[0]`), converts `FLU` / `FRD` frames and `rad` / `deg` units, and returns `PoseSample`, `TwistSample`, `ImuSample`, `PathSample`, `ControlCmdSample`, `LaserScanSample`, and `DiagnosticEvent` values.
3. **Small CLI and stdio MCP server** (`src/pnc_diag/cli.py`, `src/pnc_diag/mcp_server.py`)
   - CLI commands: `pnc-diag inspect` and `pnc-diag preview`.
   - The `pnc-diag-mcp` stdio server exposes three tools: `ping`, `inspect_bag_summary`, and `sample_mapped_signals`.
   - Includes the orchestration [SKILL.md](.agents/skills/pnc-slam-diag/SKILL.md) and [fault pattern reference](.agents/skills/pnc-slam-diag/references/fault_patterns.md).
4. **Reproducible synthetic examples** (`fault_sim_kit/`)
   - Generates one baseline recording and nine synthetic fault, missing-data, or zero-timestamp examples under `data/golden/` for integration and regression exercises.

---

## Requirements and Installation

- **Python:** `>=3.10,<3.15` (verified on Python `3.10`, `3.11`, `3.12`, and `3.13`)
- **Package manager:** [`uv`](https://docs.astral.sh/uv/) is recommended; `uv.lock` is included.
- **ROS 2 runtime:** Not required.

> **Notes**
> 1. The default Nav2 and Autoware topic maps are bundled in the wheel under `pnc_diag._configs`. The default Nav2 map loads without `--map-config` whether you use `uv sync`, `pip install -e .`, or install the wheel from another directory. Use `--map-config autoware` for the bundled Autoware map, or pass a path to a custom YAML map.
> 2. In a source checkout, `python -m fault_sim_kit.generator` writes to `<repo>/data/golden/` by default. After a non-editable install, it writes to `./data/golden/` in the current working directory. Use `--out <directory>` to choose another location.
> 3. If your shell has sourced ROS 2 (for example, Humble or Jazzy), prefix commands with `env -u PYTHONPATH` to keep system Python paths out of the virtual environment.

```bash
# Option 1: Install from PyPI (recommended)
env -u PYTHONPATH pip install pnc-diag-mcp
pnc-diag --version

# Or run the stdio MCP server directly with uvx (no repo clone required)
env -u PYTHONPATH uvx pnc-diag-mcp

# Option 2: Run from a local source checkout
env -u PYTHONPATH uv sync
env -u PYTHONPATH uv run pnc-diag --version
```

---

## Synthetic Examples and Tests

The distribution does not contain the approximately 47 MB of generated `.mcap` files. Run the tests or generate the examples locally:

```bash
# Lint and run all unit tests; pre-existing data/golden/ files are not required.
env -u PYTHONPATH uv run ruff check .
env -u PYTHONPATH uv run pytest

# Generate all 10 synthetic MCAP examples under data/golden/.
env -u PYTHONPATH uv run python -m fault_sim_kit.generator
```

---

## CLI Usage

This edition provides the `inspect` and `preview` commands:

```bash
# Inspect timing, topic-role coverage, and neutral header-time observations.
env -u PYTHONPATH uv run pnc-diag inspect data/golden/case_01_tf_jump

# Inspect missing-sensor and zero-timestamp counterexamples.
env -u PYTHONPATH uv run pnc-diag inspect data/golden/case_08_missing_imu_and_scan
env -u PYTHONPATH uv run pnc-diag inspect data/golden/case_09_invalid_zero_stamps --json

# Preview bounded samples of mapped standard signals.
env -u PYTHONPATH uv run pnc-diag preview data/golden/nav_baseline --role odom_pose --limit 3
env -u PYTHONPATH uv run pnc-diag preview data/golden/case_01_tf_jump --topic /amcl_pose --t-start 44.5 --t-end 46.0 --json

# Inspect a recording with the bundled Autoware preset or a custom mapping file.
env -u PYTHONPATH uv run pnc-diag inspect /path/to/autoware_bag --map-config autoware
env -u PYTHONPATH uv run pnc-diag inspect /path/to/autoware_bag --map-config configs/topic_map.autoware.yaml
```

---

## MCP Server and Agent Skill

### `pnc-diag-mcp` stdio tools

| Tool | Arguments | Returns |
|---|---|---|
| `ping` | None | Service status, `version`, and `edition` (`open-source-thin`) |
| `inspect_bag_summary` | `bag_path`, `map_config` | Storage format, duration, available and missing roles, `clock_comparability`, warnings, and per-topic timing statistics |
| `sample_mapped_signals` | `bag_path`, `topic`, `role`, `map_config`, `limit`, `t_start_s`, `t_end_s` | Bounded standardized signal samples (`limit`: `1..50`) |

### Example MCP Client Configuration

Using `uvx` (from PyPI):

```json
{
  "mcpServers": {
    "pnc-diag": {
      "command": "env",
      "args": [
        "-u",
        "PYTHONPATH",
        "uvx",
        "pnc-diag-mcp"
      ]
    }
  }
}
```

Or from a local source checkout:

```json
{
  "mcpServers": {
    "pnc-diag": {
      "command": "env",
      "args": [
        "-u",
        "PYTHONPATH",
        "uv",
        "--directory",
        "<PATH_TO_REPO>",
        "run",
        "pnc-diag-mcp"
      ]
    }
  }
}
```

The Agent Skill is in [.agents/skills/pnc-slam-diag/SKILL.md](.agents/skills/pnc-slam-diag/SKILL.md), with a [fault pattern reference](.agents/skills/pnc-slam-diag/references/fault_patterns.md).

---

## Try It and Share Feedback

Start with the generated synthetic examples, then try `pnc-diag inspect <bag_path>` or `pnc-diag preview <bag_path>` on a recording you are authorized to analyze. This edition provides inspection and signal sampling, not a definitive root-cause diagnosis.

- **Reproducible bugs:** Open a [Bug report](https://github.com/VictorLiu0725/pnc-diag-mcp/issues/new?template=bug_report.md). Include your Python version, operating system, install method, recording format, command, expected and actual behavior, and sanitized output.
- **Usage questions, workflow feedback, and feature ideas:** Start a [Discussion](https://github.com/VictorLiu0725/pnc-diag-mcp/discussions).

Do not upload raw customer recordings, proprietary bags, credentials, or identifying logs to public Issues or Discussions. Share a synthetic or anonymized minimal reproduction when possible.

---

## Data and Diagnostic Limitations

1. **Inspection foundation only:** This edition does not calculate quantitative localization, planning, or control anomaly metrics, or make a definitive multi-sensor root-cause determination. Review the evidence manually or use [PNC-Diag MCP Pro](https://gumroadalbert.gumroad.com/l/pnc-diag-pro) for deterministic root-cause adjudication.
2. **No clock synchronization inference:** `observed_header_minus_log_ms` records the difference between a message header timestamp and its recorded log timestamp. By itself, it cannot distinguish sensor clock drift from queueing or transport delay. This edition reports `clock_comparability="unverified"` by default.
3. **Synthetic examples are exercises, not a blind benchmark:** `fault_sim_kit` produces simplified closed-loop kinematic data, not representative sensor noise, vehicle dynamics, or real-vehicle acceptance data. The repository does not commit `golden_truth.json` or generated bag files, but it does publish the definitions of all 10 scenarios and the code that generates their ground truth. Use a separate, unpublished dataset for blind tests or benchmark evaluations.
4. **Read-only offline operation:** The tools do not send vehicle commands, change parameters, or operate ROS nodes.

---

## License and Third-Party Notices

- **License:** This repository is released under the [Apache License 2.0](LICENSE); see [NOTICE](NOTICE). Subject to the license terms, others may use, modify, and redistribute the published code commercially. The private physical diagnostic core, calibrated rules, and enterprise gates are outside this repository.
- **Dependencies and provenance:** See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for dependency licenses and acknowledgments of upstream code and design references. The documented runtime and development dependencies use permissive MIT, BSD, or Apache-2.0 licenses; no GPL code is included in this repository.

<!-- mcp-name: io.github.VictorLiu0725/pnc-diag-mcp -->
