@sluzen/mcp 0.0.0-stage → 0.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.
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Pre-armed cold orchestrator loop over live Sluzen rails
3
+ * (AGENT_LOOP complete nerve: Find → Trust → Pay → Prove).
4
+ *
5
+ * HTTP 402 schemes on XRPL (Payment | PayChan | allowlisted RLUSD).
6
+ * Contract: TERMS_RAIL §2.3 (PayChan) · §2.4 (RLUSD) — see ../../.ops/TERMS_RAIL.md
7
+ *
8
+ * Run (after npm run build in sluzen-mcp):
9
+ * CLIENT_WALLET_SEED=... XRPL_NODE=wss://... npx tsx examples/paid-tool.ts /api/v1/investor-demo
10
+ *
11
+ * Optional Trust: SLUZEN_PRINCIPAL_MANDATE + SLUZEN_MANDATE_JWKS (or SLUZEN_MACHINE_POLICY).
12
+ * No custody on Sluzen. Seed stays on this host. No MoR / refund / dispute.
13
+ */
14
+ import {
15
+ createRuntimeAsync,
16
+ toolBindTaskCall,
17
+ toolChallenge,
18
+ toolFacilitatorAuthorize,
19
+ toolFacilitatorSettle,
20
+ toolGetCallReceipt,
21
+ toolListAnnouncedRoutes,
22
+ toolProxyPay,
23
+ toolSignPaychanClaim,
24
+ toolSignPaymentRlusd,
25
+ toolSignPaymentXrp,
26
+ } from "../src/index.js";
27
+ import { isExactAccept, isPayChanAccept, selectAccept } from "@sluzen/sdk";
28
+
29
+ async function paidProxyCall(path: string): Promise<unknown> {
30
+ const runtime = await createRuntimeAsync();
31
+ const found = await toolListAnnouncedRoutes(runtime);
32
+ if (found.ok) {
33
+ const row = found.data.routes.find((r) => r.sourceRoute === path);
34
+ if (row?.railFacts) {
35
+ console.error(
36
+ JSON.stringify({ find: row.sourceRoute, railFacts: row.railFacts }),
37
+ );
38
+ }
39
+ }
40
+ const challenged = await toolChallenge({ surface: "proxy", path }, runtime);
41
+ if (!challenged.ok) {
42
+ throw new Error(challenged.error);
43
+ }
44
+
45
+ const { challenge, accept } = challenged.data;
46
+ const scheme = selectAccept(challenge);
47
+
48
+ if (isPayChanAccept(scheme) || isPayChanAccept(accept)) {
49
+ // Loop B: open channel on agent host first; then N signed claims.
50
+ const channelId = accept.scheme === "paychan" ? accept.extra.channelId : undefined;
51
+ if (!channelId) {
52
+ throw new Error(
53
+ "PayChan challenge missing channelId (open PaymentChannelCreate on agent host)",
54
+ );
55
+ }
56
+ const prev =
57
+ accept.scheme === "paychan"
58
+ ? BigInt(accept.extra.prevAcceptedCumulative ?? "0")
59
+ : 0n;
60
+ const step = BigInt(
61
+ accept.scheme === "paychan" ? accept.maxAmountRequired : "0",
62
+ );
63
+ const cumulativeDrops = (prev + step).toString();
64
+ const signed = toolSignPaychanClaim(
65
+ { channelId, cumulativeDrops },
66
+ runtime,
67
+ );
68
+ if (!signed.ok) {
69
+ throw new Error(signed.error);
70
+ }
71
+ const paid = await toolProxyPay(
72
+ { path, paymentSignature: signed.data.paymentSignature },
73
+ runtime,
74
+ );
75
+ if (!paid.ok) {
76
+ throw new Error(paid.error);
77
+ }
78
+ return paid.data;
79
+ }
80
+
81
+ if (isExactAccept(scheme) && scheme.asset === "RLUSD") {
82
+ // Loop C: allowlisted RLUSD IOU Payment (ledger submitAndWait).
83
+ const signed = await toolSignPaymentRlusd({ challenge }, runtime);
84
+ if (!signed.ok) {
85
+ throw new Error(signed.error);
86
+ }
87
+ const paid = await toolProxyPay(
88
+ { path, paymentSignature: signed.data.paymentSignature },
89
+ runtime,
90
+ );
91
+ if (!paid.ok) {
92
+ throw new Error(paid.error);
93
+ }
94
+ return paid.data;
95
+ }
96
+
97
+ // Loop A: exact XRP Payment per call (ledger submitAndWait).
98
+ const signed = await toolSignPaymentXrp({ challenge }, runtime);
99
+ if (!signed.ok) {
100
+ throw new Error(signed.error);
101
+ }
102
+ const paid = await toolProxyPay(
103
+ { path, paymentSignature: signed.data.paymentSignature },
104
+ runtime,
105
+ );
106
+ if (!paid.ok) {
107
+ throw new Error(paid.error);
108
+ }
109
+ return paid.data;
110
+ }
111
+
112
+ /** Facilitator surface: settle (exact) or authorize (PayChan). */
113
+ async function paidFacilitatorCall(resource: string): Promise<unknown> {
114
+ const runtime = await createRuntimeAsync();
115
+ const challenged = await toolChallenge(
116
+ { surface: "facilitator", resource },
117
+ runtime,
118
+ );
119
+ if (!challenged.ok) {
120
+ throw new Error(challenged.error);
121
+ }
122
+ const { challenge, accept } = challenged.data;
123
+
124
+ if (isPayChanAccept(accept)) {
125
+ const channelId = accept.extra.channelId;
126
+ if (!channelId) {
127
+ throw new Error("PayChan challenge missing channelId");
128
+ }
129
+ const prev = BigInt(accept.extra.prevAcceptedCumulative ?? "0");
130
+ const cumulativeDrops = (prev + BigInt(accept.maxAmountRequired)).toString();
131
+ const signed = toolSignPaychanClaim(
132
+ { channelId, cumulativeDrops },
133
+ runtime,
134
+ );
135
+ if (!signed.ok) {
136
+ throw new Error(signed.error);
137
+ }
138
+ return toolFacilitatorAuthorize(
139
+ {
140
+ resource,
141
+ channelId: signed.data.channelId,
142
+ claimSignature: signed.data.claimSignature,
143
+ cumulativeDrops: signed.data.cumulativeDrops,
144
+ },
145
+ runtime,
146
+ );
147
+ }
148
+
149
+ if (isExactAccept(accept) && accept.asset === "RLUSD") {
150
+ const signed = await toolSignPaymentRlusd({ challenge }, runtime);
151
+ if (!signed.ok) {
152
+ throw new Error(signed.error);
153
+ }
154
+ return toolFacilitatorSettle(
155
+ { resource, paymentSignature: signed.data.paymentSignature },
156
+ runtime,
157
+ );
158
+ }
159
+
160
+ const signed = await toolSignPaymentXrp({ challenge }, runtime);
161
+ if (!signed.ok) {
162
+ throw new Error(signed.error);
163
+ }
164
+ return toolFacilitatorSettle(
165
+ { resource, paymentSignature: signed.data.paymentSignature },
166
+ runtime,
167
+ );
168
+ }
169
+
170
+ async function main(): Promise<void> {
171
+ const path = process.argv[2] ?? "/api/v1/investor-demo";
172
+ const taskId = process.env.SLUZEN_TASK_ID?.trim() || `task-${Date.now()}`;
173
+ if (path.startsWith("https://")) {
174
+ const result = await paidFacilitatorCall(path);
175
+ console.log(JSON.stringify(result, null, 2));
176
+ return;
177
+ }
178
+ const runtime = await createRuntimeAsync();
179
+ const result = await paidProxyCall(path);
180
+ const callId =
181
+ result &&
182
+ typeof result === "object" &&
183
+ "callId" in result &&
184
+ typeof (result as { callId?: unknown }).callId === "string"
185
+ ? (result as { callId: string }).callId
186
+ : undefined;
187
+ if (callId) {
188
+ const receipt = await toolGetCallReceipt({ callId }, runtime);
189
+ const binding = toolBindTaskCall({ callId, taskId }, runtime);
190
+ console.log(
191
+ JSON.stringify(
192
+ { pay: result, prove: receipt, taskBinding: binding },
193
+ null,
194
+ 2,
195
+ ),
196
+ );
197
+ return;
198
+ }
199
+ console.log(JSON.stringify(result, null, 2));
200
+ }
201
+
202
+ main().catch((err) => {
203
+ console.error(err instanceof Error ? err.message : String(err));
204
+ process.exit(1);
205
+ });
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@sluzen/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "Sluzen MCP server: Find (density+railFacts) / Trust (principal mandate) / Pay / Prove (receipt+task bind) over HTTP 402 on XRPL. Local seed only.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "sluzen-mcp": "dist/bin/sluzen-mcp.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "examples"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "start": "node dist/bin/sluzen-mcp.js",
19
+ "test": "vitest run",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "engines": {
23
+ "node": ">=20"
24
+ },
25
+ "author": "Vectis",
26
+ "license": "ISC",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "@modelcontextprotocol/sdk": "^1.32.1",
32
+ "@sluzen/sdk": "^2.1.0",
33
+ "zod": "^3.25.76"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.15.0",
37
+ "typescript": "^6.0.3",
38
+ "vitest": "^4.1.9"
39
+ }
40
+ }