Metadata-Version: 2.4
Name: dw-mcp-core
Version: 0.1.0a2
Summary: DW CORE: guarded MCP gateway with declarative policy, HITL approval, tool pinning, and hash-chained audit ledger.
Author: DW Design
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/dw-design-org/dw-core
Project-URL: Repository, https://github.com/dw-design-org/dw-core
Project-URL: Security, https://github.com/dw-design-org/dw-core/blob/main/SECURITY.md
Keywords: mcp,security,gateway,ai-agents,hitl,audit
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: SECURITY.md
Requires-Dist: dw-mcp-guard<2,>=1.3.4
Dynamic: license-file

<div align="center">
  <img src="assets/banner.svg" alt="DW Core — Intelligence under control" width="100%"/>
  <br/><br/>
  <a href="https://github.com/dw-design-org/dw-core/actions/workflows/ci.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/dw-design-org/dw-core/ci.yml?branch=main&style=flat-square&label=CI&color=C6FF3D&labelColor=0B0C0D" alt="CI"/>
  </a>
  <a href="https://pypi.org/project/dw-mcp-core/">
    <img src="https://img.shields.io/badge/PyPI-dw--mcp--core%200.1.0a2%20(Alpha)-C6FF3D?style=flat-square&labelColor=0B0C0D" alt="PyPI dw-mcp-core"/>
  </a>
  <img src="https://img.shields.io/badge/python-3.11%20|%203.12%20|%203.13%20|%203.14-FFFFFF?style=flat-square&labelColor=0B0C0D" alt="Python 3.11+"/>
  <img src="https://img.shields.io/badge/license-Apache--2.0-FFFFFF?style=flat-square&labelColor=0B0C0D" alt="Apache-2.0"/>
  <img src="https://img.shields.io/badge/runtime-stdlib%20%2B%20dw--mcp--guard-C6FF3D?style=flat-square&labelColor=0B0C0D" alt="Minimal Core"/>
</div>

<br/>

**DW CORE** is a sovereign, self-hosted **governance and control layer** for AI agents — **not an agent orchestrator**.

It sits deterministically between any MCP-compatible AI client (Claude Code, Cursor, Codex, custom agents) and your upstream MCP servers (`stdio` and Streamable HTTP/TLS), enforcing declarative policy, cryptographic human-in-the-loop approval, tool definition pinning, and tamper-evident execution logs without binding you to any LLM vendor.

<div align="center">
  <img src="assets/architecture.svg" alt="DW Core Architecture — Connect. Govern. Trust." width="100%"/>
</div>

---

## The Six Pillars

| Pillar | What It Enforces |
|---|---|
| **Policy Guard** | Re-reads declarative TOML policy on every `tools/call` via a fail-closed `PolicyReloader`. `destructive`, `egress`, and `unknown` tools can never be configured as `allow`. |
| **Human Approval** | Single-use out-of-band HITL (`dw-approve-ui`) binding `(client, call_fingerprint, tool_definition_hash, matched_rule, policy_hash)`. Self-approval is disabled by default; payloads > 32 KiB require explicit truncated-payload confirmation. |
| **Flight Recorder** | Append-only SHA-256 hash-chained SQLite `events` ledger with transactional HITL audit (`BEGIN IMMEDIATE`) and external anchor verification (`dwcore audit verify --anchor-seq ... --anchor-hash ...`). |
| **Registry & Pinning** | Canonical SHA-256 pinning over `name`, `title`, `description`, `inputSchema`, and `outputSchema`. Automatically quarantines drifted tools, new unapproved tools, injection-like descriptions, and schemas deeper than 20 levels. |
| **Shadow Mode** | Time-bounded observation (`shadow_until`, max 30 days) with automatic fallback to `enforce` on expiry — while preserving absolute `ToolClass.DESTRUCTIVE` protection, `OutputGuard`, `CaMeL-lite`, and `Registry` quarantine. |
| **Policy Replay** | Deterministic offline policy impact simulation against recorded ledger calls (`dwcore policy replay`), with exact `call_id` deduplication, zero business-argument leakage, and factual coverage metrics. |

---

## Design Philosophy

- **Sovereignty & Self-Hosted**: Runs locally in `stdio` or behind your own HTTPS/TLS boundary (`--trusted-proxies` CIDR-aware). Zero SaaS telemetry, zero external control plane.
- **Determinism over Prompts**: Safety invariants live in policy rules, cryptographic bindings, and deterministic guards — not system prompt wishes.
- **LLM-Agnostic**: Works in front of any model or host that speaks Model Context Protocol (`2024-11-05` to `2025-06-18` + `oneOf` `outputSchema` compatibility).
- **Technical Sobriety (`ADR-02 / ADR-30`)**: Core runtime depends **only on Python >= 3.11 standard library plus `dw-mcp-guard >= 1.3.4`**. Optional integrations hook strictly through standard-library `entry_points(group="dw_core.hooks")`.

---

## Install

```bash
# PyPI distribution name is `dw-mcp-core` (provides the `dwcore` CLI and imports as `dw_core`)
pip install dw-mcp-core==0.1.0a2

# Or run via container image (GHCR)
docker run --rm ghcr.io/dw-design-org/dw-core:0.1.0a2 version
```

> **Package naming note**: Install from PyPI using `pip install dw-mcp-core` (the unrelated PyPI package `dw-core` belongs to a different project and also uses a `dw_core` module namespace — do not install both into the same Python environment).

---

## 2-Minute Quickstart

### 1. Zero-config `wrap` around any stdio MCP server

```bash
dwcore wrap --mode shadow --shadow-days 7 -- npx -y @modelcontextprotocol/server-filesystem /tmp
```

### 2. Import an existing Claude / Cursor config & validate

```bash
dwcore init --from-claude --mode shadow --shadow-days 7 --out policy.toml
dwcore check policy.toml
```

### 3. Run stdio gateway or authenticated Streamable HTTPS server

```bash
# Local stdio gateway (Claude Desktop, Cursor, local MCP clients)
dwcore serve policy.toml

# Authenticated Streamable HTTPS server
dwcore token create agent-ci --tokens tokens.json --scopes mcp
dwcore server policy.toml --tokens tokens.json --host 0.0.0.0 --port 8765 \
  --certfile cert.pem --keyfile key.pem
```

### 4. Out-of-band approval UI, offline replay & ledger verification

```bash
# Create an approver account and start DW Approve UI
dwcore approve-ui account alice --roles operator,admin --accounts accounts.txt
dwcore approve-ui run --ledger ~/.local/state/dw-core/ledger.sqlite3 --accounts accounts.txt

# Offline policy simulation & hash-chain audit verification
dwcore policy replay candidate-policy.toml --ledger ~/.local/state/dw-core/ledger.sqlite3
dwcore audit verify --ledger ~/.local/state/dw-core/ledger.sqlite3
```

---

## Known V0.1 Alpha Limits

DW Core V0.1 Alpha states its boundaries openly so operators can deploy with accurate expectations:

- **CaMeL-lite fail-closed without HITL override**: Reading a tainted or injection-flagged document can block subsequent legitimate writes that share context tokens (such as working directory or topic terms) with no HITL override in V0.1. Guarded human escalation is the top strategic priority for V0.2.
- **Registry drift checked at startup**: Tool definitions are pinned and verified on `Gateway.start()`. There is no mid-session revalidation in persistent HTTP mode in V0.1; unknown tools are Trust-On-First-Use (TOFU) on initial startup, and pinning verifies declared JSON metadata/schemas rather than hidden upstream runtime behavior.
- **In-memory taint state**: Session taint is held in memory per `client_id` with TTL (persists across HTTP reconnects while the server runs; process-scoped in `stdio`).
- **Audit ledger & `audit verify` scope**: `dwcore audit verify` validates the full `events` SHA-256 chain and cross-checks `requests.status`, `requests.decided_by`, and missing/deleted `requests` rows. Validity-affecting columns `requests.binding` and `requests.expires_at` are **not** included in the chained `events` table: even with external anchoring of `events`, direct local SQLite tampering of `requests.binding` or `requests.expires_at` is not detected by `dwcore audit verify` (both remain enforced at runtime on `consume()`). External anchoring only protects the `events` hash chain against local history rewriting under root or the same OS UID.
- **Post-dispatch ledger failure & indeterminate execution**: If the ledger fails after dispatching a call upstream, or if the upstream crashes or times out mid-mutation, DW Core halts with `AUDIT FAILURE AFTER DISPATCH` / `upstream_indeterminate` and never auto-retries.
- **Policy rollback (`A → B → A`)**: Without a `policy_epoch` counter (planned for V0.2), an unexpired approval created under policy hash `H_A` (default 10-minute TTL) becomes valid again if policy reverts strictly to `H_A` before expiration.

---

## Companion Library & Security

- Security runtime kernel: [**`dw-mcp-guard`**](https://github.com/dw-design-org/dw-mcp-guard) (standalone zero-dependency Python library, `>= 1.3.4`).
- Vulnerability reporting & full trust model: [SECURITY.md](SECURITY.md).
- License: **Apache-2.0** — see [LICENSE](LICENSE).
