apex-psi-mcp 1.1.1 → 1.1.2
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/dist/index.js +58 -14
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -19,7 +19,10 @@ import { z } from "zod";
|
|
|
19
19
|
// Configuration
|
|
20
20
|
const APEX_API_BASE = (process.env.APEX_API_BASE || "https://qhtntebpcribjiwrdtdd.supabase.co/functions/v1").replace(/\/$/, "");
|
|
21
21
|
const APEX_API_KEY = process.env.APEX_API_KEY || "";
|
|
22
|
-
|
|
22
|
+
// Human-facing site. The API host is a Supabase function and is not a page a
|
|
23
|
+
// person can open, so every link handed back to a user points here instead.
|
|
24
|
+
const APEX_SITE_BASE = (process.env.APEX_SITE_BASE || "https://www.ai-governance-standard.com").replace(/\/$/, "");
|
|
25
|
+
const VERSION = "1.1.2";
|
|
23
26
|
// Helper: make an API call to the Apex PSI backend
|
|
24
27
|
async function apexApiCall(endpoint, method = "GET", body) {
|
|
25
28
|
const url = `${APEX_API_BASE}${endpoint}`;
|
|
@@ -47,6 +50,36 @@ async function apexApiCall(endpoint, method = "GET", body) {
|
|
|
47
50
|
function stripHashPrefix(value) {
|
|
48
51
|
return typeof value === "string" ? value.replace(/^sha256:/i, "") : "";
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Accept either a bare receipt or the whole envelope `seal` returns
|
|
55
|
+
* (`{ success, receipt, verify_hash, ... }`). The readers below once assumed a
|
|
56
|
+
* flat receipt, which meant a genuine seal piped straight back into verify,
|
|
57
|
+
* cite or verify_chain reported "chain broken" with an empty hash.
|
|
58
|
+
*/
|
|
59
|
+
function asReceipt(value) {
|
|
60
|
+
if (!value || typeof value !== "object")
|
|
61
|
+
return {};
|
|
62
|
+
const obj = value;
|
|
63
|
+
const nested = obj.receipt;
|
|
64
|
+
if (obj.decision_hash === undefined && nested && typeof nested === "object" && !Array.isArray(nested)) {
|
|
65
|
+
return nested;
|
|
66
|
+
}
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
// Helper: the hash a receipt stands for, from any of the fields the ledger uses
|
|
70
|
+
function receiptHash(value) {
|
|
71
|
+
const r = asReceipt(value);
|
|
72
|
+
const raw = r.decision_hash ?? r.merkle_leaf ?? r.merkle_root ?? r.verify_hash ?? r.hash;
|
|
73
|
+
const hash = stripHashPrefix(raw);
|
|
74
|
+
if (!hash) {
|
|
75
|
+
throw new Error("This receipt carries no hash (looked for decision_hash, merkle_leaf, merkle_root) — pass the object exactly as the seal tool returned it");
|
|
76
|
+
}
|
|
77
|
+
return hash;
|
|
78
|
+
}
|
|
79
|
+
// Helper: a link a person can open in a browser
|
|
80
|
+
function verifyPageUrl(hash) {
|
|
81
|
+
return `${APEX_SITE_BASE}/verify?hash=${encodeURIComponent(hash)}`;
|
|
82
|
+
}
|
|
50
83
|
// Helper: wrap a result (or error) into an MCP text response
|
|
51
84
|
function mcpResult(result) {
|
|
52
85
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
@@ -93,7 +126,8 @@ server.registerTool("seal", {
|
|
|
93
126
|
receipt,
|
|
94
127
|
receipt_id: receipt.receipt_id,
|
|
95
128
|
verify_hash: decisionHash,
|
|
96
|
-
verify_url:
|
|
129
|
+
verify_url: verifyPageUrl(decisionHash),
|
|
130
|
+
verify_api_url: `${APEX_API_BASE}/verify-hash?hash=${decisionHash}`,
|
|
97
131
|
message: "Content sealed in the APEX PSI append-only ledger",
|
|
98
132
|
});
|
|
99
133
|
}
|
|
@@ -114,17 +148,19 @@ server.registerTool("verify", {
|
|
|
114
148
|
},
|
|
115
149
|
}, async ({ hash, receipt }) => {
|
|
116
150
|
try {
|
|
117
|
-
let lookup = hash
|
|
118
|
-
if (!lookup && receipt) {
|
|
119
|
-
lookup =
|
|
151
|
+
let lookup = stripHashPrefix(hash);
|
|
152
|
+
if (!lookup && receipt !== undefined) {
|
|
153
|
+
lookup = receiptHash(receipt);
|
|
120
154
|
}
|
|
121
155
|
if (!lookup) {
|
|
122
156
|
throw new Error("Provide either a hash or a receipt object");
|
|
123
157
|
}
|
|
124
|
-
const result = await apexApiCall(`/verify-hash?hash=${encodeURIComponent(
|
|
158
|
+
const result = await apexApiCall(`/verify-hash?hash=${encodeURIComponent(lookup)}`);
|
|
125
159
|
return mcpResult({
|
|
126
160
|
success: true,
|
|
161
|
+
hash: lookup,
|
|
127
162
|
verification: result,
|
|
163
|
+
verify_url: verifyPageUrl(lookup),
|
|
128
164
|
message: result.verified
|
|
129
165
|
? "Seal verified — hash is present in the APEX PSI append-only ledger"
|
|
130
166
|
: "Hash not found in the ledger",
|
|
@@ -184,13 +220,18 @@ server.registerTool("cite", {
|
|
|
184
220
|
}, async ({ receipt, format }) => {
|
|
185
221
|
try {
|
|
186
222
|
const fmt = format || "apa";
|
|
187
|
-
const
|
|
188
|
-
const
|
|
223
|
+
const r = asReceipt(receipt);
|
|
224
|
+
const receiptId = String(r.receipt_id || "APEX-PSI-RECEIPT");
|
|
225
|
+
const timestamp = String(r.timestamp || new Date().toISOString());
|
|
189
226
|
const year = timestamp.slice(0, 4);
|
|
190
227
|
const date = timestamp.slice(0, 10);
|
|
191
|
-
const decisionHash =
|
|
192
|
-
const verifyUrl =
|
|
193
|
-
|
|
228
|
+
const decisionHash = receiptHash(receipt);
|
|
229
|
+
const verifyUrl = verifyPageUrl(decisionHash);
|
|
230
|
+
// Only name algorithms the receipt itself names. The ledger attaches
|
|
231
|
+
// LMS-W4-SHA256 only when a slot is available, so a hard-coded default
|
|
232
|
+
// would cite signatures this particular receipt does not carry.
|
|
233
|
+
const stated = typeof r.algorithm === "string" ? r.algorithm.trim() : "";
|
|
234
|
+
const algorithm = stated || "algorithms not stated in this receipt";
|
|
194
235
|
let citation;
|
|
195
236
|
if (fmt === "bibtex") {
|
|
196
237
|
citation = [
|
|
@@ -235,9 +276,12 @@ server.registerTool("verify_chain", {
|
|
|
235
276
|
let previousRoot = "";
|
|
236
277
|
let chainIntact = true;
|
|
237
278
|
for (let i = 0; i < receipts.length; i++) {
|
|
238
|
-
const r = receipts[i];
|
|
239
|
-
|
|
240
|
-
|
|
279
|
+
const r = asReceipt(receipts[i]);
|
|
280
|
+
let hash = "";
|
|
281
|
+
try {
|
|
282
|
+
hash = receiptHash(r);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
241
285
|
results.push({ index: i, receipt_id: String(r.receipt_id || "?"), verified: false, found: false, hash: "" });
|
|
242
286
|
chainIntact = false;
|
|
243
287
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apex-psi-mcp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"mcpName": "io.github.kawal393/apex-psi-mcp",
|
|
5
5
|
"description": "APEX PSI MCP server - append-only evidence receipts for AI decisions and documents: seal a record, verify a hash against the public ledger, check a chain, cite a receipt, read Bitcoin anchoring status. Verification is free and needs no account.",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"start": "node dist/index.js",
|
|
18
|
-
"dev": "tsx src/index.ts"
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"check:roundtrip": "node scripts/roundtrip-check.mjs",
|
|
20
|
+
"check:all": "npm run build && node scripts/roundtrip-check.mjs && node scripts/anchor-tool-check.mjs && node scripts/card-copy-check.mjs"
|
|
19
21
|
},
|
|
20
22
|
"keywords": [
|
|
21
23
|
"mcp",
|