@esseyonsui/sui-mcp-v3 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
1
+ # @esseyonsui/sui-mcp-v3
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A private Model Context Protocol server over `@esseyonsui/sui-sdk-v3` for the Essey V3 testnet demo. Stdio
4
+ transport. Testnet only.
5
+
6
+ ## Quick start
7
+
8
+ ```sh
9
+ npx -y -p @esseyonsui/sui-mcp-v3 essey-sui-mcp-v3-init ~/.essey-v3
10
+ ```
11
+
12
+ That writes a mode-600 note key and agent key into `~/.essey-v3` (it never overwrites one) and prints the
13
+ `mcpServers` entry to paste into your MCP client. Give each agent its own directory. Then ask the agent to obtain
14
+ a credential, take faucet notes, and open or fund a loan. Node 22.13 or later.
15
+
16
+ The chain io the server uses is also exported for SDK callers: `import { chainIo } from "@esseyonsui/sui-mcp-v3/io"`.
17
+
18
+ The server speaks the same hand-written stdio subset as `packages/mcp`: `initialize`, `ping`, `tools/list`,
19
+ `tools/call`. It does not reuse that server's lending calls.
20
+
21
+ ## Keys
22
+
23
+ `ESSEY_NOTE_KEY_FILE` and `ESSEY_AGENT_KEY_FILE` are mode-600 paths. The note file is 32 raw bytes or 64 hex
24
+ digits; the server passes it to `Essey.connect` and does not put it on the tool context. The agent key file is
25
+ checked at startup and never read: V3 loan and note calls go through the SDK, which does not take that key, and
26
+ this server does not sign. No tool argument is a key, a seed, or the invite. `ESSEY_INVITE`, when set, is the
27
+ invite gate for `essey_credential_obtain`. Results drop secret names (`borrowerSk`, `loanKey`, `salt`, and the same words inside a larger name), raw bytes,
28
+ `suiprivkey` text, bare 64-hex seeds, and the invite. An SDK failure returns its error code and a fixed hint,
29
+ not the SDK's message; a service refusal adds the service's own all-capitals code as `reason` (`RATE_LIMITED`,
30
+ `E_INSOLVENT`). A refusal while starting prints that code on stderr and not the message.
31
+
32
+ ## Tools
33
+
34
+ Credential: `essey_credential_obtain`, `essey_credential_status`, `essey_credential_renew`.
35
+
36
+ Notes: `essey_faucet`, `essey_notes_deposit`, `essey_notes_balance` (scan; balance and note count only),
37
+ `essey_notes_withdraw`, `essey_notes_receive_address`, `essey_notes_transfer`. `essey_notes_deposit` needs a
38
+ paying wallet, which this server does not hold; fund with `essey_faucet`.
39
+
40
+ Borrower: `essey_loan_open` (collateral coin and amount, loan coin, principal, max rate, term, offer window),
41
+ `essey_loan_settle`, `essey_loan_repay`, `essey_loan_release`, `essey_loan_cancel`, `essey_loan_reclaim_coll`,
42
+ `essey_loan_heartbeat`, `essey_loan_topup`, `essey_loan_collect_surplus`.
43
+
44
+ Lender: `essey_loan_list`, `essey_loan_request`, `essey_loan_offer` (loan id, rate), `essey_loan_collect`,
45
+ `essey_loan_reclaim`, `essey_loan_collect_seized`.
46
+
47
+ Each loan tool calls the SDK's own planner, so the server builds every proof with the circuits `/v3/config`
48
+ pins, reads the chain over Sui GraphQL and seals with the deployment's Seal set (`src/io.ts`). What a later step
49
+ needs and no chain read gives back (the borrower's terms, key and locked amount; the lender's offer record) is
50
+ written to `loan-<id>.json` and `offer-<id>.json`, mode 600, in the state file's directory, the same files
51
+ `scripts/v3/live/run.mts` writes. No tool returns them. Give each server its own state directory.
52
+
53
+ `essey_loan_status` reads one loan's public fields from chain. `essey_loan_view` runs the SDK's `localHealth`
54
+ and `covered` on the public fields in its arguments and reads nothing.
55
+
56
+ There is no refinance tool.
57
+
58
+ Amounts are whole-number strings in the coin's smallest unit.
59
+
60
+ ## Configuration
61
+
62
+ | variable | |
63
+ | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
+ | `ESSEY_NETWORK` | `testnet` (required) |
65
+ | `ESSEY_V3_CONFIG` | `https` URL of `GET /v3/config`, or `http` on localhost, or a path to that JSON (required). A URL is what lets the SDK name the v3api. A file has no API origin. |
66
+ | `ESSEY_STATE_FILE` | mode-600 state path the SDK keeps the credential in (required) |
67
+ | `ESSEY_NOTE_KEY_FILE` | mode-600 note seed (required) |
68
+ | `ESSEY_AGENT_KEY_FILE` | mode-600 agent key file (required; not read) |
69
+ | `ESSEY_INVITE` | optional invite token, 1..256 characters without whitespace |
70
+ | `ESSEY_RELAYER` | `clear` (default) or `onion` |
71
+ | `ESSEY_GRAPHQL` | Sui GraphQL URL, `https` or `http` on localhost (default `https://graphql.testnet.sui.io/graphql`) |
72
+
73
+ Any other `ESSEY_*` variable stops the server, and so does a name containing `OWNER` or a value holding a private key.
74
+
75
+ Run the published `essey-sui-mcp-v3` bin, or `node --import tsx packages/mcp-v3/src/main.ts` from the repo root, with
76
+ those variables set.
package/dist/args.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { type CoinKey } from "@esseyonsui/sui-sdk-v3";
2
+ import type { OpenParams } from "./client.ts";
3
+ import type { PublicLoan } from "./loan-view.ts";
4
+ type Rec = Record<string, unknown>;
5
+ type JsonSchema = Record<string, unknown>;
6
+ export declare function parseRole(args: Rec): "member" | "keeper" | undefined;
7
+ export declare function parseCoin(args: Rec, k?: string): CoinKey;
8
+ export declare function parseAmount(args: Rec, k?: string): bigint;
9
+ export declare function parseDenominations(args: Rec): boolean | undefined;
10
+ export declare function parsePayee(args: Rec): string;
11
+ export declare const parseLoanId: (args: Rec) => string;
12
+ export declare const LOAN_SCHEMA: JsonSchema;
13
+ export declare const TRANSFER_SCHEMA: JsonSchema;
14
+ export declare function parseReceiver(args: Rec): string;
15
+ export declare const OPEN_SCHEMA: JsonSchema;
16
+ export declare function parseOpen(args: Rec): OpenParams;
17
+ export declare const OFFER_SCHEMA: JsonSchema;
18
+ export declare function parseOfferArgs(args: Rec): {
19
+ loan: string;
20
+ rateBps: number;
21
+ };
22
+ export declare const HEARTBEAT_SCHEMA: JsonSchema;
23
+ export declare function parseHeartbeat(args: Rec): {
24
+ loan: string;
25
+ k?: number;
26
+ };
27
+ export declare const TOPUP_SCHEMA: JsonSchema;
28
+ export declare function parseTopup(args: Rec): {
29
+ loan: string;
30
+ add: bigint;
31
+ asBorrower?: boolean;
32
+ };
33
+ export declare const LIST_SCHEMA: JsonSchema;
34
+ export declare const parseListAll: (args: Rec) => boolean;
35
+ export declare const VIEW_SCHEMA: JsonSchema;
36
+ export declare function parseView(args: Rec): PublicLoan;
37
+ export {};
38
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAMnC,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAoF1C,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAIpE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,GAAG,OAAO,CAExD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAW,GAAG,MAAM,CAI3D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,GAAG,SAAS,CAEjE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAE5C;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,KAAG,MAA+B,CAAC;AAExE,eAAO,MAAM,WAAW,YAAyC,CAAC;AAElE,eAAO,MAAM,eAAe,YAW3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAK/C;AAED,eAAO,MAAM,WAAW,YAWvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU,CAa/C;AAED,eAAO,MAAM,YAAY,YAGvB,CAAC;AAEH,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAE3E;AAED,eAAO,MAAM,gBAAgB,YAM5B,CAAC;AAEF,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAGtE;AAED,eAAO,MAAM,YAAY,YAOxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAKzF;AAED,eAAO,MAAM,WAAW,YAGvB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,GAAG,KAAG,OAAwC,CAAC;AA2BlF,eAAO,MAAM,WAAW,YAmBvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU,CAmB/C"}
package/dist/args.js ADDED
@@ -0,0 +1,240 @@
1
+ import { COINS, v3 } from "@esseyonsui/sui-sdk-v3";
2
+ import { ToolRefusal } from "./failure.js";
3
+ const U64 = 1n << 64n;
4
+ const MAX_BPS = 10_000;
5
+ const { K_MIN, K_MAX } = v3.collateral;
6
+ function bad(msg) {
7
+ throw new ToolRefusal(msg);
8
+ }
9
+ const U64S = {
10
+ type: "string",
11
+ pattern: "^(0|[1-9][0-9]*)$",
12
+ description: "canonical decimal u64",
13
+ };
14
+ const AMOUNT = {
15
+ type: "string",
16
+ pattern: "^[1-9][0-9]*$",
17
+ description: "whole-number string in the coin's smallest unit",
18
+ };
19
+ const COIN = { type: "string", enum: [...COINS], description: "tusdsui, usdc or sui" };
20
+ const ADDRESS = {
21
+ type: "string",
22
+ pattern: "^0x[0-9a-fA-F]{1,64}$",
23
+ description: "0x object id",
24
+ };
25
+ const LOAN = {
26
+ ...ADDRESS,
27
+ description: "loan id, as essey_loan_open or essey_loan_list returns it",
28
+ };
29
+ const BPS = { type: "integer", minimum: 0, maximum: MAX_BPS, description: "basis points" };
30
+ const MS = { type: "integer", minimum: 1, maximum: Number.MAX_SAFE_INTEGER };
31
+ const objectSchema = (properties, required) => ({
32
+ type: "object",
33
+ properties,
34
+ required,
35
+ additionalProperties: false,
36
+ });
37
+ function only(v, keys, what) {
38
+ for (const k of Object.keys(v))
39
+ if (!keys.includes(k))
40
+ bad(`${what} has a field that is not accepted`);
41
+ }
42
+ function decimal(v, what) {
43
+ if (typeof v !== "string" || !/^(0|[1-9][0-9]*)$/.test(v))
44
+ bad(`${what} must be a canonical decimal string`);
45
+ return BigInt(v);
46
+ }
47
+ function u64(a, k) {
48
+ const n = decimal(a[k], k);
49
+ if (n >= U64)
50
+ bad(`${k} is not a u64`);
51
+ return n;
52
+ }
53
+ function coin(a, k) {
54
+ const v = a[k];
55
+ if (typeof v !== "string" || !COINS.includes(v))
56
+ bad(`${k} must be tusdsui, usdc or sui`);
57
+ return v;
58
+ }
59
+ function address(a, k) {
60
+ const v = a[k];
61
+ if (typeof v !== "string")
62
+ bad(`${k} must be an 0x address`);
63
+ const hex = v.replace(/^0x/i, "").toLowerCase();
64
+ if (!/^[0-9a-f]{1,64}$/.test(hex))
65
+ bad(`${k} must be an 0x address`);
66
+ return `0x${hex.padStart(64, "0")}`;
67
+ }
68
+ function payee(a, k) {
69
+ const v = a[k];
70
+ if (typeof v !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(v))
71
+ bad(`${k} must be 0x and 64 hex digits`);
72
+ const out = v.toLowerCase();
73
+ if (out === `0x${"0".repeat(64)}`)
74
+ bad(`${k} is the zero address`);
75
+ return out;
76
+ }
77
+ function optBool(a, k) {
78
+ if (a[k] === undefined)
79
+ return undefined;
80
+ if (typeof a[k] !== "boolean")
81
+ bad(`${k} must be true or false`);
82
+ return a[k];
83
+ }
84
+ function int(a, k, min, max) {
85
+ const v = a[k];
86
+ if (typeof v !== "number" || !Number.isInteger(v) || v < min || v > max)
87
+ bad(`${k} must be an integer from ${min} to ${max}`);
88
+ return v;
89
+ }
90
+ export function parseRole(args) {
91
+ if (args.role === undefined)
92
+ return undefined;
93
+ if (args.role !== "member" && args.role !== "keeper")
94
+ bad("role must be member or keeper");
95
+ return args.role;
96
+ }
97
+ export function parseCoin(args, k = "coin") {
98
+ return coin(args, k);
99
+ }
100
+ export function parseAmount(args, k = "amount") {
101
+ const n = u64(args, k);
102
+ if (n <= 0n)
103
+ bad(`${k} must be a u64 above 0`);
104
+ return n;
105
+ }
106
+ export function parseDenominations(args) {
107
+ return optBool(args, "denominations");
108
+ }
109
+ export function parsePayee(args) {
110
+ return payee(args, "to");
111
+ }
112
+ export const parseLoanId = (args) => address(args, "loan");
113
+ export const LOAN_SCHEMA = objectSchema({ loan: LOAN }, ["loan"]);
114
+ export const TRANSFER_SCHEMA = objectSchema({
115
+ coin: COIN,
116
+ amount: AMOUNT,
117
+ to: {
118
+ type: "string",
119
+ pattern: "^v3note:[0-9]{1,78}:(02|03)[0-9a-f]{64}:[0-9]{1,15}$",
120
+ description: "the payee's essey_notes_receive_address",
121
+ },
122
+ }, ["coin", "amount", "to"]);
123
+ export function parseReceiver(args) {
124
+ const v = args.to;
125
+ if (typeof v !== "string" || !/^v3note:[0-9]{1,78}:(02|03)[0-9a-f]{64}:[0-9]{1,15}$/.test(v))
126
+ bad("to must be a v3note receive address");
127
+ return v;
128
+ }
129
+ export const OPEN_SCHEMA = objectSchema({
130
+ collateralCoin: COIN,
131
+ collateral: { ...AMOUNT, description: "collateral to lock, in the collateral coin's smallest unit" },
132
+ loanCoin: COIN,
133
+ principal: { ...AMOUNT, description: "principal to borrow, in the loan coin's smallest unit" },
134
+ maxRateBps: { ...BPS, description: "highest rate accepted, basis points" },
135
+ termMs: { ...MS, description: "loan term after settle, milliseconds" },
136
+ offerWindowMs: { ...MS, description: "how long lenders may offer, milliseconds" },
137
+ }, ["collateralCoin", "collateral", "loanCoin", "principal", "maxRateBps", "termMs", "offerWindowMs"]);
138
+ export function parseOpen(args) {
139
+ const collateralCoin = coin(args, "collateralCoin");
140
+ const loanCoin = coin(args, "loanCoin");
141
+ if (collateralCoin === loanCoin)
142
+ bad("loanCoin and collateralCoin must differ");
143
+ return {
144
+ collateralCoin,
145
+ collateral: parseAmount(args, "collateral"),
146
+ loanCoin,
147
+ principal: parseAmount(args, "principal"),
148
+ maxRateBps: int(args, "maxRateBps", 0, MAX_BPS),
149
+ termMs: int(args, "termMs", 1, Number.MAX_SAFE_INTEGER),
150
+ offerWindowMs: int(args, "offerWindowMs", 1, Number.MAX_SAFE_INTEGER),
151
+ };
152
+ }
153
+ export const OFFER_SCHEMA = objectSchema({ loan: LOAN, rateBps: { ...BPS, description: "offered rate" } }, [
154
+ "loan",
155
+ "rateBps",
156
+ ]);
157
+ export function parseOfferArgs(args) {
158
+ return { loan: parseLoanId(args), rateBps: int(args, "rateBps", 0, MAX_BPS) };
159
+ }
160
+ export const HEARTBEAT_SCHEMA = objectSchema({
161
+ loan: LOAN,
162
+ k: { type: "integer", minimum: K_MIN, maximum: K_MAX, description: "health bucket, default 1" },
163
+ }, ["loan"]);
164
+ export function parseHeartbeat(args) {
165
+ const loan = parseLoanId(args);
166
+ return args.k === undefined ? { loan } : { loan, k: int(args, "k", K_MIN, K_MAX) };
167
+ }
168
+ export const TOPUP_SCHEMA = objectSchema({
169
+ loan: LOAN,
170
+ add: { ...AMOUNT, description: "collateral to add, in the collateral coin's smallest unit" },
171
+ asBorrower: { type: "boolean", description: "through the borrower pass (topup_by_borrower)" },
172
+ }, ["loan", "add"]);
173
+ export function parseTopup(args) {
174
+ const loan = parseLoanId(args);
175
+ const add = parseAmount(args, "add");
176
+ const asBorrower = optBool(args, "asBorrower");
177
+ return asBorrower === undefined ? { loan, add } : { loan, add, asBorrower };
178
+ }
179
+ export const LIST_SCHEMA = objectSchema({ all: { type: "boolean", description: "every loan, not only those taking offers" } }, []);
180
+ export const parseListAll = (args) => optBool(args, "all") ?? false;
181
+ const VIEW_KEYS = [
182
+ "id",
183
+ "state",
184
+ "collateral",
185
+ "owed",
186
+ "cDec",
187
+ "lDec",
188
+ "liqBps",
189
+ "spot",
190
+ "ema",
191
+ "expo",
192
+ "floorPrice",
193
+ "floorExpo",
194
+ "hbExpiryMs",
195
+ "nonce",
196
+ "nowMs",
197
+ ];
198
+ const SMALL = (min, max, description) => ({
199
+ type: "integer",
200
+ minimum: min,
201
+ maximum: max,
202
+ description,
203
+ });
204
+ export const VIEW_SCHEMA = objectSchema({
205
+ id: ADDRESS,
206
+ state: SMALL(0, 255, "public loan state"),
207
+ collateral: { ...U64S, description: "collateral amount in the coin's smallest unit" },
208
+ owed: { ...U64S, description: "amount owed in the loan coin's smallest unit" },
209
+ cDec: SMALL(0, 18, "collateral decimals"),
210
+ lDec: SMALL(0, 18, "loan-coin decimals"),
211
+ liqBps: SMALL(0, 10_000, "liquidation threshold in basis points"),
212
+ spot: U64S,
213
+ ema: U64S,
214
+ expo: SMALL(0, 18, "price exponent"),
215
+ floorPrice: U64S,
216
+ floorExpo: SMALL(0, 255, "stored floor exponent"),
217
+ hbExpiryMs: U64S,
218
+ nonce: U64S,
219
+ nowMs: U64S,
220
+ }, [...VIEW_KEYS]);
221
+ export function parseView(args) {
222
+ only(args, VIEW_KEYS, "essey_loan_view");
223
+ return {
224
+ id: address(args, "id"),
225
+ state: int(args, "state", 0, 255),
226
+ collateral: u64(args, "collateral"),
227
+ owed: u64(args, "owed"),
228
+ cDec: BigInt(int(args, "cDec", 0, 18)),
229
+ lDec: BigInt(int(args, "lDec", 0, 18)),
230
+ liqBps: BigInt(int(args, "liqBps", 0, 10_000)),
231
+ spot: u64(args, "spot"),
232
+ ema: u64(args, "ema"),
233
+ expo: BigInt(int(args, "expo", 0, 18)),
234
+ floorPrice: u64(args, "floorPrice"),
235
+ floorExpo: int(args, "floorExpo", 0, 255),
236
+ hbExpiryMs: u64(args, "hbExpiryMs"),
237
+ nonce: u64(args, "nonce"),
238
+ nowMs: u64(args, "nowMs"),
239
+ };
240
+ }
@@ -0,0 +1,26 @@
1
+ import type { Essey } from "@esseyonsui/sui-sdk-v3";
2
+ import type { LoanStatus, PublicLoan } from "./loan-view.ts";
3
+ type Loans = Essey["loans"];
4
+ type Landed = Awaited<ReturnType<Loans["payBack"]>>;
5
+ export type OpenParams = Extract<Parameters<Loans["open"]>[0], {
6
+ loanCoin: unknown;
7
+ }>;
8
+ /**
9
+ * The slice of `@esseyonsui/sui-sdk-v3` the tools call. Tests replace it.
10
+ * The note seed and the agent key are not fields of this object.
11
+ */
12
+ export type DemoClient = {
13
+ credential: Essey["credential"];
14
+ notes: Pick<Essey["notes"], "faucet" | "deposit" | "scan" | "withdraw" | "transfer" | "receiveAddress">;
15
+ loans: Pick<Loans, "request" | "lend" | "accept" | "payBack" | "release" | "collect" | "cancelOwn" | "reclaimCollateral" | "reclaimOffer" | "collectSeized" | "collectSurplus" | "heartbeat" | "topup" | "list" | "view"> & {
16
+ open(p: OpenParams): Promise<{
17
+ id: string;
18
+ } & Landed>;
19
+ health(loan: PublicLoan): Promise<LoanStatus>;
20
+ };
21
+ };
22
+ export declare function clientOf(essey: Essey, health?: DemoClient["loans"]["health"]): DemoClient;
23
+ /** The invite stays in the server process. Tool arguments cannot replace it or read it back. */
24
+ export declare function withInvite(client: DemoClient, invite: string | null): DemoClient;
25
+ export {};
26
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,KAAK,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5B,KAAK,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,gBAAgB,CAAC,CAAC;IACxG,KAAK,EAAE,IAAI,CACT,KAAK,EACH,SAAS,GACT,MAAM,GACN,QAAQ,GACR,SAAS,GACT,SAAS,GACT,SAAS,GACT,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,eAAe,GACf,gBAAgB,GAChB,WAAW,GACX,OAAO,GACP,MAAM,GACN,MAAM,CACT,GAAG;QACF,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,MAAM,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;KAC/C,CAAC;CACH,CAAC;AASF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,CAA6C,GAChF,UAAU,CAgCZ;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAShF"}
package/dist/client.js ADDED
@@ -0,0 +1,53 @@
1
+ import { statusOf } from "./loan-view.js";
2
+ /** With `loanCoin` set the SDK plans the open itself and returns the new id (`essey.ts` openRequest). */
3
+ async function openPlanned(essey, p) {
4
+ const r = await essey.loans.open(p);
5
+ if (!("id" in r))
6
+ throw new Error("loan open returned no id");
7
+ return r;
8
+ }
9
+ export function clientOf(essey, health = (loan) => Promise.resolve(statusOf(loan))) {
10
+ const { loans, notes } = essey;
11
+ return {
12
+ credential: essey.credential,
13
+ notes: {
14
+ faucet: (coin) => notes.faucet(coin),
15
+ deposit: (coin, amount, o) => notes.deposit(coin, amount, o),
16
+ scan: (coin) => notes.scan(coin),
17
+ withdraw: (coin, amount, to) => notes.withdraw(coin, amount, to),
18
+ transfer: (coin, amount, to) => notes.transfer(coin, amount, to),
19
+ receiveAddress: () => notes.receiveAddress(),
20
+ },
21
+ loans: {
22
+ open: (p) => openPlanned(essey, p),
23
+ request: (id) => loans.request(id),
24
+ lend: (p) => loans.lend(p),
25
+ accept: (id) => loans.accept(id),
26
+ payBack: (p) => loans.payBack(p),
27
+ release: (p) => loans.release(p),
28
+ collect: (p) => loans.collect(p),
29
+ cancelOwn: (id) => loans.cancelOwn(id),
30
+ reclaimCollateral: (p) => loans.reclaimCollateral(p),
31
+ reclaimOffer: (p) => loans.reclaimOffer(p),
32
+ collectSeized: (p) => loans.collectSeized(p),
33
+ collectSurplus: (p) => loans.collectSurplus(p),
34
+ heartbeat: (p) => loans.heartbeat(p),
35
+ topup: (p) => loans.topup(p),
36
+ list: () => loans.list(),
37
+ view: (id) => loans.view(id),
38
+ health,
39
+ },
40
+ };
41
+ }
42
+ /** The invite stays in the server process. Tool arguments cannot replace it or read it back. */
43
+ export function withInvite(client, invite) {
44
+ if (!invite)
45
+ return client;
46
+ return {
47
+ ...client,
48
+ credential: {
49
+ ...client.credential,
50
+ obtain: (o) => client.credential.obtain({ ...o, invite }),
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,32 @@
1
+ export type McpConfig = {
2
+ network: "testnet";
3
+ /** `GET /v3/config`, which also names the v3api, or a path to that JSON. */
4
+ config: {
5
+ kind: "url";
6
+ url: string;
7
+ } | {
8
+ kind: "file";
9
+ path: string;
10
+ };
11
+ /** Mode-600 state file the SDK uses for the credential. Per-loan records go in its directory. Never returned. */
12
+ stateFile: string;
13
+ /** Sui GraphQL the chain readers and Seal sessions use. */
14
+ graphql: string;
15
+ /** Mode-600 note seed. The server passes it to the SDK and does not keep a copy on the tool context. */
16
+ noteKeyFile: string;
17
+ /** Mode-600 agent key file. Checked at startup and never read, signed with, or accepted as a tool argument. */
18
+ agentKeyFile: string;
19
+ /** Invite gate token. Unset: credential obtain uses the proof-of-work challenge. Never a tool argument. */
20
+ invite: string | null;
21
+ relayer: "clear" | "onion";
22
+ };
23
+ export declare const TESTNET_GRAPHQL = "https://graphql.testnet.sui.io/graphql";
24
+ export declare class ConfigError extends Error {
25
+ readonly code = "INVALID_CONFIG";
26
+ }
27
+ /**
28
+ * Every ESSEY_* variable must be one of KNOWN, so a key cannot be slipped in under a new name. No value may
29
+ * hold a private key inline: the note seed and the agent key live only in their mode-600 files.
30
+ */
31
+ export declare function parseConfig(env: NodeJS.ProcessEnv): McpConfig;
32
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,iHAAiH;IACjH,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IACpB,+GAA+G;IAC/G,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,eAAe,2CAA2C,CAAC;AAaxE,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,oBAAoB;CAClC;AAWD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,CA0B7D"}
package/dist/config.js ADDED
@@ -0,0 +1,87 @@
1
+ export const TESTNET_GRAPHQL = "https://graphql.testnet.sui.io/graphql";
2
+ const KNOWN = [
3
+ "ESSEY_NETWORK",
4
+ "ESSEY_V3_CONFIG",
5
+ "ESSEY_STATE_FILE",
6
+ "ESSEY_NOTE_KEY_FILE",
7
+ "ESSEY_AGENT_KEY_FILE",
8
+ "ESSEY_INVITE",
9
+ "ESSEY_RELAYER",
10
+ "ESSEY_GRAPHQL",
11
+ ];
12
+ export class ConfigError extends Error {
13
+ code = "INVALID_CONFIG";
14
+ }
15
+ function fail(msg) {
16
+ throw new ConfigError(msg);
17
+ }
18
+ /** A value that is itself key material. The message names the variable and not the value. */
19
+ function inlineKey(v) {
20
+ return /suiprivkey|PRIVATE_KEY|mnemonic/i.test(v);
21
+ }
22
+ /**
23
+ * Every ESSEY_* variable must be one of KNOWN, so a key cannot be slipped in under a new name. No value may
24
+ * hold a private key inline: the note seed and the agent key live only in their mode-600 files.
25
+ */
26
+ export function parseConfig(env) {
27
+ for (const [k, v] of Object.entries(env)) {
28
+ if (!k.startsWith("ESSEY_"))
29
+ continue;
30
+ if (/OWNER/.test(k))
31
+ fail(`${k}: there is no owner-key setting; note and agent keys are file paths`);
32
+ if (!KNOWN.includes(k))
33
+ fail(`${k} is not a setting (known: ${KNOWN.join(", ")})`);
34
+ if (v && inlineKey(v))
35
+ fail(`${k} holds a key; keys go in ESSEY_NOTE_KEY_FILE and ESSEY_AGENT_KEY_FILE`);
36
+ }
37
+ const need = (k) => env[k] || fail(`${k} is required`);
38
+ const network = need("ESSEY_NETWORK");
39
+ if (network !== "testnet")
40
+ fail("ESSEY_NETWORK must be testnet");
41
+ const relayer = env.ESSEY_RELAYER ?? "clear";
42
+ if (relayer !== "clear" && relayer !== "onion")
43
+ fail("ESSEY_RELAYER must be clear or onion");
44
+ const noteKeyFile = need("ESSEY_NOTE_KEY_FILE");
45
+ const agentKeyFile = need("ESSEY_AGENT_KEY_FILE");
46
+ if (/^[0-9a-fA-F]{64}$/.test(noteKeyFile) || /^[0-9a-fA-F]{64}$/.test(agentKeyFile))
47
+ fail("a key file setting holds key material; it must be a path");
48
+ return {
49
+ network: "testnet",
50
+ config: configOf(need("ESSEY_V3_CONFIG")),
51
+ stateFile: need("ESSEY_STATE_FILE"),
52
+ graphql: env.ESSEY_GRAPHQL ? serviceUrl(env.ESSEY_GRAPHQL, "ESSEY_GRAPHQL") : TESTNET_GRAPHQL,
53
+ noteKeyFile,
54
+ agentKeyFile,
55
+ invite: inviteOf(env.ESSEY_INVITE),
56
+ relayer,
57
+ };
58
+ }
59
+ function configOf(v) {
60
+ if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(v))
61
+ return { kind: "file", path: v };
62
+ return { kind: "url", url: serviceUrl(v, "ESSEY_V3_CONFIG") };
63
+ }
64
+ function serviceUrl(v, name) {
65
+ let url;
66
+ try {
67
+ url = new URL(v);
68
+ }
69
+ catch {
70
+ return fail(`${name} is not a URL`);
71
+ }
72
+ if (url.username || url.password)
73
+ fail(`${name} must not carry credentials`);
74
+ if (url.hostname.endsWith(".onion"))
75
+ fail(`${name}: no Tor transport in this build`);
76
+ const local = url.hostname === "127.0.0.1" || url.hostname === "localhost";
77
+ if (url.protocol !== "https:" && !(local && url.protocol === "http:"))
78
+ fail(`${name} must be https`);
79
+ return url.origin + url.pathname + url.search;
80
+ }
81
+ function inviteOf(v) {
82
+ if (v === undefined || v === "")
83
+ return null;
84
+ if (v.length > 256 || /[\0-\x1f\s]/.test(v))
85
+ fail("ESSEY_INVITE is not a token");
86
+ return v;
87
+ }
@@ -0,0 +1,26 @@
1
+ import { EsseyError } from "@esseyonsui/sui-sdk-v3";
2
+ export declare const WITHHELD = "The tool failed inside a library; its error is withheld.";
3
+ export type Failure = {
4
+ ok: false;
5
+ error: string;
6
+ hint: string;
7
+ reason?: string;
8
+ };
9
+ /**
10
+ * A refusal this server words itself. The hint is a rule, never a value the caller sent.
11
+ * Adapted from the VPS draft at 882f9eec (claude/v3-054-mcp-wip).
12
+ */
13
+ export declare class ToolRefusal extends Error {
14
+ readonly hint: string;
15
+ readonly code = "INVALID_ARGUMENT";
16
+ constructor(hint: string);
17
+ }
18
+ /**
19
+ * An SDK message can quote a service reply. Only a code from the SDK's own list is returned, with a fixed hint.
20
+ * Anything else, including a lookalike `{ code }` on a plain Error, is withheld.
21
+ */
22
+ export declare function failureOf(err: unknown, secrets?: readonly string[]): Failure;
23
+ export declare const isSdkCode: (err: unknown) => err is EsseyError;
24
+ /** Refuses key material in arguments. The hint names neither the value nor the property. */
25
+ export declare function assertNoSecrets(value: unknown): void;
26
+ //# sourceMappingURL=failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,UAAU,EAAgB,MAAM,wBAAwB,CAAC;AAIrF,eAAO,MAAM,QAAQ,6DAA6D,CAAC;AAEnF,MAAM,MAAM,OAAO,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAKlF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAExB,QAAQ,CAAC,IAAI,EAAE,MAAM;IADjC,QAAQ,CAAC,IAAI,sBAAsB;gBACd,IAAI,EAAE,MAAM;CAGlC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAQhF;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,UACkC,CAAC;AAEnF,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAcpD"}
@@ -0,0 +1,50 @@
1
+ import { ESSEY_ERROR_CODES, isEsseyError } from "@esseyonsui/sui-sdk-v3";
2
+ import { redactText, secretArgument } from "./redact.js";
3
+ export const WITHHELD = "The tool failed inside a library; its error is withheld.";
4
+ /** Only an all-capitals code is passed on (RATE_LIMITED, E_INSOLVENT): no digits, so no key text fits it. */
5
+ const SERVICE_CODE = /^(?:v3api|relayer) refused: ([A-Z_]{3,40})$/;
6
+ /**
7
+ * A refusal this server words itself. The hint is a rule, never a value the caller sent.
8
+ * Adapted from the VPS draft at 882f9eec (claude/v3-054-mcp-wip).
9
+ */
10
+ export class ToolRefusal extends Error {
11
+ hint;
12
+ code = "INVALID_ARGUMENT";
13
+ constructor(hint) {
14
+ super(hint);
15
+ this.hint = hint;
16
+ }
17
+ }
18
+ /**
19
+ * An SDK message can quote a service reply. Only a code from the SDK's own list is returned, with a fixed hint.
20
+ * Anything else, including a lookalike `{ code }` on a plain Error, is withheld.
21
+ */
22
+ export function failureOf(err, secrets = []) {
23
+ if (err instanceof ToolRefusal)
24
+ return { ok: false, error: err.code, hint: redactText(err.hint, secrets) };
25
+ if (isEsseyError(err) && ESSEY_ERROR_CODES.includes(err.code)) {
26
+ const reason = err.code === "SERVICE_REFUSED" ? SERVICE_CODE.exec(err.message)?.[1] : undefined;
27
+ const hint = `Look up ${err.code} in the sdk/errors reference.`;
28
+ return { ok: false, error: err.code, hint, ...(reason ? { reason } : {}) };
29
+ }
30
+ return { ok: false, error: "UNEXPECTED", hint: WITHHELD };
31
+ }
32
+ export const isSdkCode = (err) => isEsseyError(err) && ESSEY_ERROR_CODES.includes(err.code);
33
+ /** Refuses key material in arguments. The hint names neither the value nor the property. */
34
+ export function assertNoSecrets(value) {
35
+ if (Array.isArray(value)) {
36
+ for (const item of value)
37
+ assertNoSecrets(item);
38
+ return;
39
+ }
40
+ if (value === null || typeof value !== "object") {
41
+ if (typeof value === "string" && /suiprivkey/i.test(value))
42
+ throw new ToolRefusal("an argument holds a private key");
43
+ return;
44
+ }
45
+ for (const [name, inner] of Object.entries(value)) {
46
+ if (secretArgument(name))
47
+ throw new ToolRefusal("a secret is not a tool argument");
48
+ assertNoSecrets(inner);
49
+ }
50
+ }
package/dist/init.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ export declare const DEFAULT_CONFIG_URL = "https://essey-v3-production.up.railway.app/v3/config";
3
+ export type InitResult = {
4
+ ok: true;
5
+ env: Record<string, string>;
6
+ } | {
7
+ ok: false;
8
+ error: string;
9
+ };
10
+ export declare function init(dir: string, configUrl?: string): InitResult;
11
+ //# sourceMappingURL=init.d.ts.map