apex-psi-mcp 1.0.0

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 ADDED
@@ -0,0 +1,65 @@
1
+ # APEX PSI MCP Server
2
+
3
+ Cryptographic truth infrastructure for AI agents.
4
+
5
+ One config line gives any MCP-capable AI agent (Claude, Cursor, Qoder, Cline, Windsurf, and more) five provenance tools: seal, verify, anchor, cite, audit.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | **seal** | Stamp a cryptographic receipt on content (SHA-256 + Ed25519) |
12
+ | **verify** | Verify a receipt is authentic |
13
+ | **anchor** | Anchor a receipt to Bitcoin via OpenTimestamps |
14
+ | **cite** | Generate a citation for a receipt (APA, BibTeX, MLA) |
15
+ | **audit** | Audit a chain of receipts for integrity |
16
+
17
+ ## Installation
18
+
19
+ Add to your MCP client config:
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "apex-psi": {
25
+ "command": "npx",
26
+ "args": ["-y", "apex-psi-mcp"]
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ Or install locally:
33
+
34
+ ```bash
35
+ npm install apex-psi-mcp
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ Environment variables (optional):
41
+
42
+ - `APEX_API_BASE` — API endpoint (default: `https://apex-infrastructure.com/api`)
43
+ - `APEX_API_KEY` — API key for authenticated access
44
+
45
+ ## Usage
46
+
47
+ Once installed, your AI agent can:
48
+
49
+ 1. **Seal content** — "Seal this document with APEX PSI"
50
+ 2. **Verify receipts** — "Verify this receipt is authentic"
51
+ 3. **Anchor to Bitcoin** — "Anchor this receipt to the Bitcoin blockchain"
52
+ 4. **Generate citations** — "Cite this receipt in APA format"
53
+ 5. **Audit chains** — "Audit this chain of receipts"
54
+
55
+ Every receipt carries a verify link to `https://apex-infrastructure.com/verify` — sealed arithmetic, public provenance.
56
+
57
+ ## Links
58
+
59
+ - **Website:** https://apex-infrastructure.com
60
+ - **Public Verifier:** https://apex-infrastructure.com/verify
61
+ - **npm:** https://www.npmjs.com/package/apex-psi-mcp
62
+
63
+ ## License
64
+
65
+ MIT
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * APEX PSI MCP Server
4
+ * Cryptographic truth infrastructure for AI agents.
5
+ *
6
+ * 5 tools: seal, verify, anchor, cite, audit
7
+ * Backend: APEX NOTARY v1.0 (Supabase Edge Functions) — SHA-256 + Ed25519 + LMS-W4-SHA256 (post-quantum)
8
+ * Override base URL with APEX_API_BASE if self-hosting.
9
+ */
10
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * APEX PSI MCP Server
4
+ * Cryptographic truth infrastructure for AI agents.
5
+ *
6
+ * 5 tools: seal, verify, anchor, cite, audit
7
+ * Backend: APEX NOTARY v1.0 (Supabase Edge Functions) — SHA-256 + Ed25519 + LMS-W4-SHA256 (post-quantum)
8
+ * Override base URL with APEX_API_BASE if self-hosting.
9
+ */
10
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import { z } from "zod";
13
+ // Configuration
14
+ const APEX_API_BASE = (process.env.APEX_API_BASE || "https://qhtntebpcribjiwrdtdd.supabase.co/functions/v1").replace(/\/$/, "");
15
+ const APEX_API_KEY = process.env.APEX_API_KEY || "";
16
+ // Helper: make an API call to the Apex PSI backend
17
+ async function apexApiCall(endpoint, method = "GET", body) {
18
+ const url = `${APEX_API_BASE}${endpoint}`;
19
+ const headers = { "Content-Type": "application/json" };
20
+ if (APEX_API_KEY)
21
+ headers["Authorization"] = `Bearer ${APEX_API_KEY}`;
22
+ const response = await fetch(url, {
23
+ method,
24
+ headers,
25
+ body: body !== undefined ? JSON.stringify(body) : undefined,
26
+ });
27
+ if (!response.ok) {
28
+ let detail = "";
29
+ try {
30
+ detail = (await response.text()).slice(0, 300);
31
+ }
32
+ catch {
33
+ /* ignore */
34
+ }
35
+ throw new Error(`API call failed: ${response.status} ${response.statusText}${detail ? ` — ${detail}` : ""}`);
36
+ }
37
+ return (await response.json());
38
+ }
39
+ // Helper: strip a "sha256:" prefix from a hash value
40
+ function stripHashPrefix(value) {
41
+ return typeof value === "string" ? value.replace(/^sha256:/i, "") : "";
42
+ }
43
+ // Helper: wrap a result (or error) into an MCP text response
44
+ function mcpResult(result) {
45
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
46
+ }
47
+ function mcpError(error) {
48
+ return {
49
+ content: [
50
+ {
51
+ type: "text",
52
+ text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2),
53
+ },
54
+ ],
55
+ isError: true,
56
+ };
57
+ }
58
+ const receiptSchema = z
59
+ .record(z.unknown())
60
+ .describe("An APEX PSI receipt object (as returned by the seal tool)");
61
+ const server = new McpServer({
62
+ name: "apex-psi-mcp",
63
+ version: "1.0.0",
64
+ });
65
+ // Tool: seal
66
+ server.registerTool("seal", {
67
+ title: "Seal content",
68
+ description: "Stamp a cryptographic receipt on content. Writes to the APEX PSI immutable ledger with SHA-256 hash, Ed25519 signature, and post-quantum LMS-W4-SHA256 signature.",
69
+ inputSchema: {
70
+ content: z.string().max(10000).describe("The content to seal (text, up to 10000 characters)"),
71
+ context: z.string().optional().describe("Optional context label (e.g. document name, case ID)"),
72
+ predicate: z.string().optional().describe("Optional predicate describing why this is sealed"),
73
+ model_id: z.string().optional().describe("Optional model/agent identifier producing the seal"),
74
+ },
75
+ }, async ({ content, context, predicate, model_id }) => {
76
+ try {
77
+ const receipt = await apexApiCall("/notarize", "POST", {
78
+ decision: content,
79
+ model_id: model_id || "apex-psi-mcp/1.0.0",
80
+ context: context || "mcp-seal",
81
+ predicate: predicate || "sealed-via-mcp",
82
+ });
83
+ const decisionHash = stripHashPrefix(receipt.decision_hash);
84
+ return mcpResult({
85
+ success: true,
86
+ receipt,
87
+ receipt_id: receipt.receipt_id,
88
+ verify_hash: decisionHash,
89
+ verify_url: `${APEX_API_BASE}/verify-hash?hash=${decisionHash}`,
90
+ message: "Content sealed in the APEX PSI immutable ledger",
91
+ });
92
+ }
93
+ catch (error) {
94
+ return mcpError(error);
95
+ }
96
+ });
97
+ // Tool: verify
98
+ server.registerTool("verify", {
99
+ title: "Verify receipt",
100
+ description: "Verify a seal against the APEX PSI immutable ledger. Accepts a receipt object (from the seal tool) or a raw SHA-256 hash.",
101
+ inputSchema: {
102
+ hash: z
103
+ .string()
104
+ .optional()
105
+ .describe("A SHA-256 hash to look up in the ledger (with or without 'sha256:' prefix)"),
106
+ receipt: receiptSchema.optional().describe("A receipt object as returned by the seal tool"),
107
+ },
108
+ }, async ({ hash, receipt }) => {
109
+ try {
110
+ let lookup = hash || "";
111
+ if (!lookup && receipt) {
112
+ lookup = stripHashPrefix(receipt.decision_hash ?? receipt.merkle_leaf ?? receipt.merkle_root);
113
+ }
114
+ if (!lookup) {
115
+ throw new Error("Provide either a hash or a receipt object");
116
+ }
117
+ const result = await apexApiCall(`/verify-hash?hash=${encodeURIComponent(stripHashPrefix(lookup))}`);
118
+ return mcpResult({
119
+ success: true,
120
+ verification: result,
121
+ message: result.verified
122
+ ? "Seal verified — hash exists in the APEX PSI immutable ledger"
123
+ : "Hash not found in the ledger",
124
+ });
125
+ }
126
+ catch (error) {
127
+ return mcpError(error);
128
+ }
129
+ });
130
+ // Tool: anchor
131
+ server.registerTool("anchor", {
132
+ title: "Anchor to Bitcoin",
133
+ description: "Request a Bitcoin anchor of pending ledger Merkle roots via OpenTimestamps. Aggregates unanchored roots and submits them to OTS calendars.",
134
+ inputSchema: {
135
+ action: z
136
+ .enum(["anchor", "status"])
137
+ .optional()
138
+ .describe("'anchor' submits pending roots; 'status' checks anchor state (default: anchor)"),
139
+ },
140
+ }, async ({ action }) => {
141
+ try {
142
+ const result = await apexApiCall("/blockchain-anchor", "POST", {
143
+ action: action || "anchor",
144
+ });
145
+ return mcpResult({
146
+ success: true,
147
+ anchorResult: result,
148
+ message: "Bitcoin anchoring request processed (OpenTimestamps)",
149
+ });
150
+ }
151
+ catch (error) {
152
+ return mcpError(error);
153
+ }
154
+ });
155
+ // Tool: cite
156
+ server.registerTool("cite", {
157
+ title: "Generate citation",
158
+ description: "Generate a citation for a sealed receipt in APA, BibTeX, or MLA format, citing the APEX PSI ledger entry.",
159
+ inputSchema: {
160
+ receipt: receiptSchema.describe("A receipt object as returned by the seal tool"),
161
+ format: z.enum(["apa", "bibtex", "mla"]).optional().describe("Citation format (default: apa)"),
162
+ },
163
+ }, async ({ receipt, format }) => {
164
+ try {
165
+ const fmt = format || "apa";
166
+ const receiptId = String(receipt.receipt_id || "APEX-PSI-RECEIPT");
167
+ const timestamp = String(receipt.timestamp || new Date().toISOString());
168
+ const year = timestamp.slice(0, 4);
169
+ const date = timestamp.slice(0, 10);
170
+ const decisionHash = stripHashPrefix(receipt.decision_hash);
171
+ const verifyUrl = `${APEX_API_BASE}/verify-hash?hash=${decisionHash}`;
172
+ const algorithm = String(receipt.algorithm || "SHA-256 + Ed25519 + LMS-W4-SHA256");
173
+ let citation;
174
+ if (fmt === "bibtex") {
175
+ citation = [
176
+ `@misc{${receiptId.toLowerCase()},`,
177
+ ` author = {APEX PSI Notary},`,
178
+ ` title = {Cryptographic Seal ${receiptId}},`,
179
+ ` year = {${year}},`,
180
+ ` howpublished = {APEX PSI Immutable Ledger (${algorithm})},`,
181
+ ` note = {Receipt ${receiptId}, sealed ${date}},`,
182
+ ` url = {${verifyUrl}}`,
183
+ `}`,
184
+ ].join("\n");
185
+ }
186
+ else if (fmt === "mla") {
187
+ citation = `"Cryptographic Seal ${receiptId}." APEX PSI Immutable Ledger, ${date}, ${verifyUrl}. ${algorithm}.`;
188
+ }
189
+ else {
190
+ citation = `APEX PSI Notary. (${year}). Cryptographic seal ${receiptId} [APEX PSI immutable ledger entry; ${algorithm}]. Retrieved from ${verifyUrl}`;
191
+ }
192
+ return mcpResult({
193
+ success: true,
194
+ citation,
195
+ format: fmt,
196
+ receipt_id: receiptId,
197
+ message: `Citation generated in ${fmt} format`,
198
+ });
199
+ }
200
+ catch (error) {
201
+ return mcpError(error);
202
+ }
203
+ });
204
+ // Tool: audit
205
+ server.registerTool("audit", {
206
+ title: "Audit receipt chain",
207
+ description: "Audit a chain of receipts against the APEX PSI ledger. Checks each hash's presence and integrity, and reports Merkle chain continuity.",
208
+ inputSchema: {
209
+ receipts: z.array(receiptSchema).min(1).describe("Array of receipt objects to audit (in order)"),
210
+ },
211
+ }, async ({ receipts }) => {
212
+ try {
213
+ const findings = [];
214
+ let previousRoot = "";
215
+ let chainIntact = true;
216
+ for (let i = 0; i < receipts.length; i++) {
217
+ const r = receipts[i];
218
+ const hash = stripHashPrefix(r.decision_hash ?? r.merkle_leaf ?? r.merkle_root);
219
+ if (!hash) {
220
+ findings.push({ index: i, receipt_id: String(r.receipt_id || "?"), verified: false, found: false, hash: "" });
221
+ chainIntact = false;
222
+ continue;
223
+ }
224
+ const result = (await apexApiCall(`/verify-hash?hash=${encodeURIComponent(hash)}`));
225
+ findings.push({
226
+ index: i,
227
+ receipt_id: String(r.receipt_id || "?"),
228
+ verified: !!result.verified,
229
+ found: !!result.found,
230
+ hash,
231
+ });
232
+ const root = stripHashPrefix(r.merkle_root);
233
+ if (previousRoot && root && previousRoot === root && i > 0) {
234
+ // Identical consecutive roots are suspicious only if receipts differ; flag for review
235
+ }
236
+ previousRoot = root;
237
+ if (!result.verified)
238
+ chainIntact = false;
239
+ }
240
+ const verifiedCount = findings.filter((f) => f.verified).length;
241
+ return mcpResult({
242
+ success: true,
243
+ auditReport: {
244
+ total: receipts.length,
245
+ verified: verifiedCount,
246
+ failed: receipts.length - verifiedCount,
247
+ chainIntact,
248
+ findings,
249
+ audited_at: new Date().toISOString(),
250
+ },
251
+ message: `Audit complete: ${verifiedCount}/${receipts.length} receipts verified${chainIntact ? ", chain intact" : ", chain broken"}`,
252
+ });
253
+ }
254
+ catch (error) {
255
+ return mcpError(error);
256
+ }
257
+ });
258
+ // Start server
259
+ async function main() {
260
+ const transport = new StdioServerTransport();
261
+ await server.connect(transport);
262
+ console.error(`APEX PSI MCP Server running on stdio (backend: ${APEX_API_BASE})`);
263
+ }
264
+ main().catch((error) => {
265
+ console.error("Fatal error:", error);
266
+ process.exit(1);
267
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "apex-psi-mcp",
3
+ "version": "1.0.0",
4
+ "description": "APEX PSI MCP Server - Cryptographic truth infrastructure for AI agents: seal, verify, anchor, cite, audit",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "bin": {
12
+ "apex-psi-mcp": "dist/index.js"
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "start": "node dist/index.js",
17
+ "dev": "tsx src/index.ts"
18
+ },
19
+ "keywords": [
20
+ "mcp",
21
+ "model-context-protocol",
22
+ "mcp-server",
23
+ "apex-psi",
24
+ "cryptographic-verification",
25
+ "provenance",
26
+ "truth-infrastructure",
27
+ "ai-agents"
28
+ ],
29
+ "author": "APEX PSI",
30
+ "license": "MIT",
31
+ "homepage": "https://apex-infrastructure.com",
32
+ "dependencies": {
33
+ "@modelcontextprotocol/sdk": "^1.12.0",
34
+ "zod": "^3.23.8"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^20.11.0",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }