@sluzen/mcp 0.1.0 → 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.
- package/README.md +53 -2
- package/dist/bin/sluzen-mcp.js +2 -2
- package/dist/config.d.ts +30 -0
- package/dist/config.js +144 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server.js +59 -7
- package/dist/tools.d.ts +38 -3
- package/dist/tools.js +170 -2
- package/examples/paid-tool.ts +39 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,6 +6,19 @@ Wraps live Sluzen APIs and `@sluzen/sdk`. Does **not** invent rails. Private key
|
|
|
6
6
|
|
|
7
7
|
Rail contract: [`.ops/TERMS_RAIL.md`](../.ops/TERMS_RAIL.md) **§2.3** (PayChan) · **§2.4** (RLUSD). Specs: [`.ops/SPEC_PAYCHAN.md`](../.ops/SPEC_PAYCHAN.md), [`.ops/SPEC_RLUSD.md`](../.ops/SPEC_RLUSD.md).
|
|
8
8
|
|
|
9
|
+
Machine contract (OpenAPI): [`docs/openapi.yaml`](../docs/openapi.yaml) · [sluzen.network/openapi.yaml](https://sluzen.network/openapi.yaml). Human evaluate: [sluzen.network/developers](https://sluzen.network/developers#agent-loop).
|
|
10
|
+
|
|
11
|
+
## Cold orchestrator loop (Find → Trust → Pay → Prove)
|
|
12
|
+
|
|
13
|
+
Use shipped surfaces only. No consumer social graph, no ranking marketplace, no `/.well-known` agent-card (not mandated; Find is `GET /api/v1/discovery`).
|
|
14
|
+
|
|
15
|
+
1. **Discover (Find)** — `list_announced_routes` → `GET /api/v1/discovery` (SDK `listAnnouncedRoutes`). Optional density + `railFacts` (facts, not scores). Empty `routes` is valid. Sticker ≠ binding price.
|
|
16
|
+
2. **Policy (Trust)** — prefer `SLUZEN_PRINCIPAL_MANDATE` + JWKS (signed principal TTL mandate) or legacy `SLUZEN_MACHINE_POLICY` JSON. Fail-closed before sign.
|
|
17
|
+
3. **Pay** — `challenge` → `sign_payment_xrp` | `sign_payment_rlusd` | `sign_paychan_claim` → `proxy_pay` or facilitator `settle` / `authorize`. Seed stays on this host.
|
|
18
|
+
4. **Verify receipt (Prove)** — `get_call_receipt` with `SLUZEN-CALL-ID` / `callId` → `GET /api/v1/receipt`. Then `bind_task_call` to map local `taskId`/`goalId` → `callId` (process memory only). Facilitator: `delivery.recorded=false` (issuer holds body).
|
|
19
|
+
|
|
20
|
+
Hosts: API `https://api.sluzen.network`; marketing docs `https://sluzen.network`. Land `/` stays issuer-first (no endpoint catalog).
|
|
21
|
+
|
|
9
22
|
## Schemes
|
|
10
23
|
|
|
11
24
|
| Loop | Challenge | Sign (local) | Deliver to Sluzen | Latency (honest) |
|
|
@@ -29,6 +42,10 @@ Open `PaymentChannelCreate` and on-chain `PaymentChannelClaim` stay on the agent
|
|
|
29
42
|
| Tool | Role |
|
|
30
43
|
|------|------|
|
|
31
44
|
| `health` | `GET /health` |
|
|
45
|
+
| `list_announced_routes` | Find: `GET /api/v1/discovery` (density + railFacts; no seed; empty list valid) |
|
|
46
|
+
| `get_call_receipt` | Prove: `GET /api/v1/receipt?callId=` (settle→delivery join; facilitator has no Sluzen delivery) |
|
|
47
|
+
| `bind_task_call` | Local taskId/goalId ↔ callId (process memory; not a Sluzen store) |
|
|
48
|
+
| `lookup_task_call` | Lookup a prior local binding |
|
|
32
49
|
| `facilitator_supported` | `GET /facilitator/supported` |
|
|
33
50
|
| `challenge` | Proxy unpaid path or `POST /facilitator/challenge` |
|
|
34
51
|
| `sign_payment_xrp` | Local exact XRP Payment blob |
|
|
@@ -39,7 +56,7 @@ Open `PaymentChannelCreate` and on-chain `PaymentChannelClaim` stay on the agent
|
|
|
39
56
|
| `facilitator_settle` | Exact only (`use_authorize` if PayChan JSON) |
|
|
40
57
|
| `facilitator_authorize` | PayChan debit + cursor |
|
|
41
58
|
|
|
42
|
-
Fail-closed when currency is not allowlisted, PayChan params are invalid,
|
|
59
|
+
Fail-closed when currency is not allowlisted, PayChan params are invalid, local seed is missing, or `SLUZEN_MACHINE_POLICY` rejects the spend (per-call caps, PayChan cumulative, session `maxCalls` / `maxSessionDrops`).
|
|
43
60
|
|
|
44
61
|
## Env
|
|
45
62
|
|
|
@@ -48,6 +65,25 @@ Fail-closed when currency is not allowlisted, PayChan params are invalid, or loc
|
|
|
48
65
|
| `CLIENT_WALLET_SEED` | For sign tools | Local host only |
|
|
49
66
|
| `XRPL_NODE` | For exact Payment sign (autofill) | WebSocket rippled |
|
|
50
67
|
| `SLUZEN_API_BASE` | No | Default `https://api.sluzen.network` |
|
|
68
|
+
| `SLUZEN_MACHINE_POLICY` | No | JSON `MachinePolicy` (same shape as SDK). Unset = uncapped legacy. PayChan needs `maxCumulativeDrops` and/or `maxPriceDrops` (+ optional `challenge` / `deltaDrops`). Session counters live in the MCP process. |
|
|
69
|
+
| `SLUZEN_PRINCIPAL_MANDATE` | No | Compact JWS from the principal (prefers over JSON policy). Requires JWKS/public key. |
|
|
70
|
+
| `SLUZEN_MANDATE_JWKS` | With JWS | JWKS or JWK JSON for verify. |
|
|
71
|
+
| `SLUZEN_MANDATE_PUBLIC_KEY` | Alt | SPKI PEM or JWK JSON when JWKS unset. |
|
|
72
|
+
| `SLUZEN_MANDATE_REVOKED_JTIS` | No | Comma-separated `jti` denylist (orchestrator-owned revocation). |
|
|
73
|
+
|
|
74
|
+
Example mandate (host-local JSON legacy):
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"maxPriceDrops": 50000,
|
|
79
|
+
"maxCumulativeDrops": 1000000,
|
|
80
|
+
"maxSessionDrops": 500000,
|
|
81
|
+
"maxCalls": 100,
|
|
82
|
+
"requireDiscoveryListed": true
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
PayChan remains XRP-only. Channel Amount on ledger is the deposit envelope; `maxCumulativeDrops` is the agent claim ceiling. See [`docs/PRICE_AND_CAPS.md`](../docs/PRICE_AND_CAPS.md).
|
|
51
87
|
|
|
52
88
|
## Claude Desktop (stdio)
|
|
53
89
|
|
|
@@ -69,9 +105,24 @@ Fail-closed when currency is not allowlisted, PayChan params are invalid, or loc
|
|
|
69
105
|
|
|
70
106
|
Build first: `npm --prefix sluzen-mcp install && npm --prefix sluzen-mcp run build` (and `npm --prefix sluzen-sdk run build`).
|
|
71
107
|
|
|
108
|
+
Published package: `npx @sluzen/mcp` after npm publish of this version (see `.ops/NPM.md`).
|
|
109
|
+
|
|
72
110
|
## AgentKit-style example
|
|
73
111
|
|
|
74
|
-
[`examples/paid-tool.ts`](examples/paid-tool.ts)
|
|
112
|
+
[`examples/paid-tool.ts`](examples/paid-tool.ts) cold path: Find (`list_announced_routes` + `railFacts`) → Trust (mandate/policy via `createRuntimeAsync`) → Pay → Prove (`get_call_receipt` + `bind_task_call`). No EVM / multi-rail co-branding.
|
|
113
|
+
|
|
114
|
+
## Registries / default path
|
|
115
|
+
|
|
116
|
+
| Channel | Status |
|
|
117
|
+
|---------|--------|
|
|
118
|
+
| npm `@sluzen/mcp` | Publish = **HUMAN** WebAuthn (`.ops/NPM.md`). Tree version `0.1.2` (complete nerve). Prior registry may still be `0.1.0` / `0.1.1` until published. |
|
|
119
|
+
| npm `@sluzen/sdk` | Tree `2.1.0` (mandate + task bind + density types). Publish = HUMAN sync to public client repo. |
|
|
120
|
+
| MCP client config | Claude Desktop / Cursor stdio snippet above (`npx @sluzen/mcp` or local `dist/bin`). |
|
|
121
|
+
| HTTP Find | `GET https://api.sluzen.network/api/v1/discovery` |
|
|
122
|
+
| OpenAPI | `https://sluzen.network/openapi.yaml` |
|
|
123
|
+
| `/.well-known` agent-card | **CLOSED** (not mandated; AGENT_LOOP Phase 10). |
|
|
124
|
+
|
|
125
|
+
Third-party MCP directory listings (where an account is required) = HUMAN submission after npm publish.
|
|
75
126
|
|
|
76
127
|
## Develop
|
|
77
128
|
|
package/dist/bin/sluzen-mcp.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import {
|
|
3
|
+
import { createRuntimeAsync } from "../config.js";
|
|
4
4
|
import { createSluzenMcpServer } from "../server.js";
|
|
5
5
|
async function main() {
|
|
6
|
-
const runtime =
|
|
6
|
+
const runtime = await createRuntimeAsync();
|
|
7
7
|
const server = createSluzenMcpServer(runtime);
|
|
8
8
|
const transport = new StdioServerTransport();
|
|
9
9
|
await server.connect(transport);
|
package/dist/config.d.ts
CHANGED
|
@@ -1,17 +1,47 @@
|
|
|
1
|
+
import { TaskCallBindingStore, type MachinePolicy, type SpendSessionState } from "@sluzen/sdk";
|
|
1
2
|
export declare const DEFAULT_API_BASE = "https://api.sluzen.network";
|
|
2
3
|
export type McpRuntimeConfig = {
|
|
3
4
|
apiBase: string;
|
|
4
5
|
walletSeed: string;
|
|
5
6
|
xrplNode: string | undefined;
|
|
6
7
|
fetchFn: typeof fetch;
|
|
8
|
+
/** Optional Trust/Pay mandate. Absent = uncapped signing (legacy). */
|
|
9
|
+
machinePolicy: MachinePolicy | undefined;
|
|
10
|
+
/** Session counters for maxSessionDrops / maxCalls; always present. */
|
|
11
|
+
spendSession: SpendSessionState;
|
|
12
|
+
/** Local taskId/goalId ↔ callId store (process memory only). */
|
|
13
|
+
taskBindings: TaskCallBindingStore;
|
|
7
14
|
};
|
|
8
15
|
export declare function resolveApiBase(override?: string): string;
|
|
9
16
|
export declare function resolveWalletSeed(override?: string): string;
|
|
10
17
|
export declare function resolveXrplNode(override?: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Prefer signed principal mandate (`SLUZEN_PRINCIPAL_MANDATE` + key material).
|
|
20
|
+
* Falls back to legacy `SLUZEN_MACHINE_POLICY` JSON. Unset both → uncapped.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveMachinePolicyFromEnv(env?: NodeJS.ProcessEnv): Promise<MachinePolicy | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Parse optional `SLUZEN_MACHINE_POLICY` JSON into a MachinePolicy.
|
|
25
|
+
* Empty / unset → undefined (uncapped). Invalid JSON or fields → throw.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseMachinePolicyEnv(raw?: string | undefined): MachinePolicy | undefined;
|
|
11
28
|
export declare function createRuntime(options?: {
|
|
12
29
|
apiBase?: string;
|
|
13
30
|
walletSeed?: string;
|
|
14
31
|
xrplNode?: string;
|
|
15
32
|
fetchFn?: typeof fetch;
|
|
33
|
+
machinePolicy?: MachinePolicy;
|
|
34
|
+
spendSession?: SpendSessionState;
|
|
35
|
+
taskBindings?: TaskCallBindingStore;
|
|
16
36
|
}): McpRuntimeConfig;
|
|
37
|
+
/** Async entry for signed principal mandate env (Phase 7). */
|
|
38
|
+
export declare function createRuntimeAsync(options?: {
|
|
39
|
+
apiBase?: string;
|
|
40
|
+
walletSeed?: string;
|
|
41
|
+
xrplNode?: string;
|
|
42
|
+
fetchFn?: typeof fetch;
|
|
43
|
+
machinePolicy?: MachinePolicy;
|
|
44
|
+
spendSession?: SpendSessionState;
|
|
45
|
+
taskBindings?: TaskCallBindingStore;
|
|
46
|
+
}): Promise<McpRuntimeConfig>;
|
|
17
47
|
export declare function requireSeed(seed: string): string;
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createSpendSession, TaskCallBindingStore, verifyPrincipalMandate, } from "@sluzen/sdk";
|
|
1
2
|
export const DEFAULT_API_BASE = "https://api.sluzen.network";
|
|
2
3
|
export function resolveApiBase(override) {
|
|
3
4
|
const raw = override?.trim() ||
|
|
@@ -14,14 +15,157 @@ export function resolveXrplNode(override) {
|
|
|
14
15
|
const node = override?.trim() || process.env.XRPL_NODE?.trim();
|
|
15
16
|
return node && node.length > 0 ? node : undefined;
|
|
16
17
|
}
|
|
18
|
+
function asFiniteNonNegInt(value, label) {
|
|
19
|
+
if (value == null) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
23
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
24
|
+
throw new Error(`SLUZEN_MACHINE_POLICY: ${label} must be a safe non-negative integer`);
|
|
25
|
+
}
|
|
26
|
+
return n;
|
|
27
|
+
}
|
|
28
|
+
/** MCP schemes are XRPL Payment | PayChan | allowlisted RLUSD only. */
|
|
29
|
+
function asCurrencyList(value) {
|
|
30
|
+
if (value == null) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(value)) {
|
|
34
|
+
throw new Error("SLUZEN_MACHINE_POLICY: allowedCurrencies must be an array");
|
|
35
|
+
}
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const raw of value) {
|
|
38
|
+
const c = String(raw).trim().toUpperCase();
|
|
39
|
+
if (c !== "XRP" && c !== "RLUSD") {
|
|
40
|
+
throw new Error(`SLUZEN_MACHINE_POLICY: unsupported currency ${raw} (MCP: XRP|RLUSD only)`);
|
|
41
|
+
}
|
|
42
|
+
if (!out.includes(c)) {
|
|
43
|
+
out.push(c);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Prefer signed principal mandate (`SLUZEN_PRINCIPAL_MANDATE` + key material).
|
|
50
|
+
* Falls back to legacy `SLUZEN_MACHINE_POLICY` JSON. Unset both → uncapped.
|
|
51
|
+
*/
|
|
52
|
+
export async function resolveMachinePolicyFromEnv(env = process.env) {
|
|
53
|
+
const jws = env.SLUZEN_PRINCIPAL_MANDATE?.trim() ?? "";
|
|
54
|
+
if (jws.length > 0) {
|
|
55
|
+
const jwks = env.SLUZEN_MANDATE_JWKS?.trim() ||
|
|
56
|
+
env.SLUZEN_MANDATE_PUBLIC_KEY?.trim() ||
|
|
57
|
+
"";
|
|
58
|
+
if (!jwks) {
|
|
59
|
+
throw new Error("SLUZEN_PRINCIPAL_MANDATE requires SLUZEN_MANDATE_JWKS or SLUZEN_MANDATE_PUBLIC_KEY");
|
|
60
|
+
}
|
|
61
|
+
const revokedRaw = env.SLUZEN_MANDATE_REVOKED_JTIS?.trim() ?? "";
|
|
62
|
+
const revokedJtis = revokedRaw.length > 0
|
|
63
|
+
? revokedRaw.split(",").map((x) => x.trim()).filter(Boolean)
|
|
64
|
+
: undefined;
|
|
65
|
+
const verified = await verifyPrincipalMandate(jws, {
|
|
66
|
+
publicKey: jwks,
|
|
67
|
+
revokedJtis,
|
|
68
|
+
});
|
|
69
|
+
return verified.machinePolicy;
|
|
70
|
+
}
|
|
71
|
+
return parseMachinePolicyEnv(env.SLUZEN_MACHINE_POLICY);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parse optional `SLUZEN_MACHINE_POLICY` JSON into a MachinePolicy.
|
|
75
|
+
* Empty / unset → undefined (uncapped). Invalid JSON or fields → throw.
|
|
76
|
+
*/
|
|
77
|
+
export function parseMachinePolicyEnv(raw = process.env.SLUZEN_MACHINE_POLICY) {
|
|
78
|
+
const text = raw?.trim() ?? "";
|
|
79
|
+
if (text.length === 0) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
let parsed;
|
|
83
|
+
try {
|
|
84
|
+
parsed = JSON.parse(text);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error("SLUZEN_MACHINE_POLICY must be valid JSON");
|
|
88
|
+
}
|
|
89
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
90
|
+
throw new Error("SLUZEN_MACHINE_POLICY must be a JSON object");
|
|
91
|
+
}
|
|
92
|
+
const o = parsed;
|
|
93
|
+
const policy = {};
|
|
94
|
+
const maxPriceDrops = asFiniteNonNegInt(o.maxPriceDrops, "maxPriceDrops");
|
|
95
|
+
if (maxPriceDrops != null) {
|
|
96
|
+
policy.maxPriceDrops = maxPriceDrops;
|
|
97
|
+
}
|
|
98
|
+
if (o.maxPriceDropsByHost != null) {
|
|
99
|
+
if (typeof o.maxPriceDropsByHost !== "object" ||
|
|
100
|
+
Array.isArray(o.maxPriceDropsByHost)) {
|
|
101
|
+
throw new Error("SLUZEN_MACHINE_POLICY: maxPriceDropsByHost must be an object");
|
|
102
|
+
}
|
|
103
|
+
const map = {};
|
|
104
|
+
for (const [host, val] of Object.entries(o.maxPriceDropsByHost)) {
|
|
105
|
+
const n = asFiniteNonNegInt(val, `maxPriceDropsByHost.${host}`);
|
|
106
|
+
if (n != null) {
|
|
107
|
+
map[host.trim().toLowerCase()] = n;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
policy.maxPriceDropsByHost = map;
|
|
111
|
+
}
|
|
112
|
+
if (typeof o.maxIouValue === "string" && o.maxIouValue.trim().length > 0) {
|
|
113
|
+
policy.maxIouValue = o.maxIouValue.trim();
|
|
114
|
+
}
|
|
115
|
+
const allowedCurrencies = asCurrencyList(o.allowedCurrencies);
|
|
116
|
+
if (allowedCurrencies != null) {
|
|
117
|
+
policy.allowedCurrencies = allowedCurrencies;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(o.allowedNetworks)) {
|
|
120
|
+
policy.allowedNetworks = o.allowedNetworks.map((x) => String(x));
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(o.allowedDestinations)) {
|
|
123
|
+
policy.allowedDestinations = o.allowedDestinations.map((x) => String(x));
|
|
124
|
+
}
|
|
125
|
+
if (o.requireDiscoveryListed === true) {
|
|
126
|
+
policy.requireDiscoveryListed = true;
|
|
127
|
+
}
|
|
128
|
+
if (typeof o.discoveryBaseUrl === "string" && o.discoveryBaseUrl.trim()) {
|
|
129
|
+
policy.discoveryBaseUrl = o.discoveryBaseUrl.trim().replace(/\/$/, "");
|
|
130
|
+
}
|
|
131
|
+
const maxCumulativeDrops = asFiniteNonNegInt(o.maxCumulativeDrops, "maxCumulativeDrops");
|
|
132
|
+
if (maxCumulativeDrops != null) {
|
|
133
|
+
policy.maxCumulativeDrops = maxCumulativeDrops;
|
|
134
|
+
}
|
|
135
|
+
const maxSessionDrops = asFiniteNonNegInt(o.maxSessionDrops, "maxSessionDrops");
|
|
136
|
+
if (maxSessionDrops != null) {
|
|
137
|
+
policy.maxSessionDrops = maxSessionDrops;
|
|
138
|
+
}
|
|
139
|
+
const maxCalls = asFiniteNonNegInt(o.maxCalls, "maxCalls");
|
|
140
|
+
if (maxCalls != null) {
|
|
141
|
+
policy.maxCalls = maxCalls;
|
|
142
|
+
}
|
|
143
|
+
return policy;
|
|
144
|
+
}
|
|
17
145
|
export function createRuntime(options) {
|
|
146
|
+
if (options?.machinePolicy === undefined &&
|
|
147
|
+
(process.env.SLUZEN_PRINCIPAL_MANDATE?.trim() ?? "").length > 0) {
|
|
148
|
+
throw new Error("SLUZEN_PRINCIPAL_MANDATE is set: use createRuntimeAsync() (or pass machinePolicy)");
|
|
149
|
+
}
|
|
18
150
|
return {
|
|
19
151
|
apiBase: resolveApiBase(options?.apiBase),
|
|
20
152
|
walletSeed: resolveWalletSeed(options?.walletSeed),
|
|
21
153
|
xrplNode: resolveXrplNode(options?.xrplNode),
|
|
22
154
|
fetchFn: options?.fetchFn ?? fetch,
|
|
155
|
+
machinePolicy: options?.machinePolicy !== undefined
|
|
156
|
+
? options.machinePolicy
|
|
157
|
+
: parseMachinePolicyEnv(),
|
|
158
|
+
spendSession: options?.spendSession ?? createSpendSession(),
|
|
159
|
+
taskBindings: options?.taskBindings ?? new TaskCallBindingStore(),
|
|
23
160
|
};
|
|
24
161
|
}
|
|
162
|
+
/** Async entry for signed principal mandate env (Phase 7). */
|
|
163
|
+
export async function createRuntimeAsync(options) {
|
|
164
|
+
const machinePolicy = options && Object.prototype.hasOwnProperty.call(options, "machinePolicy")
|
|
165
|
+
? options.machinePolicy
|
|
166
|
+
: await resolveMachinePolicyFromEnv();
|
|
167
|
+
return createRuntime({ ...options, machinePolicy });
|
|
168
|
+
}
|
|
25
169
|
export function requireSeed(seed) {
|
|
26
170
|
if (!seed || seed.length === 0) {
|
|
27
171
|
throw new Error("CLIENT_WALLET_SEED is required on the MCP host (local only; never send seed to Sluzen)");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createRuntime, resolveApiBase, DEFAULT_API_BASE } from "./config.js";
|
|
1
|
+
export { createRuntime, createRuntimeAsync, resolveApiBase, resolveMachinePolicyFromEnv, DEFAULT_API_BASE, } from "./config.js";
|
|
2
2
|
export { createSluzenMcpServer } from "./server.js";
|
|
3
3
|
export * from "./tools.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createRuntime, resolveApiBase, DEFAULT_API_BASE } from "./config.js";
|
|
1
|
+
export { createRuntime, createRuntimeAsync, resolveApiBase, resolveMachinePolicyFromEnv, DEFAULT_API_BASE, } from "./config.js";
|
|
2
2
|
export { createSluzenMcpServer } from "./server.js";
|
|
3
3
|
export * from "./tools.js";
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createRuntime } from "./config.js";
|
|
4
|
-
import { toolChallenge, toolFacilitatorAuthorize, toolFacilitatorSettle, toolFacilitatorSupported, toolFacilitatorVerify, toolHealth, toolProxyPay, toolSignPaychanClaim, toolSignPaymentRlusd, toolSignPaymentXrp, } from "./tools.js";
|
|
4
|
+
import { toolChallenge, toolFacilitatorAuthorize, toolFacilitatorSettle, toolFacilitatorSupported, toolFacilitatorVerify, toolBindTaskCall, toolGetCallReceipt, toolHealth, toolListAnnouncedRoutes, toolLookupTaskCall, toolProxyPay, toolSignPaychanClaim, toolSignPaymentRlusd, toolSignPaymentXrp, } from "./tools.js";
|
|
5
5
|
function textResult(result) {
|
|
6
6
|
const payload = JSON.stringify(result, null, 2);
|
|
7
7
|
if (!result.ok) {
|
|
@@ -23,14 +23,46 @@ const challengeInput = z.union([z.string(), z.record(z.unknown())]);
|
|
|
23
23
|
export function createSluzenMcpServer(runtime = createRuntime()) {
|
|
24
24
|
const server = new McpServer({
|
|
25
25
|
name: "sluzen",
|
|
26
|
-
version: "0.1.
|
|
26
|
+
version: "0.1.2",
|
|
27
27
|
});
|
|
28
28
|
server.registerTool("health", {
|
|
29
29
|
description: "GET /health on the Sluzen API (rail open, network, supportsPayChan).",
|
|
30
30
|
inputSchema: {},
|
|
31
31
|
}, async () => textResult(await toolHealth(runtime)));
|
|
32
|
+
server.registerTool("list_announced_routes", {
|
|
33
|
+
description: "Find: GET /api/v1/discovery (SDK listAnnouncedRoutes). Public announced sellable proxy capabilities (url, sourceRoute, currency/network, price sticker, label, optional category). No seed. Empty routes is valid. Not a marketplace, rank, or volume claim. Binding price is still the 402 challenge.",
|
|
34
|
+
inputSchema: {},
|
|
35
|
+
}, async () => textResult(await toolListAnnouncedRoutes(runtime)));
|
|
36
|
+
server.registerTool("get_call_receipt", {
|
|
37
|
+
description: "Prove: GET /api/v1/receipt?callId= (joined settle→delivery). No admin Bearer. Facilitator: delivery.recorded=false (issuer holds body). Not a browseable index.",
|
|
38
|
+
inputSchema: {
|
|
39
|
+
callId: z
|
|
40
|
+
.string()
|
|
41
|
+
.describe("Attempt id from SLUZEN-CALL-ID / challenge.callId"),
|
|
42
|
+
},
|
|
43
|
+
}, async (args) => textResult(await toolGetCallReceipt(args, runtime)));
|
|
44
|
+
server.registerTool("bind_task_call", {
|
|
45
|
+
description: "Prove bridge: bind local taskId/goalId to callId in MCP process memory only. Does not upload to Sluzen; no durable body store. Optional resultRef stays local.",
|
|
46
|
+
inputSchema: {
|
|
47
|
+
callId: z.string().describe("Attempt id (SLUZEN-CALL-ID)"),
|
|
48
|
+
taskId: z.string().optional(),
|
|
49
|
+
goalId: z.string().optional(),
|
|
50
|
+
resultRef: z
|
|
51
|
+
.string()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("Optional local/issuer result hash or opaque ref"),
|
|
54
|
+
},
|
|
55
|
+
}, async (args) => textResult(toolBindTaskCall(args, runtime)));
|
|
56
|
+
server.registerTool("lookup_task_call", {
|
|
57
|
+
description: "Lookup a local task↔call binding previously stored with bind_task_call (process memory only).",
|
|
58
|
+
inputSchema: {
|
|
59
|
+
callId: z.string().optional(),
|
|
60
|
+
taskId: z.string().optional(),
|
|
61
|
+
goalId: z.string().optional(),
|
|
62
|
+
},
|
|
63
|
+
}, async (args) => textResult(toolLookupTaskCall(args, runtime)));
|
|
32
64
|
server.registerTool("facilitator_supported", {
|
|
33
|
-
description: "GET /facilitator/supported. Global kinds: exact XRP + paychan XRP. RLUSD is per-route only.",
|
|
65
|
+
description: "GET /facilitator/supported. Global kinds: exact XRP + paychan XRP. RLUSD is per-route only (v2 challenge/settle supported; not listed here).",
|
|
34
66
|
inputSchema: {},
|
|
35
67
|
}, async () => textResult(await toolFacilitatorSupported(runtime)));
|
|
36
68
|
server.registerTool("challenge", {
|
|
@@ -53,36 +85,56 @@ export function createSluzenMcpServer(runtime = createRuntime()) {
|
|
|
53
85
|
},
|
|
54
86
|
}, async (args) => textResult(await toolChallenge(args, runtime)));
|
|
55
87
|
server.registerTool("sign_payment_xrp", {
|
|
56
|
-
description: "Sign exact XRP Payment locally (CLIENT_WALLET_SEED on MCP host).
|
|
88
|
+
description: "Sign exact XRP Payment locally (CLIENT_WALLET_SEED on MCP host). Optional SLUZEN_MACHINE_POLICY fail-closed before sign. Requires XRPL_NODE for autofill.",
|
|
57
89
|
inputSchema: {
|
|
58
90
|
challenge: challengeInput.describe("Decoded challenge object or PAYMENT-REQUIRED base64"),
|
|
59
91
|
walletSeed: z
|
|
60
92
|
.string()
|
|
61
93
|
.optional()
|
|
62
94
|
.describe("Override seed; prefer CLIENT_WALLET_SEED env on host"),
|
|
95
|
+
requestUrl: z
|
|
96
|
+
.string()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe("URL for host caps / discovery listing proof"),
|
|
63
99
|
},
|
|
64
100
|
}, async (args) => textResult(await toolSignPaymentXrp({
|
|
65
101
|
challenge: args.challenge,
|
|
66
102
|
walletSeed: args.walletSeed,
|
|
103
|
+
requestUrl: args.requestUrl,
|
|
67
104
|
}, runtime)));
|
|
68
105
|
server.registerTool("sign_payment_rlusd", {
|
|
69
|
-
description: "Sign allowlisted RLUSD IOU Payment locally. Fail-closed if currency/issuer not allowlisted.
|
|
106
|
+
description: "Sign allowlisted RLUSD IOU Payment locally. Fail-closed if currency/issuer not allowlisted. Honors SLUZEN_MACHINE_POLICY when set.",
|
|
70
107
|
inputSchema: {
|
|
71
108
|
challenge: challengeInput,
|
|
72
109
|
walletSeed: z.string().optional(),
|
|
110
|
+
requestUrl: z.string().optional(),
|
|
73
111
|
},
|
|
74
112
|
}, async (args) => textResult(await toolSignPaymentRlusd({
|
|
75
113
|
challenge: args.challenge,
|
|
76
114
|
walletSeed: args.walletSeed,
|
|
115
|
+
requestUrl: args.requestUrl,
|
|
77
116
|
}, runtime)));
|
|
78
117
|
server.registerTool("sign_paychan_claim", {
|
|
79
|
-
description: "Sign off-chain PayChan claim locally (
|
|
118
|
+
description: "Sign off-chain PayChan claim locally (XRP-only). With SLUZEN_MACHINE_POLICY: need maxCumulativeDrops and/or maxPriceDrops (+ challenge/deltaDrops). Channel Amount is the on-ledger deposit envelope.",
|
|
80
119
|
inputSchema: {
|
|
81
120
|
channelId: z.string(),
|
|
82
121
|
cumulativeDrops: z.string(),
|
|
83
122
|
walletSeed: z.string().optional(),
|
|
123
|
+
challenge: challengeInput.optional(),
|
|
124
|
+
deltaDrops: z
|
|
125
|
+
.string()
|
|
126
|
+
.optional()
|
|
127
|
+
.describe("Per-call delta drops when no challenge.amount"),
|
|
128
|
+
requestUrl: z.string().optional(),
|
|
84
129
|
},
|
|
85
|
-
}, async (args) => textResult(toolSignPaychanClaim(
|
|
130
|
+
}, async (args) => textResult(await toolSignPaychanClaim({
|
|
131
|
+
channelId: args.channelId,
|
|
132
|
+
cumulativeDrops: args.cumulativeDrops,
|
|
133
|
+
walletSeed: args.walletSeed,
|
|
134
|
+
challenge: args.challenge,
|
|
135
|
+
deltaDrops: args.deltaDrops,
|
|
136
|
+
requestUrl: args.requestUrl,
|
|
137
|
+
}, runtime)));
|
|
86
138
|
server.registerTool("proxy_pay", {
|
|
87
139
|
description: "Retry a proxy path with PAYMENT-SIGNATURE (exact tx blob or PayChan JSON). Exact settle uses submitAndWait server-side; PayChan authorize path is off-chain claim verify.",
|
|
88
140
|
inputSchema: {
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { selectAccept, type X402Challenge } from "@sluzen/sdk";
|
|
1
|
+
import { selectAccept, type AnnouncedRoute, type CallReceipt, type TaskCallBinding, type X402Challenge } from "@sluzen/sdk";
|
|
2
2
|
import { type McpRuntimeConfig } from "./config.js";
|
|
3
3
|
export type ToolOk<T> = {
|
|
4
4
|
ok: true;
|
|
@@ -11,6 +11,13 @@ export type ToolErr = {
|
|
|
11
11
|
};
|
|
12
12
|
export type ToolResult<T> = ToolOk<T> | ToolErr;
|
|
13
13
|
export declare function toolHealth(runtime?: McpRuntimeConfig): Promise<ToolResult<unknown>>;
|
|
14
|
+
/**
|
|
15
|
+
* Find: public announced sellable proxy capabilities (no seed).
|
|
16
|
+
* Empty routes is valid. Binding price remains the 402 challenge.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toolListAnnouncedRoutes(runtime?: McpRuntimeConfig): Promise<ToolResult<{
|
|
19
|
+
routes: AnnouncedRoute[];
|
|
20
|
+
}>>;
|
|
14
21
|
export declare function toolFacilitatorSupported(runtime?: McpRuntimeConfig): Promise<ToolResult<unknown>>;
|
|
15
22
|
export declare function toolChallenge(args: {
|
|
16
23
|
surface: "proxy" | "facilitator";
|
|
@@ -28,12 +35,14 @@ export declare function toolChallenge(args: {
|
|
|
28
35
|
export declare function toolSignPaymentXrp(args: {
|
|
29
36
|
challenge: X402Challenge | string;
|
|
30
37
|
walletSeed?: string;
|
|
38
|
+
requestUrl?: string;
|
|
31
39
|
}, runtime?: McpRuntimeConfig): Promise<ToolResult<{
|
|
32
40
|
paymentSignature: string;
|
|
33
41
|
}>>;
|
|
34
42
|
export declare function toolSignPaymentRlusd(args: {
|
|
35
43
|
challenge: X402Challenge | string;
|
|
36
44
|
walletSeed?: string;
|
|
45
|
+
requestUrl?: string;
|
|
37
46
|
}, runtime?: McpRuntimeConfig): Promise<ToolResult<{
|
|
38
47
|
paymentSignature: string;
|
|
39
48
|
}>>;
|
|
@@ -41,14 +50,17 @@ export declare function toolSignPaychanClaim(args: {
|
|
|
41
50
|
channelId: string;
|
|
42
51
|
cumulativeDrops: string;
|
|
43
52
|
walletSeed?: string;
|
|
44
|
-
|
|
53
|
+
challenge?: X402Challenge | string;
|
|
54
|
+
deltaDrops?: string;
|
|
55
|
+
requestUrl?: string;
|
|
56
|
+
}, runtime?: McpRuntimeConfig): Promise<ToolResult<{
|
|
45
57
|
channelId: string;
|
|
46
58
|
claimSignature: string;
|
|
47
59
|
cumulativeDrops: string;
|
|
48
60
|
paymentSignature: string;
|
|
49
61
|
publicKey: string;
|
|
50
62
|
account: string;
|
|
51
|
-
}
|
|
63
|
+
}>>;
|
|
52
64
|
export declare function toolProxyPay(args: {
|
|
53
65
|
path: string;
|
|
54
66
|
paymentSignature: string;
|
|
@@ -77,6 +89,29 @@ export declare function toolFacilitatorAuthorize(args: {
|
|
|
77
89
|
claimSignature: string;
|
|
78
90
|
cumulativeDrops: string;
|
|
79
91
|
}, runtime?: McpRuntimeConfig): Promise<ToolResult<unknown>>;
|
|
92
|
+
/**
|
|
93
|
+
* Prove: public joined receipt for one callId (settle + delivery when recorded).
|
|
94
|
+
* Facilitator never invents a Sluzen delivery row.
|
|
95
|
+
*/
|
|
96
|
+
export declare function toolGetCallReceipt(args: {
|
|
97
|
+
callId: string;
|
|
98
|
+
}, runtime?: McpRuntimeConfig): Promise<ToolResult<CallReceipt>>;
|
|
99
|
+
/**
|
|
100
|
+
* Local Prove bridge: bind orchestrator taskId/goalId to callId in process memory.
|
|
101
|
+
* Does not call Sluzen; does not store paid bodies.
|
|
102
|
+
*/
|
|
103
|
+
export declare function toolBindTaskCall(args: {
|
|
104
|
+
callId: string;
|
|
105
|
+
taskId?: string;
|
|
106
|
+
goalId?: string;
|
|
107
|
+
resultRef?: string;
|
|
108
|
+
}, runtime?: McpRuntimeConfig): ToolResult<TaskCallBinding>;
|
|
109
|
+
/** Lookup a local task↔call binding (process memory only). */
|
|
110
|
+
export declare function toolLookupTaskCall(args: {
|
|
111
|
+
callId?: string;
|
|
112
|
+
taskId?: string;
|
|
113
|
+
goalId?: string;
|
|
114
|
+
}, runtime?: McpRuntimeConfig): ToolResult<TaskCallBinding>;
|
|
80
115
|
/** Assert accept is PayChan with usable channel params (fail-closed helper). */
|
|
81
116
|
export declare function assertPayChanParams(challenge: X402Challenge): ToolResult<{
|
|
82
117
|
channelId: string;
|
package/dist/tools.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodeChallenge, encodePayChanPaymentSignature, facilitatorAuthorize, facilitatorChallenge, facilitatorSettle, facilitatorSupported, facilitatorVerify, isAllowlistedIou, isExactAccept, isPayChanAccept, isRlusdProductCurrency, isXrpDropsCurrency, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, CALL_ID_HEADER, selectAccept, signExactPayment, signPayChanClaim, } from "@sluzen/sdk";
|
|
1
|
+
import { assertDiscoveryListed, assertMachinePolicyAllowsPayChanClaim, assertMachinePolicyAllowsSign, assertMachinePolicySessionAllows, commitSpendSession, decodeChallenge, encodePayChanPaymentSignature, facilitatorAuthorize, facilitatorChallenge, facilitatorSettle, facilitatorSupported, facilitatorVerify, getCallReceipt, isAllowlistedIou, isExactAccept, isPayChanAccept, isRlusdProductCurrency, isXrpDropsCurrency, listAnnouncedRoutes, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, CALL_ID_HEADER, selectAccept, signExactPayment, signPayChanClaim, } from "@sluzen/sdk";
|
|
2
2
|
import { createRuntime, requireSeed, } from "./config.js";
|
|
3
3
|
function fail(error, cause) {
|
|
4
4
|
return cause ? { ok: false, error, cause } : { ok: false, error };
|
|
@@ -15,6 +15,83 @@ function catchFail(err) {
|
|
|
15
15
|
}
|
|
16
16
|
return fail(String(err));
|
|
17
17
|
}
|
|
18
|
+
function policyRequestUrl(runtime, requestUrl) {
|
|
19
|
+
const override = requestUrl?.trim();
|
|
20
|
+
if (override && override.length > 0) {
|
|
21
|
+
return override;
|
|
22
|
+
}
|
|
23
|
+
return `${runtime.apiBase}/`;
|
|
24
|
+
}
|
|
25
|
+
async function enforceListingIfRequired(runtime, requestUrl) {
|
|
26
|
+
const policy = runtime.machinePolicy;
|
|
27
|
+
if (policy == null || policy.requireDiscoveryListed !== true) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const discoveryBase = policy.discoveryBaseUrl?.replace(/\/$/, "") || runtime.apiBase;
|
|
31
|
+
const routes = await listAnnouncedRoutes({
|
|
32
|
+
baseUrl: discoveryBase,
|
|
33
|
+
fetchFn: runtime.fetchFn,
|
|
34
|
+
});
|
|
35
|
+
assertDiscoveryListed({ routes, requestUrl });
|
|
36
|
+
}
|
|
37
|
+
function commitSessionDrops(runtime, addDrops) {
|
|
38
|
+
if (runtime.machinePolicy == null) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const next = commitSpendSession(runtime.spendSession, addDrops);
|
|
42
|
+
runtime.spendSession.spentDrops = next.spentDrops;
|
|
43
|
+
runtime.spendSession.callCount = next.callCount;
|
|
44
|
+
}
|
|
45
|
+
async function enforceExactSignPolicy(runtime, challenge, requestUrl) {
|
|
46
|
+
const policy = runtime.machinePolicy;
|
|
47
|
+
if (policy == null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const url = policyRequestUrl(runtime, requestUrl);
|
|
51
|
+
await enforceListingIfRequired(runtime, url);
|
|
52
|
+
assertMachinePolicyAllowsSign({
|
|
53
|
+
policy,
|
|
54
|
+
challenge,
|
|
55
|
+
requestUrl: url,
|
|
56
|
+
});
|
|
57
|
+
const addDrops = isXrpDropsCurrency(challenge.currency) ? challenge.amount : 0;
|
|
58
|
+
assertMachinePolicySessionAllows({
|
|
59
|
+
policy,
|
|
60
|
+
state: runtime.spendSession,
|
|
61
|
+
addDrops,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function enforcePayChanSignPolicy(runtime, args) {
|
|
65
|
+
const policy = runtime.machinePolicy;
|
|
66
|
+
if (policy == null) {
|
|
67
|
+
return { addDrops: 0 };
|
|
68
|
+
}
|
|
69
|
+
const url = policyRequestUrl(runtime, args.requestUrl);
|
|
70
|
+
await enforceListingIfRequired(runtime, url);
|
|
71
|
+
assertMachinePolicyAllowsPayChanClaim({
|
|
72
|
+
policy,
|
|
73
|
+
cumulativeDrops: args.cumulativeDrops,
|
|
74
|
+
deltaDrops: args.deltaDrops,
|
|
75
|
+
challenge: args.challenge,
|
|
76
|
+
requestUrl: url,
|
|
77
|
+
});
|
|
78
|
+
let addDrops = 0;
|
|
79
|
+
if (args.deltaDrops != null) {
|
|
80
|
+
addDrops = Number(args.deltaDrops);
|
|
81
|
+
}
|
|
82
|
+
else if (args.challenge != null) {
|
|
83
|
+
addDrops = args.challenge.amount;
|
|
84
|
+
}
|
|
85
|
+
if (!Number.isSafeInteger(addDrops) || addDrops < 0) {
|
|
86
|
+
addDrops = 0;
|
|
87
|
+
}
|
|
88
|
+
assertMachinePolicySessionAllows({
|
|
89
|
+
policy,
|
|
90
|
+
state: runtime.spendSession,
|
|
91
|
+
addDrops,
|
|
92
|
+
});
|
|
93
|
+
return { addDrops };
|
|
94
|
+
}
|
|
18
95
|
function parseChallengeJson(challenge) {
|
|
19
96
|
if (typeof challenge === "string") {
|
|
20
97
|
const trimmed = challenge.trim();
|
|
@@ -45,6 +122,24 @@ export async function toolHealth(runtime = createRuntime()) {
|
|
|
45
122
|
return catchFail(err);
|
|
46
123
|
}
|
|
47
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Find: public announced sellable proxy capabilities (no seed).
|
|
127
|
+
* Empty routes is valid. Binding price remains the 402 challenge.
|
|
128
|
+
*/
|
|
129
|
+
export async function toolListAnnouncedRoutes(runtime = createRuntime()) {
|
|
130
|
+
try {
|
|
131
|
+
const discoveryBase = runtime.machinePolicy?.discoveryBaseUrl?.replace(/\/$/, "") ||
|
|
132
|
+
runtime.apiBase;
|
|
133
|
+
const routes = await listAnnouncedRoutes({
|
|
134
|
+
baseUrl: discoveryBase,
|
|
135
|
+
fetchFn: runtime.fetchFn,
|
|
136
|
+
});
|
|
137
|
+
return ok({ routes });
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return catchFail(err);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
48
143
|
export async function toolFacilitatorSupported(runtime = createRuntime()) {
|
|
49
144
|
try {
|
|
50
145
|
const data = await facilitatorSupported({
|
|
@@ -120,11 +215,13 @@ export async function toolSignPaymentXrp(args, runtime = createRuntime()) {
|
|
|
120
215
|
if (!isXrpDropsCurrency(challenge.currency)) {
|
|
121
216
|
return fail(`currency ${challenge.currency} is not XRP`, "iou_not_supported");
|
|
122
217
|
}
|
|
218
|
+
await enforceExactSignPolicy(runtime, challenge, args.requestUrl);
|
|
123
219
|
const paymentSignature = await signExactPayment({
|
|
124
220
|
challenge,
|
|
125
221
|
walletSeed: seed,
|
|
126
222
|
node: runtime.xrplNode,
|
|
127
223
|
});
|
|
224
|
+
commitSessionDrops(runtime, challenge.amount);
|
|
128
225
|
return ok({ paymentSignature });
|
|
129
226
|
}
|
|
130
227
|
catch (err) {
|
|
@@ -149,30 +246,40 @@ export async function toolSignPaymentRlusd(args, runtime = createRuntime()) {
|
|
|
149
246
|
})) {
|
|
150
247
|
return fail("IOU issuer/currency not on Sluzen allowlist", "iou_not_supported");
|
|
151
248
|
}
|
|
249
|
+
await enforceExactSignPolicy(runtime, challenge, args.requestUrl);
|
|
152
250
|
const paymentSignature = await signExactPayment({
|
|
153
251
|
challenge,
|
|
154
252
|
walletSeed: seed,
|
|
155
253
|
node: runtime.xrplNode,
|
|
156
254
|
});
|
|
255
|
+
commitSessionDrops(runtime, 0);
|
|
157
256
|
return ok({ paymentSignature });
|
|
158
257
|
}
|
|
159
258
|
catch (err) {
|
|
160
259
|
return catchFail(err);
|
|
161
260
|
}
|
|
162
261
|
}
|
|
163
|
-
export function toolSignPaychanClaim(args, runtime = createRuntime()) {
|
|
262
|
+
export async function toolSignPaychanClaim(args, runtime = createRuntime()) {
|
|
164
263
|
try {
|
|
165
264
|
const seed = requireSeed(args.walletSeed ?? runtime.walletSeed);
|
|
166
265
|
const channelId = args.channelId.trim().toUpperCase();
|
|
167
266
|
if (!/^[0-9A-F]{64}$/.test(channelId)) {
|
|
168
267
|
return fail("channelId must be 64 hex characters", "invalid_channel_id");
|
|
169
268
|
}
|
|
269
|
+
const challenge = args.challenge != null ? parseChallengeJson(args.challenge) : undefined;
|
|
270
|
+
const { addDrops } = await enforcePayChanSignPolicy(runtime, {
|
|
271
|
+
cumulativeDrops: args.cumulativeDrops,
|
|
272
|
+
deltaDrops: args.deltaDrops,
|
|
273
|
+
challenge,
|
|
274
|
+
requestUrl: args.requestUrl,
|
|
275
|
+
});
|
|
170
276
|
const claim = signPayChanClaim({
|
|
171
277
|
channelId,
|
|
172
278
|
cumulativeDrops: args.cumulativeDrops,
|
|
173
279
|
walletSeed: seed,
|
|
174
280
|
});
|
|
175
281
|
const paymentSignature = encodePayChanPaymentSignature(claim);
|
|
282
|
+
commitSessionDrops(runtime, addDrops);
|
|
176
283
|
return ok({
|
|
177
284
|
channelId: claim.channelId,
|
|
178
285
|
claimSignature: claim.claimSignature,
|
|
@@ -319,6 +426,67 @@ export async function toolFacilitatorAuthorize(args, runtime = createRuntime())
|
|
|
319
426
|
return catchFail(err);
|
|
320
427
|
}
|
|
321
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Prove: public joined receipt for one callId (settle + delivery when recorded).
|
|
431
|
+
* Facilitator never invents a Sluzen delivery row.
|
|
432
|
+
*/
|
|
433
|
+
export async function toolGetCallReceipt(args, runtime = createRuntime()) {
|
|
434
|
+
try {
|
|
435
|
+
const callId = args.callId?.trim();
|
|
436
|
+
if (!callId) {
|
|
437
|
+
return fail("callId is required", "invalid_call_id");
|
|
438
|
+
}
|
|
439
|
+
const receipt = await getCallReceipt({
|
|
440
|
+
baseUrl: runtime.apiBase,
|
|
441
|
+
callId,
|
|
442
|
+
fetchFn: runtime.fetchFn,
|
|
443
|
+
});
|
|
444
|
+
return ok(receipt);
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
return catchFail(err);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Local Prove bridge: bind orchestrator taskId/goalId to callId in process memory.
|
|
452
|
+
* Does not call Sluzen; does not store paid bodies.
|
|
453
|
+
*/
|
|
454
|
+
export function toolBindTaskCall(args, runtime = createRuntime()) {
|
|
455
|
+
try {
|
|
456
|
+
const binding = runtime.taskBindings.bind({
|
|
457
|
+
callId: args.callId,
|
|
458
|
+
taskId: args.taskId,
|
|
459
|
+
goalId: args.goalId,
|
|
460
|
+
resultRef: args.resultRef,
|
|
461
|
+
});
|
|
462
|
+
return ok(binding);
|
|
463
|
+
}
|
|
464
|
+
catch (err) {
|
|
465
|
+
return catchFail(err);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/** Lookup a local task↔call binding (process memory only). */
|
|
469
|
+
export function toolLookupTaskCall(args, runtime = createRuntime()) {
|
|
470
|
+
try {
|
|
471
|
+
const callId = args.callId?.trim();
|
|
472
|
+
const taskId = args.taskId?.trim();
|
|
473
|
+
const goalId = args.goalId?.trim();
|
|
474
|
+
const binding = callId
|
|
475
|
+
? runtime.taskBindings.getByCallId(callId)
|
|
476
|
+
: taskId
|
|
477
|
+
? runtime.taskBindings.getByTaskId(taskId)
|
|
478
|
+
: goalId
|
|
479
|
+
? runtime.taskBindings.getByGoalId(goalId)
|
|
480
|
+
: undefined;
|
|
481
|
+
if (!binding) {
|
|
482
|
+
return fail("binding not found", "not_found");
|
|
483
|
+
}
|
|
484
|
+
return ok(binding);
|
|
485
|
+
}
|
|
486
|
+
catch (err) {
|
|
487
|
+
return catchFail(err);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
322
490
|
/** Assert accept is PayChan with usable channel params (fail-closed helper). */
|
|
323
491
|
export function assertPayChanParams(challenge) {
|
|
324
492
|
try {
|
package/examples/paid-tool.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Pre-armed cold orchestrator loop over live Sluzen rails
|
|
3
|
+
* (AGENT_LOOP complete nerve: Find → Trust → Pay → Prove).
|
|
3
4
|
*
|
|
4
5
|
* HTTP 402 schemes on XRPL (Payment | PayChan | allowlisted RLUSD).
|
|
5
6
|
* Contract: TERMS_RAIL §2.3 (PayChan) · §2.4 (RLUSD) — see ../../.ops/TERMS_RAIL.md
|
|
@@ -7,13 +8,17 @@
|
|
|
7
8
|
* Run (after npm run build in sluzen-mcp):
|
|
8
9
|
* CLIENT_WALLET_SEED=... XRPL_NODE=wss://... npx tsx examples/paid-tool.ts /api/v1/investor-demo
|
|
9
10
|
*
|
|
11
|
+
* Optional Trust: SLUZEN_PRINCIPAL_MANDATE + SLUZEN_MANDATE_JWKS (or SLUZEN_MACHINE_POLICY).
|
|
10
12
|
* No custody on Sluzen. Seed stays on this host. No MoR / refund / dispute.
|
|
11
13
|
*/
|
|
12
14
|
import {
|
|
13
|
-
|
|
15
|
+
createRuntimeAsync,
|
|
16
|
+
toolBindTaskCall,
|
|
14
17
|
toolChallenge,
|
|
15
18
|
toolFacilitatorAuthorize,
|
|
16
19
|
toolFacilitatorSettle,
|
|
20
|
+
toolGetCallReceipt,
|
|
21
|
+
toolListAnnouncedRoutes,
|
|
17
22
|
toolProxyPay,
|
|
18
23
|
toolSignPaychanClaim,
|
|
19
24
|
toolSignPaymentRlusd,
|
|
@@ -22,7 +27,16 @@ import {
|
|
|
22
27
|
import { isExactAccept, isPayChanAccept, selectAccept } from "@sluzen/sdk";
|
|
23
28
|
|
|
24
29
|
async function paidProxyCall(path: string): Promise<unknown> {
|
|
25
|
-
const runtime =
|
|
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
|
+
}
|
|
26
40
|
const challenged = await toolChallenge({ surface: "proxy", path }, runtime);
|
|
27
41
|
if (!challenged.ok) {
|
|
28
42
|
throw new Error(challenged.error);
|
|
@@ -97,7 +111,7 @@ async function paidProxyCall(path: string): Promise<unknown> {
|
|
|
97
111
|
|
|
98
112
|
/** Facilitator surface: settle (exact) or authorize (PayChan). */
|
|
99
113
|
async function paidFacilitatorCall(resource: string): Promise<unknown> {
|
|
100
|
-
const runtime =
|
|
114
|
+
const runtime = await createRuntimeAsync();
|
|
101
115
|
const challenged = await toolChallenge(
|
|
102
116
|
{ surface: "facilitator", resource },
|
|
103
117
|
runtime,
|
|
@@ -155,12 +169,33 @@ async function paidFacilitatorCall(resource: string): Promise<unknown> {
|
|
|
155
169
|
|
|
156
170
|
async function main(): Promise<void> {
|
|
157
171
|
const path = process.argv[2] ?? "/api/v1/investor-demo";
|
|
172
|
+
const taskId = process.env.SLUZEN_TASK_ID?.trim() || `task-${Date.now()}`;
|
|
158
173
|
if (path.startsWith("https://")) {
|
|
159
174
|
const result = await paidFacilitatorCall(path);
|
|
160
175
|
console.log(JSON.stringify(result, null, 2));
|
|
161
176
|
return;
|
|
162
177
|
}
|
|
178
|
+
const runtime = await createRuntimeAsync();
|
|
163
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
|
+
}
|
|
164
199
|
console.log(JSON.stringify(result, null, 2));
|
|
165
200
|
}
|
|
166
201
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sluzen/mcp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Sluzen MCP server:
|
|
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
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
32
|
-
"@sluzen/sdk": "^1.
|
|
32
|
+
"@sluzen/sdk": "^2.1.0",
|
|
33
33
|
"zod": "^3.25.76"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|