@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 +307 -11
- package/aer1.mjs +954 -0
- package/anchor.mjs +278 -0
- package/bin/mcp.mjs +0 -0
- package/cgcp-mcp-tools.mjs +142 -0
- package/composition.mjs +150 -0
- package/consumption-store.mjs +114 -38
- package/control-plane-cli.mjs +272 -0
- package/control-plane-http.mjs +348 -0
- package/control-plane.mjs +1177 -0
- package/decision.mjs +152 -0
- package/firewall.mjs +1 -1
- package/identity.mjs +205 -0
- package/index.d.ts +991 -1
- package/index.mjs +240 -3
- package/machine-economy.mjs +366 -0
- package/mcp.mjs +657 -28
- package/observations.mjs +524 -0
- package/outcomes-bridge.mjs +169 -0
- package/outcomes.mjs +220 -0
- package/package.json +64 -14
- package/prod/kms-anchor.mjs +51 -0
- package/prod/migrate.mjs +73 -0
- package/prod/observability.mjs +35 -0
- package/prod/rbac.mjs +46 -0
- package/prod/schema.mjs +188 -0
- package/prod/sqlite-storage.mjs +135 -0
- package/profile-ref.mjs +130 -0
- package/reference.mjs +350 -0
- package/risk-cli.mjs +10 -2
- package/risk.mjs +49 -2
- package/spend.mjs +291 -0
- package/trust.mjs +322 -0
package/mcp.mjs
CHANGED
|
@@ -7,13 +7,7 @@
|
|
|
7
7
|
* (one JSON object per line, both directions) — the same shape MCP clients
|
|
8
8
|
* speak for stdio servers.
|
|
9
9
|
*
|
|
10
|
-
* Tools (all offline,
|
|
11
|
-
* coreguard_authorize intent + policy + declaredTrace + nowSeconds
|
|
12
|
-
* -> CGCR/1 consent record (pinned receipt)
|
|
13
|
-
* coreguard_verify_consent consent record -> integrity verdict
|
|
14
|
-
* coreguard_verify_execution consent + executed trace -> fail-closed
|
|
15
|
-
* verdict + AGR/1 taxonomy + named drift
|
|
16
|
-
* coreguard_assess_risk intent + policy + trace -> AGR/1 report
|
|
10
|
+
* Tools (all offline/self-hosted, deterministic, zero network keys): 10 core consent/verification tools + 10 Wave 1 Machine Economy tools + 6 Wave 2 CGCP/1 mapping tools (intent/receipt/limits/revoke/audit) = 26 total. Optional trust roots enable Ed25519 signature verification for telemetry/delegation; no custody, no broadcast, no network calls; external settlement/physical truth/device identity beyond supplied key material NOT proven.
|
|
17
11
|
*
|
|
18
12
|
* BOUNDARIES (standing): synthetic demo data is the caller's; nothing here
|
|
19
13
|
* contacts any platform or payment network (no contact/integration/endorsement
|
|
@@ -24,6 +18,7 @@
|
|
|
24
18
|
*/
|
|
25
19
|
|
|
26
20
|
import { createInterface } from "node:readline";
|
|
21
|
+
import { readFileSync } from "node:fs";
|
|
27
22
|
import { fileURLToPath } from "node:url";
|
|
28
23
|
import {
|
|
29
24
|
createConsent,
|
|
@@ -32,26 +27,279 @@ import {
|
|
|
32
27
|
assessRisk,
|
|
33
28
|
AGENT_COMMERCE_VERSION,
|
|
34
29
|
CONSENT_SPEC,
|
|
30
|
+
splitIdentity,
|
|
31
|
+
compareIdentities,
|
|
32
|
+
anchorFacts,
|
|
33
|
+
buildAttestation,
|
|
34
|
+
verifyAttestation,
|
|
35
|
+
outcomeForVerificationReport,
|
|
36
|
+
authorizationDecision,
|
|
37
|
+
makeProfileReference,
|
|
38
|
+
parseProfileReference,
|
|
39
|
+
createConsumptionStore,
|
|
40
|
+
CONSUMPTION_STORE_BOUNDARY,
|
|
41
|
+
CGXA_VERSION,
|
|
42
|
+
SOROBAN_CONSENT_BINDING_VERSION,
|
|
43
|
+
buildSorobanConsentBinding,
|
|
35
44
|
} from "./index.mjs";
|
|
45
|
+
import {
|
|
46
|
+
parseX402Challenge,
|
|
47
|
+
authorizeX402Payment,
|
|
48
|
+
verifyX402Settlement,
|
|
49
|
+
reconcilePayment,
|
|
50
|
+
meterAgentUsage,
|
|
51
|
+
registerMachine,
|
|
52
|
+
createMachineTask,
|
|
53
|
+
verifyTelemetry,
|
|
54
|
+
verifyTaskCompletion,
|
|
55
|
+
verifyDelegationChain,
|
|
56
|
+
MACHINE_ECONOMY_VERSION,
|
|
57
|
+
MACHINE_ECONOMY_BOUNDARY,
|
|
58
|
+
} from "./machine-economy.mjs";
|
|
59
|
+
import { createIntent, issueReceipt, verifyReceipt as verifyCgcpReceipt, checkLimits, revokeConsent, auditTransaction, CGCP_MCP_BOUNDARY } from "./cgcp-mcp-tools.mjs";
|
|
36
60
|
|
|
37
61
|
const PROTOCOL_VERSION = "2025-06-18";
|
|
38
|
-
|
|
62
|
+
|
|
63
|
+
// Single source of truth for the version: the package manifest. The server used
|
|
64
|
+
// to hard-code its own string and drifted from npm (1.0.0 vs 0.1.2); the CI test
|
|
65
|
+
// test/integrations/agent-commerce-mcp.test.mjs now fails if they differ.
|
|
66
|
+
const PACKAGE = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
67
|
+
const SERVER_INFO = Object.freeze({ name: "coreguard-agent-commerce", version: PACKAGE.version });
|
|
39
68
|
const SERVER_BOUNDARY =
|
|
40
69
|
"offline verification surface — binds approvals and verifies executions on committed machinery; " +
|
|
41
70
|
"no contact with any commerce platform or payment network; VERIFIED ≠ SAFE; " +
|
|
42
|
-
"single-use consumption is process-local
|
|
71
|
+
"single-use consumption is process-local by default — pass storePath or set COREGUARD_CONSUMPTION_STORE for an " +
|
|
72
|
+
"AC-CS/1 lock-guarded file ledger (cross-process on this host); cross-host reconciliation is CG-SPEND/1 merge; " +
|
|
73
|
+
"on-chain anchoring NOT_BUILT";
|
|
74
|
+
|
|
75
|
+
// Optional deployment-wide AC-CS/1 ledger path. Unset keeps the documented
|
|
76
|
+
// process-local default; setting it makes single-use durable across processes
|
|
77
|
+
// on this host without changing any tool arguments.
|
|
78
|
+
const DEFAULT_CONSUMPTION_STORE = process.env.COREGUARD_CONSUMPTION_STORE?.trim() || null;
|
|
43
79
|
|
|
44
80
|
const TOOL_NAMES = Object.freeze([
|
|
45
81
|
"coreguard_authorize",
|
|
46
82
|
"coreguard_verify_consent",
|
|
47
83
|
"coreguard_verify_execution",
|
|
48
84
|
"coreguard_assess_risk",
|
|
85
|
+
"coreguard_inspect_identity",
|
|
86
|
+
"coreguard_build_attestation",
|
|
87
|
+
"coreguard_verify_attestation",
|
|
88
|
+
"coreguard_decide_outcome",
|
|
89
|
+
"coreguard_profile_reference",
|
|
90
|
+
"coreguard_consumption_status",
|
|
91
|
+
"coreguard_parse_x402_challenge",
|
|
92
|
+
"coreguard_authorize_x402_payment",
|
|
93
|
+
"coreguard_verify_x402_settlement",
|
|
94
|
+
"coreguard_reconcile_payment",
|
|
95
|
+
"coreguard_meter_agent_usage",
|
|
96
|
+
"coreguard_register_machine",
|
|
97
|
+
"coreguard_create_machine_task",
|
|
98
|
+
"coreguard_verify_telemetry",
|
|
99
|
+
"coreguard_verify_task_completion",
|
|
100
|
+
"coreguard_verify_delegation_chain",
|
|
101
|
+
"coreguard_create_intent",
|
|
102
|
+
"coreguard_issue_receipt",
|
|
103
|
+
"coreguard_verify_receipt",
|
|
104
|
+
"coreguard_check_limits",
|
|
105
|
+
"coreguard_revoke_consent",
|
|
106
|
+
"coreguard_audit_transaction",
|
|
49
107
|
]);
|
|
50
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Stable error contract. Every failure is a tool result with `isError: true`,
|
|
111
|
+
* a human-readable `content[0].text` of the form "CODE: detail", and a machine
|
|
112
|
+
* readable `structuredContent.error = { code, detail }`. The server never exits
|
|
113
|
+
* or throws on bad input — the process keeps serving the next request.
|
|
114
|
+
*/
|
|
115
|
+
export const ERROR_CODES = Object.freeze({
|
|
116
|
+
UNKNOWN_TOOL: "UNKNOWN_TOOL",
|
|
117
|
+
MISSING_ARGUMENT: "MISSING_ARGUMENT",
|
|
118
|
+
INVALID_ARGUMENT: "INVALID_ARGUMENT",
|
|
119
|
+
TOOL_ERROR: "TOOL_ERROR",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
function failure(code, detail) {
|
|
123
|
+
return {
|
|
124
|
+
isError: true,
|
|
125
|
+
content: [{ type: "text", text: `${code}: ${detail}` }],
|
|
126
|
+
structuredContent: { ok: false, error: { code, detail } },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function success(value) {
|
|
131
|
+
const structured = value !== null && typeof value === "object" && !Array.isArray(value) ? value : { ok: true, value };
|
|
132
|
+
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }], structuredContent: structured };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const isPlainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
136
|
+
|
|
137
|
+
function requireObjects(args, keys) {
|
|
138
|
+
for (const key of keys) {
|
|
139
|
+
if (args[key] === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: `${key} is required` };
|
|
140
|
+
if (!isPlainObject(args[key])) return { code: ERROR_CODES.INVALID_ARGUMENT, detail: `${key} must be a JSON object` };
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function optionalObject(args, key) {
|
|
146
|
+
if (args[key] === undefined) return null;
|
|
147
|
+
if (!isPlainObject(args[key])) return { code: ERROR_CODES.INVALID_ARGUMENT, detail: `${key} must be a JSON object when supplied` };
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function requireString(args, key) {
|
|
151
|
+
if (args[key] === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: `${key} is required` };
|
|
152
|
+
if (typeof args[key] !== "string" || args[key].length === 0) {
|
|
153
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: `${key} must be a non-empty string` };
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Per-tool input validation. Returns null when the arguments are usable. */
|
|
159
|
+
const VALIDATORS = Object.freeze({
|
|
160
|
+
coreguard_authorize(args) {
|
|
161
|
+
const missing = requireObjects(args, ["intent", "policy", "declaredTrace"]);
|
|
162
|
+
if (missing) return missing;
|
|
163
|
+
if (args.nowSeconds === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: "nowSeconds is required" };
|
|
164
|
+
if (typeof args.nowSeconds !== "string" || !/^[0-9]+$/.test(args.nowSeconds)) {
|
|
165
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "nowSeconds must be a pinned unix-seconds string (digits only), not a number and never the wall clock" };
|
|
166
|
+
}
|
|
167
|
+
return optionalObject(args, "callerContext");
|
|
168
|
+
},
|
|
169
|
+
coreguard_verify_consent(args) {
|
|
170
|
+
const missing = requireObjects(args, ["consent"]);
|
|
171
|
+
if (missing) return missing;
|
|
172
|
+
return optionalObject(args, "callerContext");
|
|
173
|
+
},
|
|
174
|
+
coreguard_verify_execution(args) {
|
|
175
|
+
const missing = requireObjects(args, ["consent", "trace"]);
|
|
176
|
+
if (missing) return missing;
|
|
177
|
+
return optionalObject(args, "callerContext");
|
|
178
|
+
},
|
|
179
|
+
coreguard_assess_risk(args) {
|
|
180
|
+
const missing = requireObjects(args, ["intent", "policy", "trace"]);
|
|
181
|
+
if (missing) return missing;
|
|
182
|
+
if (args.consumed !== undefined && typeof args.consumed !== "boolean") {
|
|
183
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "consumed must be a boolean when supplied" };
|
|
184
|
+
}
|
|
185
|
+
return optionalObject(args, "callerContext");
|
|
186
|
+
},
|
|
187
|
+
coreguard_inspect_identity(args) {
|
|
188
|
+
const missing = requireString(args, "issuer") || requireString(args, "scope") || requireString(args, "subject") || requireString(args, "contentDigest");
|
|
189
|
+
if (missing) return missing;
|
|
190
|
+
if (args.anchor !== undefined && args.anchor !== null && !isPlainObject(args.anchor)) {
|
|
191
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "anchor must be a JSON object when supplied" };
|
|
192
|
+
}
|
|
193
|
+
const otherErr = optionalObject(args, "other");
|
|
194
|
+
if (otherErr) return otherErr;
|
|
195
|
+
return optionalObject(args, "callerContext");
|
|
196
|
+
},
|
|
197
|
+
coreguard_build_attestation(args) {
|
|
198
|
+
const missing = requireObjects(args, ["consent", "executedTrace"]);
|
|
199
|
+
if (missing) return missing;
|
|
200
|
+
const a = requireString(args, "adapterId");
|
|
201
|
+
if (a) return a;
|
|
202
|
+
if (args.nowSeconds === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: "nowSeconds is required" };
|
|
203
|
+
const ns = args.nowSeconds;
|
|
204
|
+
const ok = (typeof ns === "number" && Number.isInteger(ns) && ns >= 0) || (typeof ns === "string" && /^[0-9]+$/.test(ns));
|
|
205
|
+
if (!ok) {
|
|
206
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "nowSeconds must be a pinned non-negative integer (or digit string)" };
|
|
207
|
+
}
|
|
208
|
+
return optionalObject(args, "callerContext");
|
|
209
|
+
},
|
|
210
|
+
coreguard_verify_attestation(args) {
|
|
211
|
+
const missing = requireObjects(args, ["attestation", "consent", "executedTrace"]);
|
|
212
|
+
if (missing) return missing;
|
|
213
|
+
const id = requireString(args, "attestationId");
|
|
214
|
+
if (id) return id;
|
|
215
|
+
return optionalObject(args, "callerContext");
|
|
216
|
+
},
|
|
217
|
+
coreguard_decide_outcome(args) {
|
|
218
|
+
const missing = requireObjects(args, ["report"]);
|
|
219
|
+
if (missing) return missing;
|
|
220
|
+
if (args.receiptId !== undefined && (typeof args.receiptId !== "string" || args.receiptId.length === 0)) {
|
|
221
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "receiptId must be a non-empty string when supplied" };
|
|
222
|
+
}
|
|
223
|
+
return optionalObject(args, "callerContext");
|
|
224
|
+
},
|
|
225
|
+
coreguard_profile_reference(args) {
|
|
226
|
+
const action = args.action;
|
|
227
|
+
if (action !== "make" && action !== "parse") {
|
|
228
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "action must be \"make\" or \"parse\"" };
|
|
229
|
+
}
|
|
230
|
+
if (action === "make") {
|
|
231
|
+
const r = requireString(args, "receiptId");
|
|
232
|
+
if (r) return r;
|
|
233
|
+
}
|
|
234
|
+
if (action === "parse") {
|
|
235
|
+
if (args.reference === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: "reference is required for action=parse" };
|
|
236
|
+
if (!isPlainObject(args.reference) && typeof args.reference !== "string") {
|
|
237
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "reference must be an object or string for action=parse" };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return optionalObject(args, "callerContext");
|
|
241
|
+
},
|
|
242
|
+
coreguard_consumption_status(args) {
|
|
243
|
+
const r = requireString(args, "receiptId");
|
|
244
|
+
if (r) return r;
|
|
245
|
+
const action = args.action ?? "check";
|
|
246
|
+
if (!["check", "consume", "release"].includes(action)) {
|
|
247
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "action must be check, consume, or release" };
|
|
248
|
+
}
|
|
249
|
+
if (args.storePath !== undefined && (typeof args.storePath !== "string" || args.storePath.length === 0)) {
|
|
250
|
+
return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "storePath must be a non-empty string when supplied" };
|
|
251
|
+
}
|
|
252
|
+
return optionalObject(args, "callerContext");
|
|
253
|
+
},
|
|
254
|
+
coreguard_parse_x402_challenge(args) { return requireObjects(args, ["challenge"]) || optionalObject(args, "callerContext"); },
|
|
255
|
+
coreguard_authorize_x402_payment(args) { return requireObjects(args, ["challenge", "policy"]) || optionalObject(args, "callerContext"); },
|
|
256
|
+
coreguard_verify_x402_settlement(args) { return requireObjects(args, ["challenge", "settlement"]) || optionalObject(args, "callerContext"); },
|
|
257
|
+
coreguard_reconcile_payment(args) { return requireObjects(args, ["authorization"]) || optionalObject(args, "callerContext"); },
|
|
258
|
+
coreguard_meter_agent_usage(args) {
|
|
259
|
+
const r = requireString(args, "agentId"); if (r) return r;
|
|
260
|
+
if (args.events === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: "events is required" };
|
|
261
|
+
if (!Array.isArray(args.events)) return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "events must be an array" };
|
|
262
|
+
return optionalObject(args, "callerContext");
|
|
263
|
+
},
|
|
264
|
+
coreguard_register_machine(args) {
|
|
265
|
+
const r = requireString(args, "machineId"); if (r) return r;
|
|
266
|
+
return requireObjects(args, ["manifest"]) || optionalObject(args, "callerContext");
|
|
267
|
+
},
|
|
268
|
+
coreguard_create_machine_task(args) {
|
|
269
|
+
const r = requireString(args, "taskId"); if (r) return r;
|
|
270
|
+
const r2 = requireString(args, "machineId"); if (r2) return r2;
|
|
271
|
+
return requireObjects(args, ["terms"]) || optionalObject(args, "callerContext");
|
|
272
|
+
},
|
|
273
|
+
coreguard_verify_telemetry(args) {
|
|
274
|
+
const r = requireString(args, "taskId"); if (r) return r;
|
|
275
|
+
return requireObjects(args, ["telemetry"]) || optionalObject(args, "callerContext");
|
|
276
|
+
},
|
|
277
|
+
coreguard_verify_task_completion(args) { return requireObjects(args, ["task", "completion"]) || optionalObject(args, "callerContext"); },
|
|
278
|
+
coreguard_verify_delegation_chain(args) {
|
|
279
|
+
if (args.chain === undefined) return { code: ERROR_CODES.MISSING_ARGUMENT, detail: "chain is required" };
|
|
280
|
+
if (!Array.isArray(args.chain)) return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "chain must be an array" };
|
|
281
|
+
if (args.trust !== undefined && (typeof args.trust !== "object" || args.trust === null || Array.isArray(args.trust))) return { code: ERROR_CODES.INVALID_ARGUMENT, detail: "trust must be an object when supplied" };
|
|
282
|
+
return optionalObject(args, "callerContext");
|
|
283
|
+
},
|
|
284
|
+
coreguard_create_intent(args) { const r=requireString(args,"storePath"); if(r) return r; const a=requireString(args,"agentId"); if(a) return a; return optionalObject(args,"callerContext"); },
|
|
285
|
+
coreguard_issue_receipt(args) { const r=requireString(args,"storePath"); if(r) return r; const a=requireString(args,"agentId"); if(a) return a; return optionalObject(args,"callerContext"); },
|
|
286
|
+
coreguard_verify_receipt(args) { const r=requireString(args,"storePath"); if(r) return r; return optionalObject(args,"callerContext"); },
|
|
287
|
+
coreguard_check_limits(args) { const r=requireString(args,"storePath"); if(r) return r; const a=requireString(args,"agentId"); if(a) return a; return optionalObject(args,"callerContext"); },
|
|
288
|
+
coreguard_revoke_consent(args) { const r=requireString(args,"storePath"); if(r) return r; const t=requireString(args,"targetType"); if(t) return t; const i=requireString(args,"targetId"); if(i) return i; return optionalObject(args,"callerContext"); },
|
|
289
|
+
coreguard_audit_transaction(args) { const r=requireString(args,"storePath"); if(r) return r; return optionalObject(args,"callerContext"); },
|
|
290
|
+
});
|
|
291
|
+
|
|
51
292
|
function integerStringSchema(description) {
|
|
52
293
|
return { type: "string", description, pattern: "^[0-9]+$" };
|
|
53
294
|
}
|
|
54
295
|
|
|
296
|
+
const CALLER_CONTEXT_PROPERTY = {
|
|
297
|
+
callerContext: {
|
|
298
|
+
type: "object",
|
|
299
|
+
description: "Optional caller-provided trace/context metadata. Echoed in structuredContent.callerContext; never used as a cryptographic input.",
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
|
|
55
303
|
const TOOLS = Object.freeze([
|
|
56
304
|
{
|
|
57
305
|
name: "coreguard_authorize",
|
|
@@ -64,9 +312,22 @@ const TOOLS = Object.freeze([
|
|
|
64
312
|
policy: { type: "object", description: "CGEP/1 policy (value limit + target/recipient/selector allowlists)" },
|
|
65
313
|
declaredTrace: { type: "object", description: "the exact submit-order payload the approval covers" },
|
|
66
314
|
nowSeconds: integerStringSchema("pinned approval epoch (unix seconds) — never the wall clock"),
|
|
315
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
67
316
|
},
|
|
68
317
|
required: ["intent", "policy", "declaredTrace", "nowSeconds"],
|
|
69
318
|
},
|
|
319
|
+
outputSchema: {
|
|
320
|
+
type: "object",
|
|
321
|
+
description: "CGCR/1 consent record with pinned commitments over approved bytes.",
|
|
322
|
+
properties: {
|
|
323
|
+
spec: { type: "string", description: "always CGCR/1" },
|
|
324
|
+
receipt: { type: "object", description: "pinned receipt commitments and timestamp" },
|
|
325
|
+
intent: { type: "object" },
|
|
326
|
+
policy: { type: "object" },
|
|
327
|
+
callerContext: { type: "object", description: "echoed caller context when supplied" },
|
|
328
|
+
},
|
|
329
|
+
additionalProperties: true,
|
|
330
|
+
},
|
|
70
331
|
},
|
|
71
332
|
{
|
|
72
333
|
name: "coreguard_verify_consent",
|
|
@@ -74,27 +335,54 @@ const TOOLS = Object.freeze([
|
|
|
74
335
|
"Verify a consent record's integrity and binding: recompute every commitment against the record's own approved bytes. Any tampered byte fails closed.",
|
|
75
336
|
inputSchema: {
|
|
76
337
|
type: "object",
|
|
77
|
-
properties: {
|
|
338
|
+
properties: {
|
|
339
|
+
consent: { type: "object", description: "CGCR/1 consent record as returned by coreguard_authorize" },
|
|
340
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
341
|
+
},
|
|
78
342
|
required: ["consent"],
|
|
79
343
|
},
|
|
344
|
+
outputSchema: {
|
|
345
|
+
type: "object",
|
|
346
|
+
description: "Integrity verdict for the record's own bytes; fail-closed on tamper.",
|
|
347
|
+
properties: {
|
|
348
|
+
verdict: { type: "string", description: "VERIFIED or INVALID/UNKNOWN — never SAFE" },
|
|
349
|
+
spec: { type: "string" },
|
|
350
|
+
callerContext: { type: "object" },
|
|
351
|
+
},
|
|
352
|
+
additionalProperties: true,
|
|
353
|
+
},
|
|
80
354
|
},
|
|
81
355
|
{
|
|
82
356
|
name: "coreguard_verify_execution",
|
|
83
357
|
description:
|
|
84
|
-
"Verify an executed order against a consent record, fail-closed: exact execution -> VERIFIED; any drift -> INVALID with the drifted field named (AGR/1). Single-use consents are consumed by
|
|
358
|
+
"Verify an executed order against a consent record, fail-closed: exact execution -> VERIFIED; any drift -> INVALID with the drifted field named (AGR/1). Single-use consents are consumed by first verified execution (process-local by default; file-backed host store via AC-CS/1 when supplied by caller integration).",
|
|
85
359
|
inputSchema: {
|
|
86
360
|
type: "object",
|
|
87
361
|
properties: {
|
|
88
362
|
consent: { type: "object", description: "CGCR/1 consent record" },
|
|
89
363
|
trace: { type: "object", description: "the executed order payload as observed" },
|
|
364
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
90
365
|
},
|
|
91
366
|
required: ["consent", "trace"],
|
|
92
367
|
},
|
|
368
|
+
outputSchema: {
|
|
369
|
+
type: "object",
|
|
370
|
+
description: "Fail-closed execution verdict with AGR/1 risk report and consumption boundary.",
|
|
371
|
+
properties: {
|
|
372
|
+
spec: { type: "string", description: "AC-SDK/1" },
|
|
373
|
+
verdict: { type: "string", description: "VERIFIED or INVALID" },
|
|
374
|
+
risk: { type: "object" },
|
|
375
|
+
consumed: { type: "boolean" },
|
|
376
|
+
consumedLedger: { type: "string" },
|
|
377
|
+
callerContext: { type: "object" },
|
|
378
|
+
},
|
|
379
|
+
additionalProperties: true,
|
|
380
|
+
},
|
|
93
381
|
},
|
|
94
382
|
{
|
|
95
383
|
name: "coreguard_assess_risk",
|
|
96
384
|
description:
|
|
97
|
-
"Classify one executed order against one approved authorization with the deterministic AGR/1 taxonomy
|
|
385
|
+
"Classify one executed order against one approved authorization with the deterministic AGR/1 taxonomy. Not a probabilistic fraud score; VERIFIED ≠ SAFE.",
|
|
98
386
|
inputSchema: {
|
|
99
387
|
type: "object",
|
|
100
388
|
properties: {
|
|
@@ -102,33 +390,366 @@ const TOOLS = Object.freeze([
|
|
|
102
390
|
policy: { type: "object", description: "the committed policy" },
|
|
103
391
|
trace: { type: "object", description: "the executed order payload" },
|
|
104
392
|
consumed: { type: "boolean", description: "whether this authorization was already consumed", default: false },
|
|
393
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
105
394
|
},
|
|
106
395
|
required: ["intent", "policy", "trace"],
|
|
107
396
|
},
|
|
397
|
+
outputSchema: {
|
|
398
|
+
type: "object",
|
|
399
|
+
description: "Deterministic AGR/1 risk report with classification, named violations, and taxonomy metadata.",
|
|
400
|
+
properties: {
|
|
401
|
+
classification: { type: "string" },
|
|
402
|
+
violations: { type: "array" },
|
|
403
|
+
callerContext: { type: "object" },
|
|
404
|
+
},
|
|
405
|
+
additionalProperties: true,
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
name: "coreguard_inspect_identity",
|
|
410
|
+
description:
|
|
411
|
+
"Inspect CG-ID/1 identity split: recordId (who) vs contentDigest (what), with optional anchor facts and optional comparison to another identity. Offline and deterministic.",
|
|
412
|
+
inputSchema: {
|
|
413
|
+
type: "object",
|
|
414
|
+
properties: {
|
|
415
|
+
issuer: { type: "string", description: "identity issuer" },
|
|
416
|
+
scope: { type: "string", description: "identity scope" },
|
|
417
|
+
subject: { type: "string", description: "identity subject" },
|
|
418
|
+
contentDigest: { type: "string", description: "content digest as 64-char lowercase hex (no 0x prefix)" },
|
|
419
|
+
anchor: { type: "object", description: "optional anchor reference" },
|
|
420
|
+
other: { type: "object", description: "optional other identity for comparison" },
|
|
421
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
422
|
+
},
|
|
423
|
+
required: ["issuer", "scope", "subject", "contentDigest"],
|
|
424
|
+
},
|
|
425
|
+
outputSchema: {
|
|
426
|
+
type: "object",
|
|
427
|
+
description: "CG-ID/1 identity view with anchor facts and optional comparison.",
|
|
428
|
+
properties: {
|
|
429
|
+
identity: { type: "object" },
|
|
430
|
+
anchorFacts: { type: "object" },
|
|
431
|
+
comparison: { type: "object" },
|
|
432
|
+
callerContext: { type: "object" },
|
|
433
|
+
},
|
|
434
|
+
additionalProperties: true,
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
name: "coreguard_build_attestation",
|
|
439
|
+
description:
|
|
440
|
+
"Build a CGXA/1 offline execution attestation from a consent record and executed trace. No broadcast; no chain/network contact. nowSeconds must be pinned.",
|
|
441
|
+
inputSchema: {
|
|
442
|
+
type: "object",
|
|
443
|
+
properties: {
|
|
444
|
+
consent: { type: "object", description: "CGCR/1 consent record" },
|
|
445
|
+
executedTrace: { type: "object", description: "executed trace observed by caller" },
|
|
446
|
+
adapterId: { type: "string", description: "CGXA adapter id" },
|
|
447
|
+
nowSeconds: { description: "pinned approval epoch (unix seconds) as non-negative integer or digit string — never wall clock", oneOf: [{ type: "integer", minimum: 0 }, { type: "string", pattern: "^[0-9]+$" }] },
|
|
448
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
449
|
+
},
|
|
450
|
+
required: ["consent", "executedTrace", "adapterId", "nowSeconds"],
|
|
451
|
+
},
|
|
452
|
+
outputSchema: {
|
|
453
|
+
type: "object",
|
|
454
|
+
description: "CGXA/1 offline attestation payload with attestation record and deterministic attestationId.",
|
|
455
|
+
properties: {
|
|
456
|
+
attestation: { type: "object" },
|
|
457
|
+
attestationId: { type: "string" },
|
|
458
|
+
callerContext: { type: "object" },
|
|
459
|
+
},
|
|
460
|
+
additionalProperties: true,
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: "coreguard_verify_attestation",
|
|
465
|
+
description:
|
|
466
|
+
"Verify a CGXA/1 attestation against its consent and executed trace. Offline, fail-closed; no chain/network contact.",
|
|
467
|
+
inputSchema: {
|
|
468
|
+
type: "object",
|
|
469
|
+
properties: {
|
|
470
|
+
attestation: { type: "object", description: "CGXA/1 attestation" },
|
|
471
|
+
attestationId: { type: "string", description: "attestation identifier" },
|
|
472
|
+
consent: { type: "object", description: "CGCR/1 consent record" },
|
|
473
|
+
executedTrace: { type: "object", description: "executed trace" },
|
|
474
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
475
|
+
},
|
|
476
|
+
required: ["attestation", "attestationId", "consent", "executedTrace"],
|
|
477
|
+
},
|
|
478
|
+
outputSchema: {
|
|
479
|
+
type: "object",
|
|
480
|
+
description: "CGXA/1 attestation verification result with deterministic verdict and boundary-aware details.",
|
|
481
|
+
properties: {
|
|
482
|
+
verdict: { type: "string" },
|
|
483
|
+
callerContext: { type: "object" },
|
|
484
|
+
},
|
|
485
|
+
additionalProperties: true,
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "coreguard_decide_outcome",
|
|
490
|
+
description:
|
|
491
|
+
"Map a verification report to CG-OUT/1 outcome and authorization decision. ABSENT/NOT_CHECKED never render as BLOCK; VERIFIED ≠ SAFE.",
|
|
492
|
+
inputSchema: {
|
|
493
|
+
type: "object",
|
|
494
|
+
properties: {
|
|
495
|
+
report: { type: "object", description: "verification report or bridge-compatible report object" },
|
|
496
|
+
receiptId: { type: "string", description: "optional receipt id for profile reference" },
|
|
497
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
498
|
+
},
|
|
499
|
+
required: ["report"],
|
|
500
|
+
},
|
|
501
|
+
outputSchema: {
|
|
502
|
+
type: "object",
|
|
503
|
+
description: "CG-OUT/1 outcome, authorization decision, and optional profile reference.",
|
|
504
|
+
properties: {
|
|
505
|
+
outcome: { type: "object" },
|
|
506
|
+
decision: { type: "object" },
|
|
507
|
+
profileReference: { type: "object" },
|
|
508
|
+
callerContext: { type: "object" },
|
|
509
|
+
},
|
|
510
|
+
additionalProperties: true,
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
name: "coreguard_profile_reference",
|
|
515
|
+
description:
|
|
516
|
+
"Create or parse a CG-OUT/1 profile reference. action='make' requires receiptId; action='parse' requires reference.",
|
|
517
|
+
inputSchema: {
|
|
518
|
+
type: "object",
|
|
519
|
+
properties: {
|
|
520
|
+
action: { type: "string", enum: ["make", "parse"], description: "make or parse" },
|
|
521
|
+
receiptId: { type: "string", description: "receipt id for action=make" },
|
|
522
|
+
reference: { description: "profile reference object/string for action=parse" },
|
|
523
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
524
|
+
},
|
|
525
|
+
required: ["action"],
|
|
526
|
+
},
|
|
527
|
+
outputSchema: {
|
|
528
|
+
type: "object",
|
|
529
|
+
description: "CG-OUT/1 profile reference result for make or parse actions with explicit action echo.",
|
|
530
|
+
properties: {
|
|
531
|
+
action: { type: "string" },
|
|
532
|
+
profileReference: { type: "object" },
|
|
533
|
+
parsed: { type: "object" },
|
|
534
|
+
callerContext: { type: "object" },
|
|
535
|
+
},
|
|
536
|
+
additionalProperties: true,
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
name: "coreguard_consumption_status",
|
|
541
|
+
description:
|
|
542
|
+
"Check/consume/release a receiptId in a consumption ledger. Default is process-local (this MCP process only). If storePath is supplied (or COREGUARD_CONSUMPTION_STORE is set), uses the AC-CS/1 lock-guarded file store, which is atomic across processes on the same host. Cross-host reconciliation is CG-SPEND/1 merge; on-chain anchoring is NOT_BUILT.",
|
|
543
|
+
inputSchema: {
|
|
544
|
+
type: "object",
|
|
545
|
+
properties: {
|
|
546
|
+
receiptId: { type: "string", description: "receipt/consent identifier key" },
|
|
547
|
+
action: { type: "string", enum: ["check", "consume", "release"], description: "check, consume, or release", default: "check" },
|
|
548
|
+
storePath: { type: "string", description: "optional AC-CS/1 file-backed store path for same-host cross-process consumption (default: COREGUARD_CONSUMPTION_STORE)" },
|
|
549
|
+
...CALLER_CONTEXT_PROPERTY,
|
|
550
|
+
},
|
|
551
|
+
required: ["receiptId"],
|
|
552
|
+
},
|
|
553
|
+
outputSchema: {
|
|
554
|
+
type: "object",
|
|
555
|
+
description: "Consumption status with explicit ledger boundary.",
|
|
556
|
+
properties: {
|
|
557
|
+
receiptId: { type: "string" },
|
|
558
|
+
action: { type: "string" },
|
|
559
|
+
consumed: { type: "boolean" },
|
|
560
|
+
ledger: { type: "string", description: "process-local or file-backed (AC-CS/1, cross-process on this host)" },
|
|
561
|
+
boundary: { type: "string" },
|
|
562
|
+
callerContext: { type: "object" },
|
|
563
|
+
},
|
|
564
|
+
additionalProperties: true,
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: "coreguard_parse_x402_challenge",
|
|
569
|
+
description: "Parse and normalize an x402 payment challenge (HTTP 402 accepts). Offline deterministic validation only; no network contact, no payment execution.",
|
|
570
|
+
inputSchema: { type: "object", properties: { challenge: { type: "object", description: "x402 challenge/402 body with accepts[]" }, ...CALLER_CONTEXT_PROPERTY }, required: ["challenge"] },
|
|
571
|
+
outputSchema: { type: "object", description: "Parsed x402 challenge with normalized accepts, issues, and boundary; no network call.", properties: { verdict: { type: "string" }, issues: { type: "array" }, accepts: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: "coreguard_authorize_x402_payment",
|
|
575
|
+
description: "Evaluate an x402 challenge against a local policy and produce an authorization decision. No custody, no broadcast, no payment execution.",
|
|
576
|
+
inputSchema: { type: "object", properties: { challenge: { type: "object" }, policy: { type: "object", description: "policy: maxAmount, allowedNetworks, allowedAssets, allowedPayTo" }, selectedIndex: { type: "integer", minimum: 0 }, ...CALLER_CONTEXT_PROPERTY }, required: ["challenge", "policy"] },
|
|
577
|
+
outputSchema: { type: "object", description: "x402 authorization decision with policy issues and authorizationId; no payment executed.", properties: { verdict: { type: "string" }, authorizationId: { type: "string" }, issues: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
name: "coreguard_verify_x402_settlement",
|
|
581
|
+
description: "Verify caller-supplied x402 settlement evidence against a challenge. No network confirmation performed; evidence-only, fail-closed.",
|
|
582
|
+
inputSchema: { type: "object", properties: { challenge: { type: "object" }, settlement: { type: "object", description: "caller-supplied settlement evidence (network, asset, amount, payTo, txRef, status)" }, ...CALLER_CONTEXT_PROPERTY }, required: ["challenge", "settlement"] },
|
|
583
|
+
outputSchema: { type: "object", description: "x402 settlement verification from caller-supplied evidence; no network confirmation.", properties: { verdict: { type: "string" }, issues: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
name: "coreguard_reconcile_payment",
|
|
587
|
+
description: "Reconcile authorization, settlement evidence, and receipt. Deterministic evidence check only; no external ledger/custody.",
|
|
588
|
+
inputSchema: { type: "object", properties: { authorization: { type: "object" }, challenge: { type: "object" }, settlement: { type: "object" }, receipt: { type: "object" }, ...CALLER_CONTEXT_PROPERTY }, required: ["authorization"] },
|
|
589
|
+
outputSchema: { type: "object", description: "Payment reconciliation verdict across authorization, settlement, and receipt evidence.", properties: { verdict: { type: "string" }, issues: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
name: "coreguard_meter_agent_usage",
|
|
593
|
+
description: "Deterministically meter agent usage/cost events into an auditable total. No billing custody or external payment.",
|
|
594
|
+
inputSchema: { type: "object", properties: { agentId: { type: "string" }, events: { type: "array", items: { type: "object" } }, currency: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["agentId", "events"] },
|
|
595
|
+
outputSchema: { type: "object", description: "Deterministic agent usage metering totals and event digest; no billing custody.", properties: { totalAmount: { type: "string" }, eventCount: { type: "integer" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
name: "coreguard_register_machine",
|
|
599
|
+
description: "Create a local machine registration record from a manifest. No external device attestation/TPM trust root verification performed.",
|
|
600
|
+
inputSchema: { type: "object", properties: { machineId: { type: "string" }, manifest: { type: "object" }, owner: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["machineId", "manifest"] },
|
|
601
|
+
outputSchema: { type: "object", description: "Local machine registration record; external device attestation not performed.", properties: { verdict: { type: "string" }, registrationId: { type: "string" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
name: "coreguard_create_machine_task",
|
|
605
|
+
description: "Create a deterministic machine task record with terms/price/SLA conditions. No payment custody or physical execution guarantee.",
|
|
606
|
+
inputSchema: { type: "object", properties: { taskId: { type: "string" }, machineId: { type: "string" }, terms: { type: "object" }, ...CALLER_CONTEXT_PROPERTY }, required: ["taskId", "machineId", "terms"] },
|
|
607
|
+
outputSchema: { type: "object", description: "Deterministic machine task record with terms digest and boundary.", properties: { verdict: { type: "string" }, taskDigest: { type: "string" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: "coreguard_verify_telemetry",
|
|
611
|
+
description: "Verify caller-supplied telemetry evidence structure/digest and optionally verify Ed25519 signature when trust roots/public keys are supplied. Signature trust/physical-world truth not proven beyond supplied key material.",
|
|
612
|
+
inputSchema: { type: "object", properties: { taskId: { type: "string" }, telemetry: { type: "object" }, trust: { type: "object", description: "Optional trust roots: { publicKeyPem } or { publicKeys: [{keyId,publicKeyPem}]|{keyId:pem} } or { keyring }" }, ...CALLER_CONTEXT_PROPERTY }, required: ["taskId", "telemetry"] },
|
|
613
|
+
outputSchema: { type: "object", description: "Telemetry evidence verification result; signature trust/physical truth not proven.", properties: { verdict: { type: "string" }, issues: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
name: "coreguard_verify_task_completion",
|
|
617
|
+
description: "Verify task completion evidence against task record. Evidence acceptance is not physical-world proof; independent verification required for high-stakes actions.",
|
|
618
|
+
inputSchema: { type: "object", properties: { task: { type: "object" }, completion: { type: "object" }, telemetryVerification: { type: "object" }, ...CALLER_CONTEXT_PROPERTY }, required: ["task", "completion"] },
|
|
619
|
+
outputSchema: { type: "object", description: "Task completion evidence verification result; evidence acceptance is not physical proof.", properties: { verdict: { type: "string" }, issues: { type: "array" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
name: "coreguard_verify_delegation_chain",
|
|
623
|
+
description: "Verify delegation chain structure/continuity and optionally verify Ed25519 signatures when trust roots/public keys are supplied. Verification proves signatures over supplied payloads, not delegator identity beyond supplied key material.",
|
|
624
|
+
inputSchema: { type: "object", properties: { chain: { type: "array", items: { type: "object" } }, trust: { type: "object", description: "Optional trust roots: { publicKeyPem } or { publicKeys: [{keyId,publicKeyPem}]|{keyId:pem} } or { keyring }" }, ...CALLER_CONTEXT_PROPERTY }, required: ["chain"] },
|
|
625
|
+
outputSchema: { type: "object", description: "Delegation chain structural verification result; signatures require trusted roots.", properties: { verdict: { type: "string" }, issues: { type: "array" }, depth: { type: "integer" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
name: "coreguard_create_intent",
|
|
629
|
+
description: "CGCP/1 mapping: create an intent/approval request in a self-hosted file-backed control plane. Not a blockchain receipt and not payment execution.",
|
|
630
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, intentId: { type: "string" }, agentId: { type: "string" }, policyId: { type: "string" }, merchant: { type: "string" }, address: { type: "string" }, amountMinor: { type: "string" }, currency: { type: "string" }, requestedBy: { type: "string" }, expiresAt: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath", "agentId"] },
|
|
631
|
+
outputSchema: { type: "object", description: "CGCP/1 intent/approval request record with mapping and boundary.", properties: { type: { type: "string" }, spec: { type: "string" }, intent: { type: "object" }, mapping: { type: "string" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "coreguard_issue_receipt",
|
|
635
|
+
description: "CGCP/1 mapping: record an execution receipt in a self-hosted file-backed control plane. This is a local execution record, not an on-chain proof or external payment receipt.",
|
|
636
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, receiptId: { type: "string" }, agentId: { type: "string" }, policyId: { type: "string" }, approvalId: { type: "string" }, merchant: { type: "string" }, address: { type: "string" }, amountMinor: { type: "string" }, currency: { type: "string" }, status: { type: "string" }, txRef: { type: "string" }, metadata: { type: "object" }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath", "agentId"] },
|
|
637
|
+
outputSchema: { type: "object", description: "CGCP/1 execution receipt record with mapping and boundary.", properties: { type: { type: "string" }, spec: { type: "string" }, receipt: { type: "object" }, mapping: { type: "string" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
name: "coreguard_verify_receipt",
|
|
641
|
+
description: "CGCP/1 mapping: verify a receipt record and the audit chain in a file-backed control plane. No external anchor/witness/on-chain verification is performed.",
|
|
642
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, receiptId: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath"] },
|
|
643
|
+
outputSchema: { type: "object", description: "CGCP/1 receipt verification verdict, receipt lookup, and audit chain status.", properties: { verdict: { type: "string" }, issues: { type: "array" }, receiptFound: { type: "boolean" }, auditChain: { type: "object" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
name: "coreguard_check_limits",
|
|
647
|
+
description: "CGCP/1 mapping: evaluate policy/limit decision for an agent request in a file-backed control plane. No funds moved and no external IdP/KMS involved.",
|
|
648
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, agentId: { type: "string" }, policyId: { type: "string" }, merchant: { type: "string" }, address: { type: "string" }, amountMinor: { type: "string" }, currency: { type: "string" }, approvalId: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath", "agentId"] },
|
|
649
|
+
outputSchema: { type: "object", description: "CGCP/1 policy evaluation decision with mapping and boundary.", properties: { type: { type: "string" }, spec: { type: "string" }, decision: { type: "object" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: "coreguard_revoke_consent",
|
|
653
|
+
description: "CGCP/1 mapping: revoke an approval, agent, or policy in a file-backed control plane. Local single-host revocation; no distributed propagation, no external IdP lifecycle.",
|
|
654
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, targetType: { type: "string", enum: ["approval", "agent", "policy"] }, targetId: { type: "string" }, reason: { type: "string" }, decidedBy: { type: "string" }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath", "targetType", "targetId"] },
|
|
655
|
+
outputSchema: { type: "object", description: "CGCP/1 revocation record with mapping and boundary.", properties: { type: { type: "string" }, spec: { type: "string" }, targetType: { type: "string" }, result: { type: "object" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: "coreguard_audit_transaction",
|
|
659
|
+
description: "CGCP/1 mapping: read and optionally filter the append-only hash-chained audit report from a file-backed control plane. No external audit/audit anchoring.",
|
|
660
|
+
inputSchema: { type: "object", properties: { storePath: { type: "string" }, txRef: { type: "string" }, approvalId: { type: "string" }, agentId: { type: "string" }, limit: { type: "integer", minimum: 1 }, ...CALLER_CONTEXT_PROPERTY }, required: ["storePath"] },
|
|
661
|
+
outputSchema: { type: "object", description: "CGCP/1 audit report with chain status and optional filters.", properties: { type: { type: "string" }, spec: { type: "string" }, report: { type: "object" }, mapping: { type: "string" }, boundary: { type: "string" }, callerContext: { type: "object" } }, additionalProperties: true },
|
|
108
662
|
},
|
|
109
663
|
]);
|
|
110
664
|
|
|
665
|
+
function withCallerContext(value, args) {
|
|
666
|
+
if (!args?.callerContext || !isPlainObject(args.callerContext)) return value;
|
|
667
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return { ...value, callerContext: args.callerContext };
|
|
668
|
+
return { value, callerContext: args.callerContext };
|
|
669
|
+
}
|
|
670
|
+
|
|
111
671
|
async function callTool(name, args, { consumedSet } = {}) {
|
|
672
|
+
if (!TOOL_NAMES.includes(name)) return failure(ERROR_CODES.UNKNOWN_TOOL, `unknown tool: ${String(name)}`);
|
|
673
|
+
const a = args ?? {};
|
|
674
|
+
const problem = VALIDATORS[name]?.(a);
|
|
675
|
+
if (problem) return failure(problem.code, problem.detail);
|
|
112
676
|
try {
|
|
113
|
-
if (name === "coreguard_authorize")
|
|
114
|
-
|
|
115
|
-
|
|
677
|
+
if (name === "coreguard_authorize") return success(withCallerContext(await createConsent(a), a));
|
|
678
|
+
if (name === "coreguard_verify_consent") return success(withCallerContext(await verifyConsent(a.consent), a));
|
|
679
|
+
if (name === "coreguard_verify_execution") return success(withCallerContext(await verifyExecution(a.consent, a.trace, { consumedSet }), a));
|
|
680
|
+
if (name === "coreguard_assess_risk") {
|
|
681
|
+
return success(withCallerContext(assessRisk({ intent: a.intent, policy: a.policy, trace: a.trace, consumed: a.consumed === true }), a));
|
|
116
682
|
}
|
|
117
|
-
if (name === "
|
|
118
|
-
const
|
|
119
|
-
|
|
683
|
+
if (name === "coreguard_inspect_identity") {
|
|
684
|
+
const identity = splitIdentity({
|
|
685
|
+
issuer: a.issuer, scope: a.scope, subject: a.subject, contentDigest: a.contentDigest, anchor: a.anchor ?? null,
|
|
686
|
+
});
|
|
687
|
+
const facts = anchorFacts(identity);
|
|
688
|
+
const comparison = a.other ? compareIdentities(identity, splitIdentity(a.other)) : undefined;
|
|
689
|
+
return success(withCallerContext({ identity, anchorFacts: facts, ...(comparison ? { comparison } : {}) }, a));
|
|
120
690
|
}
|
|
121
|
-
if (name === "
|
|
122
|
-
const
|
|
123
|
-
|
|
691
|
+
if (name === "coreguard_build_attestation") {
|
|
692
|
+
const nowSeconds = typeof a.nowSeconds === "string" ? Number(a.nowSeconds) : a.nowSeconds;
|
|
693
|
+
const out = await buildAttestation({ consent: a.consent, executedTrace: a.executedTrace, adapterId: a.adapterId, nowSeconds });
|
|
694
|
+
return success(withCallerContext(out, a));
|
|
124
695
|
}
|
|
125
|
-
if (name === "
|
|
126
|
-
const
|
|
127
|
-
return
|
|
696
|
+
if (name === "coreguard_verify_attestation") {
|
|
697
|
+
const out = await verifyAttestation({ attestation: a.attestation, attestationId: a.attestationId, consent: a.consent, executedTrace: a.executedTrace });
|
|
698
|
+
return success(withCallerContext(out, a));
|
|
128
699
|
}
|
|
129
|
-
|
|
700
|
+
if (name === "coreguard_decide_outcome") {
|
|
701
|
+
const outcome = outcomeForVerificationReport(a.report);
|
|
702
|
+
const decision = authorizationDecision(outcome);
|
|
703
|
+
const profileReference = a.receiptId ? makeProfileReference({ receiptId: a.receiptId }) : undefined;
|
|
704
|
+
return success(withCallerContext({ outcome, decision, ...(profileReference ? { profileReference } : {}) }, a));
|
|
705
|
+
}
|
|
706
|
+
if (name === "coreguard_profile_reference") {
|
|
707
|
+
if (a.action === "make") return success(withCallerContext({ action: "make", profileReference: makeProfileReference({ receiptId: a.receiptId }) }, a));
|
|
708
|
+
return success(withCallerContext({ action: "parse", parsed: parseProfileReference(a.reference) }, a));
|
|
709
|
+
}
|
|
710
|
+
if (name === "coreguard_consumption_status") {
|
|
711
|
+
const action = a.action ?? "check";
|
|
712
|
+
const key = a.receiptId;
|
|
713
|
+
const storePath = a.storePath ?? DEFAULT_CONSUMPTION_STORE;
|
|
714
|
+
if (storePath) {
|
|
715
|
+
const store = createConsumptionStore(storePath);
|
|
716
|
+
let consumed;
|
|
717
|
+
if (action === "consume") { consumed = store.tryAdd(key) || store.has(key); }
|
|
718
|
+
else if (action === "release") { store.delete(key); consumed = store.has(key); }
|
|
719
|
+
else consumed = store.has(key);
|
|
720
|
+
return success(withCallerContext({
|
|
721
|
+
receiptId: key, action, consumed, ledger: "file-backed (AC-CS/1, lock-guarded across processes on this host)", boundary: CONSUMPTION_STORE_BOUNDARY,
|
|
722
|
+
}, a));
|
|
723
|
+
}
|
|
724
|
+
const set = consumedSet ?? new Set();
|
|
725
|
+
let consumed;
|
|
726
|
+
if (action === "consume") { consumed = set.has(key); set.add(key); consumed = set.has(key); }
|
|
727
|
+
else if (action === "release") { set.delete(key); consumed = set.has(key); }
|
|
728
|
+
else consumed = set.has(key);
|
|
729
|
+
return success(withCallerContext({
|
|
730
|
+
receiptId: key, action, consumed, ledger: "process-local",
|
|
731
|
+
boundary: "process-local only; set storePath or COREGUARD_CONSUMPTION_STORE for the AC-CS/1 file ledger (cross-process on this host); cross-host sync is CG-SPEND/1 merge; on-chain anchoring NOT_BUILT",
|
|
732
|
+
}, a));
|
|
733
|
+
}
|
|
734
|
+
if (name === "coreguard_parse_x402_challenge") return success(withCallerContext(parseX402Challenge(a), a));
|
|
735
|
+
if (name === "coreguard_authorize_x402_payment") return success(withCallerContext(authorizeX402Payment(a), a));
|
|
736
|
+
if (name === "coreguard_verify_x402_settlement") return success(withCallerContext(verifyX402Settlement(a), a));
|
|
737
|
+
if (name === "coreguard_reconcile_payment") return success(withCallerContext(reconcilePayment(a), a));
|
|
738
|
+
if (name === "coreguard_meter_agent_usage") return success(withCallerContext(meterAgentUsage(a), a));
|
|
739
|
+
if (name === "coreguard_register_machine") return success(withCallerContext(registerMachine(a), a));
|
|
740
|
+
if (name === "coreguard_create_machine_task") return success(withCallerContext(createMachineTask(a), a));
|
|
741
|
+
if (name === "coreguard_verify_telemetry") return success(withCallerContext(verifyTelemetry(a), a));
|
|
742
|
+
if (name === "coreguard_verify_task_completion") return success(withCallerContext(verifyTaskCompletion(a), a));
|
|
743
|
+
if (name === "coreguard_verify_delegation_chain") return success(withCallerContext(verifyDelegationChain(a), a));
|
|
744
|
+
if (name === "coreguard_create_intent") return success(withCallerContext(createIntent(a), a));
|
|
745
|
+
if (name === "coreguard_issue_receipt") return success(withCallerContext(issueReceipt(a), a));
|
|
746
|
+
if (name === "coreguard_verify_receipt") return success(withCallerContext(verifyCgcpReceipt(a), a));
|
|
747
|
+
if (name === "coreguard_check_limits") return success(withCallerContext(checkLimits(a), a));
|
|
748
|
+
if (name === "coreguard_revoke_consent") return success(withCallerContext(revokeConsent(a), a));
|
|
749
|
+
if (name === "coreguard_audit_transaction") return success(withCallerContext(auditTransaction(a), a));
|
|
750
|
+
return failure(ERROR_CODES.UNKNOWN_TOOL, `unknown tool: ${String(name)}`);
|
|
130
751
|
} catch (err) {
|
|
131
|
-
return
|
|
752
|
+
return failure(ERROR_CODES.TOOL_ERROR, err?.message ?? String(err));
|
|
132
753
|
}
|
|
133
754
|
}
|
|
134
755
|
|
|
@@ -179,7 +800,7 @@ export function createMcpHandler({ write } = {}) {
|
|
|
179
800
|
if (method === "tools/call") {
|
|
180
801
|
const name = params?.name;
|
|
181
802
|
if (!TOOL_NAMES.includes(name)) {
|
|
182
|
-
return respond({ result:
|
|
803
|
+
return respond({ result: failure(ERROR_CODES.UNKNOWN_TOOL, `unknown tool: ${String(name)}`) });
|
|
183
804
|
}
|
|
184
805
|
const result = await callTool(name, params?.arguments ?? {}, { consumedSet: consumed });
|
|
185
806
|
return respond({ result });
|
|
@@ -190,13 +811,21 @@ export function createMcpHandler({ write } = {}) {
|
|
|
190
811
|
|
|
191
812
|
export function selfCheck() {
|
|
192
813
|
return [
|
|
193
|
-
["tools exposed", TOOL_NAMES.
|
|
814
|
+
["tools exposed", TOOL_NAMES.length === 26 && TOOL_NAMES[0] === "coreguard_authorize" && TOOL_NAMES[9] === "coreguard_consumption_status" && TOOL_NAMES[19] === "coreguard_verify_delegation_chain" && TOOL_NAMES[25] === "coreguard_audit_transaction"],
|
|
194
815
|
["protocol version pinned", PROTOCOL_VERSION === "2025-06-18"],
|
|
195
816
|
["spec surfaced", CONSENT_SPEC === "CGCR/1" && AGENT_COMMERCE_VERSION === "AC-SDK/1"],
|
|
196
817
|
["boundary travels", SERVER_BOUNDARY.includes("VERIFIED ≠ SAFE") && SERVER_BOUNDARY.includes("NOT_BUILT")],
|
|
818
|
+
["version has one source", SERVER_INFO.version === PACKAGE.version],
|
|
819
|
+
["every tool declares an output schema", TOOLS.every((t) => t.outputSchema?.type === "object")],
|
|
820
|
+
["every tool declares required inputs", TOOLS.every((t) => Array.isArray(t.inputSchema?.required) && t.inputSchema.required.length > 0)],
|
|
821
|
+
["error contract is exported", ERROR_CODES.MISSING_ARGUMENT === "MISSING_ARGUMENT"],
|
|
822
|
+
["caller context supported", TOOLS.every((t) => t.inputSchema?.properties?.callerContext?.type === "object")],
|
|
823
|
+
["machine economy boundary", MACHINE_ECONOMY_BOUNDARY.includes("VERIFIED != SAFE")],
|
|
197
824
|
];
|
|
198
825
|
}
|
|
199
826
|
|
|
827
|
+
export { SERVER_INFO, PROTOCOL_VERSION, TOOLS };
|
|
828
|
+
|
|
200
829
|
export async function main() {
|
|
201
830
|
const handle = createMcpHandler();
|
|
202
831
|
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|