# Outil Local

The downloadable local MCP proxy (`npx @veritia/mcp-server`). It runs next to
Claude Desktop, holds the agent's Ed25519 private key, and — in its runtime mode — discovers
the provider's tools, signs a DPoP proof per call, and forwards with the delegation token
attached.

Spec: [`spec.md`](spec.md). Cross-module wire: [`../contracts.md`](../contracts.md).

## Status

| Mode | Build step | State |
|---|---|---|
| `init` | 2 | ✅ implemented (incl. `--force`'s mandate-breakage warning, contracts §9) |
| runtime proxy | 5 | ✅ implemented (incl. `NP_HOME`/`NP_MANDATE` folder resolution, contracts §9.5) |
| `setup` | 5b | ✅ implemented |

## `init`

```
npm install
npm run build
node dist/index.js init          # or: npm run init
```

Output:

```
Private key written to /home/<user>/.veritia/agent.key  (chmod 600)
Public key — paste this into the mandate form:
{"kty":"OKP","crv":"Ed25519","x":"<b64url>"}
Key id (kid / RFC 7638 thumbprint): <b64url>
```

- **Private key** — PKCS#8 PEM at `${NP_HOME:-~/.veritia}/agent.key`, mode `0600`,
  directory `0700`. Never an env var, never logged, never transmitted. One per **machine**, not
  per AI client (contracts §9) — what's per-client is the mandate (see `setup` below).
- **Refuses to overwrite** an existing key file. Pass `--force` to replace it — since every
  mandate on this machine binds to this one key, `--force` first lists every mandate folder
  under `NP_HOME` and its expiry, and warns that all of them break at once; requires an
  interactive `y` unless `--yes` is also passed.
- The printed public JWK one-liner is **byte-identical** to what lands in the mandate JWT's
  `cnf.jwk` and in every DPoP proof header — paste it verbatim into the SPA mandate form.
- `NP_HOME` overrides the directory (env wins over the default).

## `setup`

```
npx @veritia/mcp-server setup <setup_redeem_url>
```

Redeems the one-time setup code the SPA prints after minting a mandate (contracts §9) into a
**named mandate folder**: `${NP_HOME}/<agent_label-slugified>/config.json`, mode `0600`. Refuses
if `agent.key` doesn't exist yet (`init` runs once per machine, not once per client). Always
overwrites that one folder — `config.json` is the replaceable half of a mandate, `agent.key`
never moves. The URL is single-use and expires after 10 minutes.

## Runtime proxy

```
AGENT_DELEGATION_TOKEN=<jws> PROVIDER_API_ENDPOINT=http://localhost:8081/mcp node dist/index.js
```

(env wins outright when both vars are set, for manual testing — otherwise the values come from
the selected mandate folder's `config.json`, written by `setup`). Which folder: `NP_MANDATE`
picks one under `NP_HOME` by name; if unset, exactly one folder is used automatically, and
zero/multiple folders each refuse to start with a message naming why — see
[`spec.md §4.1`](spec.md) / [`contracts.md §9.5`](../contracts.md).

On startup it connects to `PROVIDER_API_ENDPOINT`, discovers its tools via `tools/list`, and
serves **exactly those** over stdio to Claude Desktop — no hardcoded tool list. Every forwarded
call is signed with a fresh DPoP proof (`src/dpop.ts`) built from the agent's private key
(`src/agent-key.ts`) and sent as `Authorization: DPoP <token>` + `DPoP: <proof>`
(`src/provider-client.ts`, wrapping the MCP SDK transport's `fetch` option per
[`spec.md §4.3`](spec.md)). A tool name Claude Desktop asks for that the provider never listed
is rejected locally (never forwarded); a 401/403 from the provider on a real call surfaces as an
MCP tool error naming the provider's `error` code, without killing the process — see
[`MANUAL-TESTING.md`](MANUAL-TESTING.md#runtime--test-matrix) for the full scenario matrix,
including the happy path live-verified against the real PDS (build step 6, done 2026-09-19).
