Metadata-Version: 2.4
Name: canari-mcp
Version: 0.1.5
Summary: Canari - agent component verification ledger: signed, offline-verifiable attestations for MCP servers and agent skills
Author: Canari contributors
License: Apache-2.0
Project-URL: Homepage, https://github.com/lanbass869-cell/canari
Keywords: mcp,agent,supply-chain,attestation,security,in-toto,dsse
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jsonschema>=4.0
Requires-Dist: in-toto>=3.1
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: cbor2>=5.6; extra == "dev"
Dynamic: license-file

# Canari

<!-- mcp-name: io.github.lanbass869-cell/canari -->

[![CI](https://github.com/lanbass869-cell/canari/actions/workflows/ci.yml/badge.svg)](https://github.com/lanbass869-cell/canari/actions/workflows/ci.yml)
![tests](https://img.shields.io/badge/tests-889%20collected-brightgreen)
![coverage](https://img.shields.io/badge/coverage-86%25%20line%20%7C%2085%25%20branch-brightgreen)
![mutation](https://img.shields.io/badge/mutation%20kill-100%25%20(52%20mutants)-brightgreen)
![release](https://img.shields.io/github/v/release/lanbass869-cell/canari)
[![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/lanbass869-cell/canari)
[![Canari on Glama](https://glama.ai/mcp/servers/lanbass869-cell/canari/badges/score.svg)](https://glama.ai/mcp/servers/lanbass869-cell/canari)

Agent component verification ledger - signed, offline-verifiable, history-preserving attestations for MCP servers, agent skills, and DSH plugins.

Named after the canary in the coal mine: the first to detect that something went wrong.

## What it does

1. **Weekly scan** of agent component ecosystems (npm, PyPI, MCP Registry, dsh.so)
2. Each component gets a **signed attestation**: DSSE/Ed25519 envelope whose payload is an **in-toto Statement v1** (`subject[]` with `digest.sha256`, `predicateType`, `predicate`) binding: artifact hash + host version + scan scenario. Readable by GUAC / cosign / slsa-verifier without Canari-specific code.
3. When the registry publishes one, the attestation also records the
   **publishing repository** (`subject.repository`, normalised to
   `host/owner/name`). That is what makes "same component on another ecosystem"
   a comparison of repositories instead of names; a record with no repository is
   `unknown`, never `different`.
3. Attestations are **offline-verifiable** by anyone with the public key
4. History is **never deleted** - version changes create supersession chains
5. Public **machine-readable feed** for any AI agent or host to consume
6. **Trust heuristics**: release cadence (L2.4), metadata anomaly (L2.5), typosquatting (L2.6).
   Which of these appear in an attestation depends on the entry point - see
   [Which checks come from which entry point](#which-checks-come-from-which-entry-point).
7. **Consumer install gate** with policies: `canari-verify bundle.json --key pub.json --gate --gate-policy paranoid`

## Install

```
pip install canari-mcp
```

Also on [PyPI](https://pypi.org/project/canari-mcp/) and as a
[GitHub release](https://github.com/lanbass869-cell/canari/releases/tag/v0.1.0)
(wheel + sdist + `SHA256SUMS` + Ed25519 signature). Both channels ship byte-identical
artifacts; see `docs/release-process.md` to verify the signed release.

```
canari-gate --store out --list
```

## What this is, end to end

**Canari is a verdict ledger for AI agent components.** It scans four ecosystems weekly,
signs a verdict per component, keeps the whole supersession history, and exposes an
install-time gate that other programs can call. It is not a scanner (no home-grown
detection engine), not a platform (no accounts, no community) and not an LLM product.

New here? Start with **[docs/PROJECT-SUMMARY-EN.md](docs/PROJECT-SUMMARY-EN.md)** — one page,
every number re-derived from an artefact on 2026-11-19 (21 automated checks, 0 failures).

For the full account — day-by-day history, the four times our own figures drifted, the
sampling artefact that turned 84% into 94.78%, and the 66.6% false-pass disclosure — read
**[docs/PROJECT-STORY-20261119.md](docs/PROJECT-STORY-20261119.md)**.

## Open dataset

`dataset/` is the published snapshot of the ledger under **CC-BY-4.0**: **5170 signed
attestations over 1417 components**, the canonical feed, drift reports, the schema, both
public keys and a `MANIFEST.json` with a sha256 per file. Verify a bundle offline with
`canari-verify`; verify the whole snapshot with the manifest (see `dataset/README.md`).
Refresh it after a scan with `python scripts/sync_dataset.py`.

## Append-only public log (verifiable without trusting us)

Every published verdict bundle and every upstream dataset snapshot is committed
into a signed, append-only Merkle log at
[`docs/log/`](https://lanbass869-cell.github.io/canari/log/). This closes a gap
that a signature alone cannot: a signed attestation proves *who* said something,
never that an older statement was not quietly deleted or re-issued with a
different verdict.

- **Latest head**: `docs/log/head-latest.json` (size, root, Ed25519 signature)
- **Latest offline bundle**: `docs/log/bundle-latest.json`
- **c2sp.org checkpoint**: `docs/log/checkpoint.txt` -- the same head as a
  signed note in `c2sp.org/tlog-checkpoint` + `signed-note` +
  `tlog-cosignature` form, so an existing transparency-log witness can co-sign
  it without adopting anything of ours. Pinned against another project's
  published test vectors (`tests/test_checkpoint.py`).
- **Format**: [`docs/spec/append-only-log.md`](docs/spec/append-only-log.md)
  (RFC 9162 hashing, inclusion + consistency proofs, explicit list of what the
  proof does *not* claim)
- **Cross-implementation vectors**: `docs/spec/merkle-vectors.json` (168 cases),
  checked by two independent verifiers

```
# no network, no canari install needed for the Node path
node docs/spec/verify_offline.js docs/log/bundle-latest.json --log-id canari-snapshot-log

# "the head I recorded yesterday is still a prefix of today's"
python -m canari.verify_offline docs/log/bundle-latest.json \
  --pinned-prefix <root-you-saved-last-week>
```

A new head is appended daily by `.github/workflows/append-only-log.yml`. The
publish path refuses to sign (`LogTruncated` / `LogRewritten`) if the on-disk
log contradicts a head it already published, because a log that re-signs a
rewrite under its own key manufactures false assurance.

## Quality gates (enforced in CI)

Measured on 2026-11-18 (local run, `python scripts/quality_gate.py`):

| Gate | Threshold | Current |
|---|---|---|
| tests | green on 3.10/3.12/3.13 | 889 collected, 878 passing, 11 env-skip (10 network, 1 platform) |
| line coverage | >= 85% | 85.3% combined (CI gates on the combined figure) |
| mutation kill rate | >= 90% (equivalent mutants excluded) | 100% (47 killed + 2 survivors classed equivalent, 3 skipped) |
| live-data audit | sampled attestations re-derive from npm/PyPI | 18/18 |

Run them yourself before every push:

```
python scripts/quality_gate.py
```

That single command runs **lint + tests + coverage + mutation**, which is the same
set CI enforces. Running only `pytest tests` is not a substitute: it skips the
coverage gate and the lint gate, and this repository once stayed red for nine
consecutive commits that way.

## Quick start

```
# install
pip install canari-mcp

# run a scan
canari-baseline --limit 50

# verify an attestation offline
canari-verify out/attestations/npm_some-package.bundle.json --key out/public_key.json

# verify + policy gate (exit 0 ALLOW / 5 BLOCK / 6 REVIEW)
canari-verify out/attestations/npm_some-package.bundle.json --key out/public_key.json \\
    --gate --gate-policy strict

# custom policy file
canari-verify bundle.json --key out/public_key.json --gate --gate-policy-file my-policy.json
```

### Policy file example

```json
{"name": "my-policy", "block_on_findings": true, "require_native_provenance": false}
```

## Consumer side (the part a host actually uses)

### 1. Look up a component and gate it

```
# resolve the newest signed attestation for a component and run the gate
canari-gate --store out --registry npm --name express
canari-gate --store out --registry dsh-registry --name aegis --policy paranoid --json

# exit codes: 0 ALLOW, 5 BLOCK, 6 REVIEW, 3 not found
canari-gate --store out --list
```

> **What this gate actually covers.** It is a verdict lookup, not a universal
> installer check: a component we have never scanned is `not found`, and the
> default policy turns that into BLOCK (fail-closed). The reference store holds
> **1,437 components** -- 66 of the MCP Registry's 22,384 servers (0.29%), plus
> 239 npm and 611 PyPI packages out of ecosystems orders of magnitude larger.
> In practice it behaves as a **1,437-entry allowlist**: anything outside it is
> refused rather than cleared. Treat BLOCK on an uncovered package as "unknown",
> not as "unsafe", and scan it yourself before concluding anything.

### 2. Record another scanner's result as a signed, timestamped attestation

**Live example:** [20 PyPI MCP servers, scanned by bandit, recorded and signed](https://lanbass869-cell.github.io/canari/scan/) - every record on that page
can be verified with `canari-verify` using the public key shipped beside it.

Canari does not scan anything itself. What it adds is durability: a scanner
tells you what it thinks *today*, Canari records what it said *on each date*,
signed and offline-verifiable, and keeps the history when the verdict flips.

`canari-ingest-sarif` reads a SARIF 2.1.0 report from any external scanner
(NVIDIA SkillSpector, Snyk agent-scan, Tencent AI-Infra-Guard, ...) and writes a
normal Canari bundle:

```
canari-ingest-sarif \
  --sarif skillspector.sarif \
  --name @modelcontextprotocol/server-filesystem --version 2025.1.0 \
  --registry npm \
  --artifact-sha256 <sha256 of the scanned artifact> \
  --key out/private_key.pem --out out/attestations
```

Rules it enforces, so the ledger cannot become a rubber stamp:

- **The upstream tool is named, not hidden.** Every check records
  `tool = <scanner>/<version>` and `checker.id` says it was ingested by Canari.
- **The artifact digest is required.** A scan result without the scanned
  artifact's sha256 cannot be bound to anything, so the command refuses.
- **An unusable report is an error, not a pass.** No run block, or
  `executionSuccessful: false`, yields verdict `error`.
- **Findings move the verdict.** Critical/high → `fail`; lower severity →
  `pass-with-findings`; no findings → `pass`.

### 2. Drift report (what changed since last week)

```
canari-drift --store out --write out/drift
# verdict flips / same-version silent changes / findings added / findings removed
```

`run_weekly.py` writes this report automatically after every scan.

### 3. Endpoint decay, judged from a streak rather than a single probe

A probe answers "what did this endpoint do at that moment", not "is this entry
dead". Treating one failed probe as a death certificate is a mistake that has
already been made and corrected in public: of 52 hosts that failed at least once
in a ten-day window, 27 (51.9%) answered again later
([registry#1692](https://github.com/modelcontextprotocol/registry/issues/1692)) —
which is why that issue asks for *n consecutive failures separated in time*,
not one.

```
canari-monitor --max-probe 50                    # probe, append, re-derive
canari-monitor --report-only                     # re-derive from history only
```

A verdict needs repeated, **time-separated** confirmations (default: 2, at least
6 h apart), so a burst of probes counts once. A success ends the run, and a
record with both a success and a failure is reported as `FLAPPING` rather than
rounded to broken. Two failure classes are never merged:

| verdict | means |
|---|---|
| `INCONSISTENT_CONFIRMED` | the endpoint answered, and the answer was not MCP — the *declaration* is wrong |
| `UNAVAILABLE_CONFIRMED` | the endpoint did not answer — *availability*, not a wrong declaration |
| `FLAPPING` | both succeeded and failed in the record, too few spaced confirmations to call it |
| `INSUFFICIENT_EVIDENCE` | first failure, or a burst of probes inside one window |
| `NEUTRAL_ONLY` | 401/403, 5xx, unsupported protocol — we could not look, so there is no finding |

`401`, `5xx`, an unsupported protocol version and a partial handshake are
recorded but never accumulate: "we could not look" is not "it is broken".

### 4. Use it from any MCP host (dsh, Codex, Claude, ...)

`canari-mcp` speaks MCP over stdio (zero dependencies) and exposes three tools:
`gate_check`, `verify_bundle`, `store_summary`.

```json
{
  "mcpServers": {
    "canari": {
      "command": "canari-mcp"
    }
  }
}
```

No arguments needed: the wheel ships a snapshot of the newest signed attestation
per component (1417 components, rebuilt by `scripts/build_snapshot.py` from
`dataset/`), so `gate_check` answers out of the box. Point `--store` (or
`$CANARI_STORE`) at a full ledger checkout when you want the complete
supersession history instead of the snapshot.

A host (or agent) can then ask: "is npm:express allowed to install?" and get
`ALLOW / BLOCK / REVIEW` with reasons, backed by a signed, offline-verifiable
attestation.

### 4. Gate the actual install command

`canari-guard` wraps an install command, checks every component against the
ledger, and refuses to execute when the verdict blocks:

```
canari-guard -- dsh plugin --profile wbpj add dsh-purge
canari-guard -- npm install some-mcp-server
canari-guard -- pip install mcp-server-fetch==0.2.1

# exit 0 allowed+executed | 5 blocked by ledger | 6 review not confirmed
# --dry-run prints what would run; --allow-review accepts pass-with-findings
```

The host is never patched - the guard sits in front of the install command.

### 5. Gate a server before it starts: `canari-mcp-gate`

`canari-mcp-gate` is a stdio wrapper. Put it where the MCP client's `command`
used to be; it looks the component up in the signed ledger, then execs the real
server and proxies the stream byte-for-byte.

**Its default is fail-open, and that is a choice you should know you are making.**
A component with no attestation, an unidentifiable command, or a missing store
does not block: the wrapper prints a warning to stderr and runs the server anyway.
A gate that refuses every server it has never seen gets uninstalled after one use.
If you want the opposite posture, ask for it explicitly:

```
# strict: refuse anything not in the ledger
canari-mcp-gate --store out --key out/public_key.json --on-unknown=block -- \
    npx -y @modelcontextprotocol/server-filesystem /tmp

# review: stop and make a human confirm (exit 6 unless --allow-review)
canari-mcp-gate --store out --on-unknown=review -- npx -y some-server

# default (allow): unknown components run with a warning
canari-mcp-gate --store out -- npx -y some-server
```

| situation | default behaviour | with `--on-unknown=block` |
|---|---|---|
| ledger has a BLOCK verdict | blocked (exit 5) | blocked (exit 5) |
| ledger has a REVIEW verdict | exit 6 unless `--allow-review` | same |
| component not in the ledger | **runs**, warning on stderr | blocked (exit 5) |
| command has no derivable registry identity | **runs** | blocked (exit 5) |
| `--store` directory does not exist | **runs**, warning on stderr | blocked (exit 5) |

Two things it cannot do: it is configuration-level (whoever edits the MCP config
can remove the wrapper), and it gates *starting* a server, not what that server
does afterwards. Client-specific setup, including a dsh profile that was tested
end-to-end, is in [docs/integrations/cline.md](docs/integrations/cline.md).

For DeepSeek Harness (dsh), add this to the profile's `cordis.patch.yml`
(verified end-to-end on dsh: the model called `mcp__canari__store_summary` and
received the live component count):

```yaml
    - id: mcp-canari
      name: '@deepseek-ai/dsh-mcp-client'
      config:
        serverName: canari
        transport: stdio
        command: 'canari-mcp'          # or: python -m canari.mcp_server
        args: ['--store', '<path-to-store>',
               '--key', '<path-to-store>/public_key.json']
        failOnStartupError: true
```


### 6. Ask whether two names are the same component

A name is not an identity: 134 bare names exist on both npm and PyPI inside one
MCP Registry snapshot, and 33 of those are unrelated projects under different
GitHub owners (`experiments/identity_conflict/`). The repository a package is
published from is the cheap disambiguator:

```
canari-identity check npm:ato-mcp pypi:ato-mcp
# npm:ato-mcp vs pypi:ato-mcp: DIFFERENT
#   github.com/william-laverty/ato-mcp and github.com/bigred97/ato-mcp are...

canari-identity check npm:aether-browser pypi:aether-browser
# SAME - both sides publish from github.com/aetherai3/agent-browser

# exit 0 same | 1 different | 2 unknown (no repository URL, or lookup failed)
```

```
canari-identity clusters --store out --write out/identity
# records 6787  clusters 0  members 0  without-repository 6787
```

`clusters` groups attestations by publishing repository, so one component
published to two ecosystems becomes one cluster with two members.

A repository link is **not** proof that two names are the same package: a
monorepo publishes several. Measured on real data - `modelcontextprotocol/servers`
ships `mcp-server-fetch`, `mcp-server-git` and `mcp-server-time`. Those land in
one cluster and it is reported as `kind: monorepo` with `distinct_names: 3`,
so a reader sees a project family rather than inferring sameness. Records with
no repository are counted separately, never folded into a cluster. It also
reports two shapes: `repo_changed` (the same component was published from a
different repository over time - a transfer or a takeover, either way visible)
and `name_collision` (the same bare name from different repositories in different
ecosystems - legal, but the consumer needs to know).

```
canari-identity sign   --store out --key out/private_key.pem --out out/identity
canari-identity verify --claims out/identity --key out/public_key.json
```

`sign` writes one DSSE/Ed25519 claim per cluster. The claim asserts only the
**link** - these members share one publishing repository, by
`publishing-repository/v1` - plus the conflicts visible for that cluster. It
does not assert that any member is safe; that stays the attestation's job.
`verify` needs no network and no Canari store: signature plus claim structure.

The live store currently reports **0 clusters / 6,787 records without a
repository**, because every record predates the field. That is the honest state,
not a bug: the first scan after this change starts populating it.

**Enforcing it at the gate is opt-in.** Passing `--identity-claim` (or setting
`require_identity` in a policy file) makes the gate refuse unless the
attestation's publishing repository matches a *signed* identity claim:

```
canari-gate --store out --registry npm --name foo \
    --key out/public_key.json --identity-claim out/identity/<cluster>.identity.json
```

The two entry points that actually stop a package take the same switch as a
directory, and resolve the claim themselves from the record's repository:

```
canari-guard --identity-dir out/identity -- npm install some-mcp-server
canari-mcp-gate --store out --identity-dir out/identity -- npx -y some-server
```

With `--identity-dir` set, a component whose claim is missing is **blocked**, not
skipped - a requested check that cannot be performed is never a pass.

Default behaviour is unchanged: no flag, no new refusals. An attestation with no
recorded repository blocks under this flag, because identity cannot be
established from nothing - `no repository` is not `same`.

`unknown` is never reported as `same`: absence of a repository URL on either
side fails the comparison rather than passing it. This is the pair verdict only;
it does not index the ecosystem. ecosyste.ms already serves repo -> packages in
bulk, and Canari does not rebuild that index - it produces a verdict that can be
signed, kept in the append-only log and enforced at install time.

## Multi-registry coverage

| Registry | Source | What we check | What we inherit |
|---|---|---|---|
| npm | search API + packument + tarball sha256 | existence, version, artifact hash, maintainers | - |
| PyPI | Simple API + JSON API | same | - |
| MCP Registry | official REST | identity presence | - |
| dsh.so | JSON API | **reference existing L1-L5 conclusions** (not re-scanned) | dsh.so verdicts |

## Which checks come from which entry point

Two entry points produce attestations, and they do **not** run the same checks.
That is deliberate: a single-component CLI has no comparison corpus, so it cannot
answer a question about a set.

| check | `canari-baseline` (one component) | weekly scan / `run_multi` |
|---|---|---|
| L1.1 registry present | yes | yes |
| L1.2 version resolved | yes | - |
| L2.1 artifact hash | yes | yes |
| L2.2 maintainer set | yes | - |
| L2.3 manifest fields | yes | - |
| L2.4 release cadence | yes | yes |
| L2.5 metadata anomaly | - | yes |
| L2.6 typosquatting | **no** | yes |
| L2.7 / L2.8 dsh plugin refs | - | yes (dsh only) |

L2.6 is absent from the single-component path because a typosquat verdict is a
statement about a **set** of names, not about one name. When it does run, the row
records the set it compared against:

```json
"comparison_corpus": {
  "registry": "pypi",
  "kind": "name-set",
  "size": 620,
  "digest": "sha256:...",
  "canonicalization": "sha256(utf-8, casefolded names sorted asc, LF-joined, trailing LF)",
  "as_of": "2026-11-16T05:31:35Z"
}
```

plus a `corpus:<registry>:sha256:...:n=<size>` line in `evidence_refs`. Without it
the same package can be "clean" against five names and "a typosquat" against six
hundred; see [docs/analysis-corpus-dependence.md](docs/analysis-corpus-dependence.md)
for the measurements. A small `size` is itself the warning: `n=1` cannot produce a
typosquat finding at all.

### Known overstatement in already-published records (2026-11-18)

Until 2026-11-18 the record verdict was `"pass" if sha else "fail"`, so any record whose
artifact downloaded was marked passing even when checks inside it reported `unsupported`.
Re-deriving the verdict from each signed record's own checks finds:

| registry | records | would be reclassified |
|---|---|---|
| pypi | 2,763 | 2,233 (80.8%) |
| npm | 1,464 | 584 (39.9%) |

The signed records were **not** rewritten — an append-only log that edits its own history is
worthless. See [`docs/DISCLOSURE-false-pass-20261118.md`](docs/DISCLOSURE-false-pass-20261118.md)
for what was affected, what changed in the code, and the one gap this audit surfaced
(`canari-gate` resolves a record by name but never compares `artifact_sha256` against the
bytes the user is about to install).

## Honest limitations

- This is a **risk signal, not a safety guarantee**
- M0/M1 covers meta-level checks (L1-L2); behavioral checks (L3+) are M1+
- Scan coverage is limited to what registries expose publicly
- `expires_at` is 7 days - attestations go stale, re-scan needed
- **L2.7 / L2.8 are relayed, not re-derived.** They are dsh.so's install and
  security conclusions that Canari records; they are not bytes we hashed. The
  default policies accept them as evidence (otherwise 1,157 dsh records that
  carry only an upstream conclusion would block), but the stronger claim is
  available: `--policy artifact-only` requires our own L2.1 artifact hash or
  L3.1 static scan and refuses a record that only relays someone else's verdict.
- L2.6 verdicts are **relative to the recorded comparison corpus**. Comparing two
  attestations that used different corpora is not a comparison of the packages.
  - **Identity coverage is measured, not assumed (2026-11-18).** Identity links
    need a publishing repository. Of 200 candidates per ecosystem, npm publishes
    one for **188 (94.0%)**; PyPI only **65 (32.5%)**, and PyPI Trusted Publishing
    provenance (`files[].provenance` -> `publisher.repository`) recovers another
    **15 of the 135** misses, for **80/200 (40.0%)**. The remaining PyPI packages
    publish neither a repository URL nor an attestation, so no repository-based
    identity claim can ever cover them. Identity enforcement is therefore strong
    on npm and partial on PyPI - it is not a universal identity layer.
  - **We do not execute packages to read their tool surface.** `tools/list` would
    identify a server independently of its repository, and it is the obvious way
    to cover the PyPI gap - but it requires running untrusted code, which this
    project's META-ONLY rule forbids. That coverage is a deliberate non-goal, not
    an oversight.

## The threat model this addresses

postmark-mcp (MITRE ATLAS AML.CS0053): 15 clean versions, then one poisoned commit, ~300 orgs affected. After takedown, **no host was notified**. The gap: no longitudinal observation, no cross-host revocation feed, no portable verdict.

Canari fills that gap.

## License

Apache-2.0. See LICENSE and SECURITY.md.
