@coreguard/agent-commerce 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @coreguard/agent-commerce
2
2
 
3
+ [![Coreguard Agent Commerce MCP server](https://mcprush.com/badge/coreguard-agent-commerce-mcp/card.svg)](https://mcprush.com/to/coreguard-agent-commerce-mcp?ref=badge)
4
+
3
5
  Consent receipts and fail-closed execution verification for agentic purchases —
4
6
  an offline, deterministic surface for binding a user's approval to the exact
5
7
  bytes approved, and for verifying any executed trace against that receipt.
@@ -10,9 +12,10 @@ bytes approved, and for verifying any executed trace against that receipt.
10
12
  - **Fail-closed execution verification** — a consent plus an executed trace
11
13
  yields a verdict with named drift classes (AGR/1 taxonomy); incomplete or
12
14
  ambiguous evidence is never treated as a pass.
13
- - **stdio MCP server** (JSON-RPC 2.0) exposing four tools, all offline, all
14
- deterministic, zero keys: `coreguard_authorize`, `coreguard_verify_consent`,
15
- `coreguard_verify_execution`, `coreguard_assess_risk`.
15
+ - **stdio MCP server** (JSON-RPC 2.0, protocol `2025-06-18`) exposing twenty-six tools,
16
+ all offline, all deterministic, zero keys.
17
+
18
+ MIT. Node ≥ 18. No network calls, no stored credentials, no wall clock.
16
19
 
17
20
  ## MCP client configuration
18
21
 
@@ -27,17 +30,310 @@ bytes approved, and for verifying any executed trace against that receipt.
27
30
  }
28
31
  ```
29
32
 
30
- `nowSeconds` is always a caller-supplied pinned epoch (unix seconds). The
31
- server never reads the wall clock into any commitment.
33
+ Per client, the same stdio command in each one's own file:
34
+
35
+ - **Claude Code** — `claude mcp add coreguard-agent-commerce -- npx -y @coreguard/agent-commerce`
36
+ - **Claude Desktop** — the `mcpServers` block above in `claude_desktop_config.json`
37
+ - **Cursor** — the same block in `.cursor/mcp.json`
38
+ - **VS Code (Copilot MCP)** — `{"servers": {"coreguard-agent-commerce": {"type": "stdio", "command": "npx", "args": ["-y", "@coreguard/agent-commerce"]}}}` in `.vscode/mcp.json`
39
+ - **Codex CLI** — `[mcp_servers.coreguard]` with `command = "npx"` and `args = ["-y", "@coreguard/agent-commerce"]` in `config.toml`
40
+ - **Gemini CLI / Zed / Windsurf** — stdio server entry, same command
41
+
42
+ What "supported" means here: the transport and schemas are what the CI harness
43
+ exercises against a real spawned child process. No third-party client has been
44
+ launched by us yet — the status vocabulary and the append-only run log are in
45
+ `docs/agent-commerce-mcp-compatibility.md`. Do not read the list above as a test
46
+ report.
47
+
48
+ ## Tools
49
+
50
+ Every tool declares `inputSchema` and `outputSchema`, and returns
51
+ `structuredContent` next to the JSON text content. All ten are offline and
52
+ deterministic. Every tool accepts optional `callerContext` (object) which is echoed
53
+ in `structuredContent.callerContext` and never used as a cryptographic input.
54
+
55
+ ### `coreguard_authorize`
56
+
57
+ Binds an approval as a CGCR/1 consent receipt.
58
+
59
+ | Input | Type | Required | Meaning |
60
+ |---|---|---|---|
61
+ | `intent` | object | yes | CGEP/1 intent: merchant, items, total, `credentialRef`, validity window, `singleUse` |
62
+ | `policy` | object | yes | CGEP/1 policy: value limit, target / recipient / selector allowlists |
63
+ | `declaredTrace` | object | yes | the exact submit-order payload the approval covers |
64
+ | `nowSeconds` | string (digits) | yes | pinned approval epoch; a number is rejected, the wall clock is never read |
65
+
66
+ Output: `{ spec: "CGCR/1", receipt, … }` — the commitments are re-derivable by
67
+ anyone holding the record.
68
+
69
+ ### `coreguard_verify_consent`
70
+
71
+ Recomputes every commitment against the record's own approved bytes.
72
+
73
+ | Input | Type | Required |
74
+ |---|---|---|
75
+ | `consent` | object | yes — a record returned by `coreguard_authorize` |
76
+
77
+ Output: an integrity verdict; any tampered byte fails closed rather than throwing.
78
+
79
+ ### `coreguard_verify_execution`
80
+
81
+ Compares an executed order to the receipt.
82
+
83
+ | Input | Type | Required | Meaning |
84
+ |---|---|---|---|
85
+ | `consent` | object | yes | CGCR/1 record |
86
+ | `trace` | object | yes | the executed order as observed |
87
+
88
+ Output: `{ spec, verdict, risk, consumed, consumedLedger }`.
89
+
90
+ - `verdict` = `VERIFIED` only on an exact re-derivation with no drift class fired.
91
+ - `verdict` = `INVALID` otherwise, with the drifted fields named in
92
+ `risk.violations[].code` (`VALUE_ESCALATION`, `ITEM_MUTATION`,
93
+ `TARGET_MISMATCH`, `RECIPIENT_MISMATCH`, `POLICY_VIOLATION`, …).
94
+ - `consumed` becomes `true` after the first verified execution of a single-use
95
+ consent. **The ledger is process-local** (durable anchoring is `NOT_BUILT`), so
96
+ this is not replay protection across processes or hosts.
97
+
98
+ ### `coreguard_assess_risk`
99
+
100
+ Deterministic AGR/1 classification of one executed order against one approval.
101
+
102
+ | Input | Type | Required | Meaning |
103
+ |---|---|---|---|
104
+ | `intent` | object | yes | the approved order |
105
+ | `policy` | object | yes | the committed policy |
106
+ | `trace` | object | yes | the executed order |
107
+ | `consumed` | boolean | no | whether the authorization was already consumed (default `false`) |
108
+
109
+ Output: `{ classification, violations[], … }`. A rule-based conformance
110
+ classification, **not** a probabilistic fraud score.
111
+
112
+ ### `coreguard_inspect_identity`
113
+
114
+ Inspects CG-ID/1 identity split (recordId/contentDigest/anchor facts), with optional comparison.
115
+
116
+ | Input | Type | Required | Meaning |
117
+ |---|---|---|---|
118
+ | `issuer` | string | yes | identity issuer |
119
+ | `scope` | string | yes | identity scope |
120
+ | `subject` | string | yes | identity subject |
121
+ | `contentDigest` | string | yes | 64-char lowercase hex digest (no `0x` prefix) |
122
+ | `anchor` | object | no | `{ kind, locator }` anchor reference |
123
+ | `other` | object | no | another identity object for comparison |
124
+
125
+ Output: `{ identity, anchorFacts, comparison? }`.
126
+
127
+ ### `coreguard_build_attestation`
128
+
129
+ Builds a CGXA/1 offline execution attestation. No broadcast; no chain/network contact.
130
+
131
+ | Input | Type | Required | Meaning |
132
+ |---|---|---|---|
133
+ | `consent` | object | yes | CGCR/1 consent record |
134
+ | `executedTrace` | object | yes | executed trace observed by caller |
135
+ | `adapterId` | string | yes | CGXA adapter id |
136
+ | `nowSeconds` | integer or digit string | yes | pinned epoch; never wall clock |
137
+
138
+ Output: `{ spec, attestation, attestationId }`.
139
+
140
+ ### `coreguard_verify_attestation`
141
+
142
+ Verifies a CGXA/1 attestation against consent and executed trace. Offline, fail-closed.
143
+
144
+ | Input | Type | Required |
145
+ |---|---|---|
146
+ | `attestation` | object | yes |
147
+ | `attestationId` | string | yes |
148
+ | `consent` | object | yes |
149
+ | `executedTrace` | object | yes |
150
+
151
+ Output: attestation verification result including `decision` (e.g. `VERIFIED`/refused) and boundary details.
152
+
153
+ ### `coreguard_decide_outcome`
154
+
155
+ Maps a verification report to CG-OUT/1 outcome and authorization decision.
156
+
157
+ | Input | Type | Required | Meaning |
158
+ |---|---|---|---|
159
+ | `report` | object | yes | verification report / bridge-compatible report |
160
+ | `receiptId` | string | no | receipt id for optional profile reference |
161
+
162
+ Output: `{ outcome, decision, profileReference? }`. `ABSENT`/`NOT_CHECKED` never render as BLOCK; `VERIFIED ≠ SAFE`.
163
+
164
+ ### `coreguard_profile_reference`
165
+
166
+ Creates or parses a CG-OUT/1 profile reference.
167
+
168
+ | Input | Type | Required | Meaning |
169
+ |---|---|---|---|
170
+ | `action` | string | yes | `make` or `parse` |
171
+ | `receiptId` | string | for make | receipt id |
172
+ | `reference` | object/string | for parse | reference to parse |
173
+
174
+ Output: `{ action, profileReference? , parsed? }`.
175
+
176
+ ### `coreguard_consumption_status`
177
+
178
+ Checks/consumes/releases a receiptId in a consumption ledger.
179
+
180
+ | Input | Type | Required | Meaning |
181
+ |---|---|---|---|
182
+ | `receiptId` | string | yes | receipt/consent key |
183
+ | `action` | string | no | `check` (default), `consume`, or `release` |
184
+ | `storePath` | string | no | AC-CS/1 file-backed store path; defaults to `COREGUARD_CONSUMPTION_STORE` when set |
185
+
186
+ Output: `{ receiptId, action, consumed, ledger, boundary }`.
187
+
188
+ **Boundary:** the default ledger is **process-local** to this MCP server process. With `storePath` (or `COREGUARD_CONSUMPTION_STORE`), the AC-CS/1 store is used: lock-guarded and atomic across processes **on one host**. Cross-host reconciliation is CG-SPEND/1 log merge (`spend.mjs`), not this file. **NOT_BUILT:** a distributed/global register, consensus, HA replication, on-chain anchoring.
189
+
190
+ ### Wave 1 — Machine Economy (CG-ME/1, deterministic offline)
191
+
192
+ These 10 tools extend CoreGuard into x402/machine/delegation evidence flows. **Boundaries:** no payment custody, no broadcast, no network calls; x402 settlement/telemetry/physical completion verified only from caller-supplied evidence; signature trust roots/device attestation/physical-world truth NOT proven here. `VERIFIED != SAFE`.
193
+
194
+ | Tool | Purpose |
195
+ |---|---|
196
+ | `coreguard_parse_x402_challenge` | Parse/normalize x402 402 accepts; fail-closed on missing fields. |
197
+ | `coreguard_authorize_x402_payment` | Evaluate challenge against policy (maxAmount, allowedNetworks/Assets/PayTo); decision only, no payment. |
198
+ | `coreguard_verify_x402_settlement` | Verify caller-supplied settlement evidence against challenge; no network confirmation. |
199
+ | `coreguard_reconcile_payment` | Reconcile authorization, settlement evidence, and receipt. |
200
+ | `coreguard_meter_agent_usage` | Deterministic usage/cost metering from event amounts. |
201
+ | `coreguard_register_machine` | Create local machine registration record from manifest; no external attestation. |
202
+ | `coreguard_create_machine_task` | Create deterministic task record with terms/price/SLA. |
203
+ | `coreguard_verify_telemetry` | Verify telemetry structure/digest/signature presence; trust/physical truth not proven. |
204
+ | `coreguard_verify_task_completion` | Verify completion evidence against task; evidence acceptance != physical proof. |
205
+ | `coreguard_verify_delegation_chain` | Verify delegation chain structure/continuity; signatures not cryptographically verified without trust roots. |
206
+
207
+ ### Wave 2 — CGCP/1 Mapping + Trusted Signatures
208
+
209
+ 6 MCP tools map the missing/partial proposed contracts to the self-hosted CGCP/1 control plane (file-backed, single host, hash-chained audit). Additionally, `coreguard_verify_telemetry` and `coreguard_verify_delegation_chain` now perform real Ed25519 signature verification when an optional `trust` object with public keys/keyring is supplied. Verification covers signature validity over the supplied payload; it does not prove device identity, key custody, or physical-world truth.
210
+
211
+ | Tool | CGCP/1 mapping |
212
+ |---|---|
213
+ | `coreguard_create_intent` | `requestApproval` (intent/approval request) |
214
+ | `coreguard_issue_receipt` | `recordExecution` (execution receipt record) |
215
+ | `coreguard_verify_receipt` | audit-chain verification + receipt lookup |
216
+ | `coreguard_check_limits` | `evaluate` (policy/limit decision) |
217
+ | `coreguard_revoke_consent` | `decideApproval` / `revokeAgent` / `revokePolicy` |
218
+ | `coreguard_audit_transaction` | `auditReport` with optional filters |
219
+
220
+ ## Errors
221
+
222
+ Failures are tool results, never exceptions and never a process exit:
223
+
224
+ ```
225
+ MISSING_ARGUMENT: nowSeconds is required
226
+ INVALID_ARGUMENT: nowSeconds must be a pinned unix-seconds string (digits only), not a number and never the wall clock
227
+ UNKNOWN_TOOL: unknown tool: coreguard_nope
228
+ TOOL_ERROR: <message from the engine>
229
+ ```
230
+
231
+ and machine-readable as `structuredContent: { ok: false, error: { code, detail } }`.
232
+ Codes are exported from `mcp.mjs` as `ERROR_CODES`. JSON-RPC level errors stay
233
+ separate (`-32700` parse, `-32600` invalid request, `-32601` method not found); a
234
+ bad line never terminates the server.
235
+
236
+ ## Try it without a client
237
+
238
+ ```bash
239
+ # Runnable demo (approve → refuse → verify → malformed)
240
+ node examples/agent-commerce-mcp/run.mjs
241
+
242
+ # Runtime smoke check (real stdio MCP child, publish/MCPRush readiness evidence)
243
+ node scripts/agent-commerce-mcp-smoke.mjs
244
+ ```
245
+
246
+ The demo ends in `PASS (8/8)`. The smoke check ends in `11/11 PASS` and exits non-zero on any failure.
247
+ Expected demo output: `examples/agent-commerce-mcp/README.md`.
248
+
249
+ ```bash
250
+ # Control plane: policies, approvals, spend caps, revocation, audit chain (HTTP, offline)
251
+ node examples/agent-commerce-control-plane/run.mjs
252
+ ```
253
+
254
+ ## Policy & Evidence Control Plane (CGCP/1)
255
+
256
+ Beyond the per-order check, a team needs the operational layer: which agents exist,
257
+ which policy each runs under, what was approved, what was executed, what was
258
+ verified, what has been spent, and what was revoked. CGCP/1 is that layer, in this
259
+ package and self-hosted.
260
+
261
+ ```js
262
+ import { createControlPlane } from "@coreguard/agent-commerce/control-plane.mjs";
263
+
264
+ const cp = createControlPlane({ storePath: "./control-plane.json" });
265
+ cp.upsertPolicy({ id: "p1", spendLimitMinor: "5000", dailyLimitMinor: "20000",
266
+ requireApprovalAboveMinor: "2000", allowMerchants: ["merchant-a"] });
267
+ cp.upsertAgent({ id: "a1", policyId: "p1" });
268
+
269
+ cp.evaluate({ agentId: "a1", merchant: "merchant-a", amountMinor: "2500" });
270
+ // { allowed: false, reasons: ["APPROVAL_REQUIRED"], ... }
271
+ const ap = cp.requestApproval({ agentId: "a1", policyId: "p1", merchant: "merchant-a", amountMinor: "2500" });
272
+ cp.decideApproval(ap.id, { decision: "approved", decidedBy: "ops@example" });
273
+ cp.commitExecution({ agentId: "a1", merchant: "merchant-a", amountMinor: "2500", approvalId: ap.id });
274
+
275
+ cp.verifyLedger(); // { ok: true, chain: { ok: true, length, headHash } }
276
+ ```
277
+
278
+ - Immutable policy versions (an upsert appends, never rewrites history).
279
+ - Per-transaction, trailing-24h and lifetime spend caps; merchant/address allow+deny lists.
280
+ - Approvals bound to one order (agent, policy, merchant, address, amount) with expiry.
281
+ - Commits re-evaluate, so a revocation or a limit breach between authorise and commit is refused.
282
+ - Append-only hash-chained audit with `verifyAuditChain()`; tamper detection names the first broken entry.
283
+ - Lock-guarded single-host store; authenticated HTTP API (`control-plane-http.mjs`) and CLI (`control-plane-cli.mjs`).
284
+
285
+ ```text
286
+ node packages/agent-commerce/control-plane-cli.mjs serve --port 8787
287
+ ```
288
+
289
+ **NOT_BUILT:** multi-tenant isolation, RBAC/SSO/SCIM, distributed HA/consensus, KMS/HSM,
290
+ managed SLA, payment custody. One host, one API key, one JSON store. Architecture:
291
+ `docs/control-plane-architecture.md`; operations: `docs/control-plane-runbook.md`.
292
+
293
+ ## SDK, without MCP
294
+
295
+ ```js
296
+ import { createConsent, verifyExecution } from "@coreguard/agent-commerce";
297
+ ```
298
+
299
+ The MCP tools are thin wrappers over these functions; nothing is added or hidden
300
+ by going through MCP.
32
301
 
33
302
  ## Boundaries (standing)
34
303
 
35
304
  - Synthetic demo data is the caller's; nothing here contacts any commerce
36
- platform or payment network, and no contact/integration/endorsement is
37
- claimed with any provider.
38
- - **VERIFIED ≠ SAFE** — a verdict states that commitments re-derive; it is not
39
- a guarantee of any broader outcome.
40
- - Single-use consumption is process-local; durable anchoring is NOT_BUILT.
41
- - Offline by construction: no network calls, no stored credentials, no keys.
305
+ platform or payment network, and no contact/integration/endorsement is claimed
306
+ with any provider.
307
+ - **VERIFIED ≠ SAFE** — a verdict states that commitments re-derive; it is not a
308
+ guarantee of any broader outcome.
309
+ - Single-use consumption is process-local by default; the AC-CS/1 store makes it durable and atomic across processes on one host. Cross-host reconciliation is CG-SPEND/1 log merge; a global/on-chain register is `NOT_BUILT`.
310
+ - The executed trace is caller-supplied. Fetching it from a chain or a PSP is an
311
+ integration this package does not contain.
312
+ - No third-party security review, no certification. Marketplace grades are
313
+ automated heuristics, not audits — see
314
+ `docs/agent-commerce-mcp-security.md`.
315
+ - `serverInfo.version` is read from this package's `package.json`; CI fails if
316
+ they diverge.
42
317
 
43
318
  License: MIT.
319
+
320
+
321
+ ## Release readiness / MCPRush evidence
322
+
323
+ - **Release notes:** `docs/releases/0.1.3.md`
324
+ - **Publish readiness checklist:** `docs/releases/0.1.3-publish-readiness.md`
325
+ - **Security & threat model:** `docs/agent-commerce-mcp-security.md`
326
+ - **Client compatibility matrix + run log:** `docs/agent-commerce-mcp-compatibility.md`
327
+ - **Runtime smoke (real stdio):** `node scripts/agent-commerce-mcp-smoke.mjs`
328
+ - **60s demo script:** `docs/agent-commerce-mcp-demo-60s.md`
329
+ - **MCP contract tests:** `node --test test/integrations/agent-commerce-mcp.test.mjs`
330
+ - **Control plane architecture / runbook:** `docs/control-plane-architecture.md` · `docs/control-plane-runbook.md`
331
+ - **Control plane demo (HTTP, offline):** `node examples/agent-commerce-control-plane/run.mjs`
332
+
333
+ ## Honest boundaries (read before integrating)
334
+
335
+ - **`VERIFIED ≠ SAFE`** — verification means the observed execution matches the approved/committed bytes under the checked rules; it is not a blanket safety or fraud guarantee.
336
+ - **Offline / no external contacts** — this package does not contact commerce platforms, payment networks, wallets, or PSPs.
337
+ - **Single-use consumption scope** — process-local by default; AC-CS/1 gives a lock-guarded file ledger across processes on one host; CG-SPEND/1 merges logs across hosts; a global register and on-chain anchoring are `NOT_BUILT`.
338
+ - **Caller-supplied observed trace** — execution verification checks the trace you provide against the consent; it does not independently fetch or prove external payment/network truth.
339
+ - **No fake "Tested" claims** — client compatibility is marked CONFIG-DOCUMENTED until a real run is recorded in the compatibility run log.