@mysten-incubation/suipay-mcp 0.3.0-dev.34 → 0.3.0-dev.36

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.
@@ -519,7 +519,7 @@ interface McpAuthContext {
519
519
 
520
520
  type McpTarget = 'dev' | 'local';
521
521
  /**
522
- * Public suipay-dev origins (Railway). `local` is the laptop stack from
522
+ * Public staging origins. `local` is the laptop stack from
523
523
  * `pnpm demo:testnet`. Explicit `SUIPAY_GATEWAY_URL` / `SUIPAY_CONSOLE_URL`
524
524
  * still win over the preset.
525
525
  */
@@ -649,7 +649,7 @@ interface DelegatePoliciesDTO {
649
649
  * Agent signing helper — emit the four `x-suipay-*` signed-request headers.
650
650
  *
651
651
  * A delegate agent proves identity on every private, grant-scoped request by
652
- * signing the canonical `SignedRequestV1` payload with a Sui personal-message
652
+ * signing the canonical `SignedRequestV2` payload with a Sui personal-message
653
653
  * signature. This helper is the client-side counterpart to the gateway verifier:
654
654
  * it canonicalizes the path/query and hashes the body EXACTLY as the verifier
655
655
  * will (reusing the P0 codec's `canonicalizePath` / `canonicalizeQuery` /
@@ -661,24 +661,30 @@ interface DelegatePoliciesDTO {
661
661
  * bound via {@link personalMessageSigner}). Money never moves on this signature;
662
662
  * it authorizes only the grant-scoped reads the epic defines.
663
663
  *
664
- * Byte-for-byte parity with P0 is locked by the golden vector in
665
- * `tests/agent-sdk-signed-headers.test.ts`, which reproduces the exact
666
- * signature the cross-language vector (`tests/parity/signed-request-golden.test.ts`)
667
- * pins.
664
+ * The signed bytes are pinned by the v2 vector in
665
+ * `tests/agent-sdk-signed-headers.test.ts`, built from the same field values
666
+ * as the v1 cross-language vector (`tests/parity/signed-request-golden.test.ts`).
668
667
  */
669
668
 
670
669
  /** Sui personal-message signer: returns the serialized signature (base64). */
671
670
  type SignPersonalMessage = (message: Uint8Array) => Promise<string>;
672
671
  /**
673
- * The deployment + grant identity every signed request binds. `network` and
674
- * `packageId` MUST equal the gateway's server-authoritative config; `delegate`
675
- * MUST equal the grant's registered on-chain delegate (the signer's address).
672
+ * The deployment + grant identity every signed request binds. `network`,
673
+ * `packageId`, and `origin` MUST equal the gateway's server-authoritative
674
+ * config; `delegate` MUST equal the grant's registered on-chain delegate (the
675
+ * signer's address).
676
676
  */
677
677
  interface SessionSignerContext {
678
678
  /** e.g. `sui:testnet` — must equal the gateway config. */
679
679
  network: string;
680
680
  /** Deployed package id — must equal the gateway config. */
681
681
  packageId: string;
682
+ /**
683
+ * The gateway the request is sent to — any http(s) URL on it; only its
684
+ * {@link canonicalOrigin} is signed. Must equal the gateway's configured base
685
+ * URL origin, so the signature cannot be replayed at another gateway.
686
+ */
687
+ origin: string;
682
688
  /** On-chain grant object id — the authorization scope. */
683
689
  grantObjectId: string;
684
690
  /** Registered delegate Sui address (the signer). */
@@ -748,8 +754,11 @@ type PayerReadResult<T> = {
748
754
  interface PayerReadClientOptions {
749
755
  /** Gateway origin, e.g. `https://gateway.suipay.dev` (no trailing slash needed). */
750
756
  gatewayUrl: string;
751
- /** Deployment + grant identity every signed read binds. */
752
- context: SessionSignerContext;
757
+ /**
758
+ * Deployment + grant identity every signed read binds. The signed origin is
759
+ * always `gatewayUrl`'s: a read binds the gateway it is sent to.
760
+ */
761
+ context: Omit<SessionSignerContext, 'origin'>;
753
762
  /** Local personal-message signer; the key never leaves it. */
754
763
  signPersonalMessage: SignPersonalMessage;
755
764
  /** Injectable fetch (tests / custom transports). Defaults to global `fetch`. */
@@ -781,6 +790,12 @@ declare function createReader(options: PayerReadClientOptions): PayerReadClient;
781
790
  */
782
791
  type GetObjectJson = (objectId: string) => Promise<Record<string, unknown> | null | undefined>;
783
792
 
793
+ interface PayExpirationPolicy {
794
+ currentEpoch: bigint;
795
+ chainIdentifier?: string;
796
+ requireBounded?: boolean;
797
+ }
798
+
784
799
  interface OfferJWK {
785
800
  kty: 'OKP' | string;
786
801
  crv?: 'Ed25519' | string;
@@ -1245,7 +1260,7 @@ declare const ERRORS: {
1245
1260
  };
1246
1261
  };
1247
1262
  readonly 'service.unavailable': {
1248
- readonly surfaces: readonly ["gateway", "console_server", "mcp_hosted", "browser"];
1263
+ readonly surfaces: readonly ["gateway", "seller", "console_server", "mcp_hosted", "browser"];
1249
1264
  readonly status: 503;
1250
1265
  readonly title: "Service temporarily unavailable";
1251
1266
  readonly paymentState: "not_charged";
@@ -1257,6 +1272,19 @@ declare const ERRORS: {
1257
1272
  readonly message: "This isn't available right now. Try again in a moment.";
1258
1273
  };
1259
1274
  };
1275
+ readonly 'service.halted': {
1276
+ readonly surfaces: readonly ["gateway", "seller", "console_server", "mcp_hosted", "browser"];
1277
+ readonly status: 503;
1278
+ readonly title: "Services halted temporarily";
1279
+ readonly paymentState: "not_charged";
1280
+ readonly retry: "after_delay";
1281
+ readonly retryAfterSeconds: 5;
1282
+ readonly nextAction: "retry_later";
1283
+ readonly user: {
1284
+ readonly title: "Services halted temporarily";
1285
+ readonly message: "Try again in a moment.";
1286
+ };
1287
+ };
1260
1288
  readonly 'service.not_ready': {
1261
1289
  readonly surfaces: readonly ["gateway", "seller", "console_server"];
1262
1290
  readonly status: 503;
@@ -2501,6 +2529,31 @@ declare const ERRORS: {
2501
2529
  readonly message: "Enter a valid agent address and try again.";
2502
2530
  };
2503
2531
  };
2532
+ readonly 'account.deposit_cap_exceeded': {
2533
+ readonly surfaces: readonly ["gateway", "sdk", "browser"];
2534
+ readonly status: 403;
2535
+ readonly title: "Deposit would exceed the vault beta cap";
2536
+ readonly paymentState: "not_charged";
2537
+ readonly retry: "never";
2538
+ readonly nextAction: "fix_request";
2539
+ readonly user: {
2540
+ readonly title: "Over the beta vault limit";
2541
+ readonly message: "This deposit would put your vault over the Mainnet Beta cap. Deposit less, or withdraw first.";
2542
+ };
2543
+ };
2544
+ readonly 'account.deposits_paused': {
2545
+ readonly surfaces: readonly ["gateway", "sdk", "browser"];
2546
+ readonly status: 403;
2547
+ readonly title: "Deposits are paused";
2548
+ readonly paymentState: "not_charged";
2549
+ readonly retry: "after_delay";
2550
+ readonly retryAfterSeconds: 30;
2551
+ readonly nextAction: "retry_later";
2552
+ readonly user: {
2553
+ readonly title: "Deposits paused";
2554
+ readonly message: "New deposits are paused right now. Withdrawals and spending still work. Try again after deposits resume.";
2555
+ };
2556
+ };
2504
2557
  readonly 'account.finalize_mismatch': {
2505
2558
  readonly surfaces: readonly ["gateway"];
2506
2559
  readonly status: 409;
@@ -4872,6 +4925,8 @@ declare function verifySpendAccountPayReconstructs(bytes: string, expected: {
4872
4925
  poolObjectId: string;
4873
4926
  grantObjectId: string;
4874
4927
  amount: string;
4928
+ /** Trusted epoch bound; without it only a coin-gas transaction with no expiration passes. */
4929
+ expiration?: PayExpirationPolicy;
4875
4930
  }): void;
4876
4931
  /**
4877
4932
  * Prepare a delegate payment WITHOUT signing. Reads the 402 offer, binds it,
@@ -5045,6 +5100,13 @@ interface McpServerOptions {
5045
5100
  * Stdio is the default so existing tests stay local.
5046
5101
  */
5047
5102
  transport?: 'stdio' | 'http';
5103
+ /**
5104
+ * Optional fetch implementation for HTTP calls made by tools (`discover`,
5105
+ * `pay`, `access_context`, `receipts`). Hosted `/mcp` supplies an in-process
5106
+ * dispatcher for the gateway's own public origin so internal hops never
5107
+ * hairpin out through the public load balancer.
5108
+ */
5109
+ fetchImpl?: typeof fetch;
5048
5110
  }
5049
5111
  declare function createServer(cfg: McpConfig, auth?: McpAuthContext, trace?: McpTraceHooks, options?: McpServerOptions): Server;
5050
5112
 
@@ -5062,6 +5124,16 @@ declare function createServer(cfg: McpConfig, auth?: McpAuthContext, trace?: Mcp
5062
5124
  * Handle one MCP Streamable HTTP request (initialize, tools/list, tools/call, …).
5063
5125
  * Creates a fresh transport+server pair per request (stateless mode).
5064
5126
  */
5127
+ /**
5128
+ * How many `tools/call` messages this request contains.
5129
+ *
5130
+ * Clones the body, so the transport can still read it. A body that is not
5131
+ * JSON counts as zero and the transport answers the parse error. The read is
5132
+ * not capped: a truncated read would report zero and let a large batch through.
5133
+ */
5134
+ declare function countMcpToolCalls(req: Request): Promise<number>;
5135
+ /** JSON-RPC Invalid Request (-32600). A batch of tool calls is not one metered call. */
5136
+ declare function tooManyToolCalls(): Response;
5065
5137
  declare function handleSuipayMcpHttpRequest(req: Request, cfg: McpConfig, auth?: McpAuthContext, trace?: McpTraceRuntime | null, options?: McpServerOptions): Promise<Response>;
5066
5138
 
5067
- export { type AgentHeldResolver as A, type SpendAccountPrepareSession as B, type CodeFor as C, type DelegatedKeySigner as D, buildSpendAccountPayKind as E, canonicalMcpRequestId as F, type GetObjectJson as G, createServer as H, handleSuipayMcpHttpRequest as I, inspectMcpEnvelope as J, loadMcpConfig as K, parseMcpTargetFlag as L, type McpConfig as M, type NextAction as N, type OfferPublicKeySource as O, type PaidHttpRequest as P, prepareSpendAccountPayment as Q, resetAgentHeldProcessLedger as R, type SpendAccountSigningRequest as S, TOOLS as T, resolveAgentHeldSettlement as U, resolveGrantTarget as V, resolveMcpTarget as W, type X402PayProgress as X, sameMcpGateway as Y, traceMcpHttpRequest as Z, verifySpendAccountPayReconstructs as _, type DelegatedPayerSession as a, type DelegatedPayerConfig as b, type DelegatedPayerDeps as c, type SpendIntent as d, type DelegatedPayResult as e, type DelegationScope as f, type GrantPolicyBinding as g, type PaymentAttemptLedger as h, type DelegatedPayerLog as i, type PreparedSettlementTerms as j, type Offer as k, type McpAuthContext as l, type McpTraceHooks as m, type SpendAccountPayDeps as n, createReader as o, type AgentHeldSettlement as p, MCP_TARGET_PRESETS as q, type McpEnvelope as r, type McpEnvelopeEntry as s, type McpServerOptions as t, type McpTarget as u, type McpTraceContext as v, type McpTraceRuntime as w, PACKAGE_NAME as x, type PreparedPayment as y, type SpendAccountPrepareResult as z };
5139
+ export { verifySpendAccountPayReconstructs as $, type AgentHeldResolver as A, type SpendAccountPrepareSession as B, type CodeFor as C, type DelegatedKeySigner as D, buildSpendAccountPayKind as E, canonicalMcpRequestId as F, type GetObjectJson as G, countMcpToolCalls as H, createServer as I, handleSuipayMcpHttpRequest as J, inspectMcpEnvelope as K, loadMcpConfig as L, type McpConfig as M, type NextAction as N, type OfferPublicKeySource as O, type PaidHttpRequest as P, parseMcpTargetFlag as Q, prepareSpendAccountPayment as R, type SpendAccountSigningRequest as S, TOOLS as T, resetAgentHeldProcessLedger as U, resolveAgentHeldSettlement as V, resolveGrantTarget as W, type X402PayProgress as X, resolveMcpTarget as Y, sameMcpGateway as Z, traceMcpHttpRequest as _, type DelegatedPayerSession as a, tooManyToolCalls as a0, type DelegatedPayerConfig as b, type DelegatedPayerDeps as c, type SpendIntent as d, type DelegatedPayResult as e, type DelegationScope as f, type GrantPolicyBinding as g, type PaymentAttemptLedger as h, type DelegatedPayerLog as i, type PreparedSettlementTerms as j, type Offer as k, type McpAuthContext as l, type McpTraceHooks as m, type SpendAccountPayDeps as n, createReader as o, type AgentHeldSettlement as p, MCP_TARGET_PRESETS as q, type McpEnvelope as r, type McpEnvelopeEntry as s, type McpServerOptions as t, type McpTarget as u, type McpTraceContext as v, type McpTraceRuntime as w, PACKAGE_NAME as x, type PreparedPayment as y, type SpendAccountPrepareResult as z };
package/dist/http.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as handleSuipayMcpHttpRequest } from './http-DRQ838c6.js';
1
+ export { H as countMcpToolCalls, J as handleSuipayMcpHttpRequest, a0 as tooManyToolCalls } from './http-BwtYzkbN.js';
2
2
  import '@modelcontextprotocol/sdk/server/index.js';
3
3
  import '@mysten/sui/keypairs/ed25519';
4
4
  import 'node:crypto';
package/dist/http.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import {
2
- handleSuipayMcpHttpRequest
3
- } from "./chunk-5S4MJN2A.js";
2
+ countMcpToolCalls,
3
+ handleSuipayMcpHttpRequest,
4
+ tooManyToolCalls
5
+ } from "./chunk-FUMH3XYC.js";
4
6
  export {
5
- handleSuipayMcpHttpRequest
7
+ countMcpToolCalls,
8
+ handleSuipayMcpHttpRequest,
9
+ tooManyToolCalls
6
10
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
2
- import { S as SpendAccountSigningRequest, P as PaidHttpRequest, D as DelegatedKeySigner, G as GetObjectJson, a as DelegatedPayerSession, b as DelegatedPayerConfig, c as DelegatedPayerDeps, d as SpendIntent, e as DelegatedPayResult, f as DelegationScope, C as CodeFor, N as NextAction, g as GrantPolicyBinding, h as PaymentAttemptLedger, O as OfferPublicKeySource, i as DelegatedPayerLog, j as PreparedSettlementTerms, X as X402PayProgress, k as Offer, M as McpConfig, l as McpAuthContext, m as McpTraceHooks, n as SpendAccountPayDeps, o as createReader } from './http-DRQ838c6.js';
3
- export { A as AgentHeldResolver, p as AgentHeldSettlement, q as MCP_TARGET_PRESETS, r as McpEnvelope, s as McpEnvelopeEntry, t as McpServerOptions, u as McpTarget, v as McpTraceContext, w as McpTraceRuntime, x as PACKAGE_NAME, y as PreparedPayment, z as SpendAccountPrepareResult, B as SpendAccountPrepareSession, T as TOOLS, E as buildSpendAccountPayKind, F as canonicalMcpRequestId, H as createServer, I as handleSuipayMcpHttpRequest, J as inspectMcpEnvelope, K as loadMcpConfig, L as parseMcpTargetFlag, Q as prepareSpendAccountPayment, R as resetAgentHeldProcessLedger, U as resolveAgentHeldSettlement, V as resolveGrantTarget, W as resolveMcpTarget, Y as sameMcpGateway, Z as traceMcpHttpRequest, _ as verifySpendAccountPayReconstructs } from './http-DRQ838c6.js';
2
+ import { S as SpendAccountSigningRequest, P as PaidHttpRequest, D as DelegatedKeySigner, G as GetObjectJson, a as DelegatedPayerSession, b as DelegatedPayerConfig, c as DelegatedPayerDeps, d as SpendIntent, e as DelegatedPayResult, f as DelegationScope, C as CodeFor, N as NextAction, g as GrantPolicyBinding, h as PaymentAttemptLedger, O as OfferPublicKeySource, i as DelegatedPayerLog, j as PreparedSettlementTerms, X as X402PayProgress, k as Offer, M as McpConfig, l as McpAuthContext, m as McpTraceHooks, n as SpendAccountPayDeps, o as createReader } from './http-BwtYzkbN.js';
3
+ export { A as AgentHeldResolver, p as AgentHeldSettlement, q as MCP_TARGET_PRESETS, r as McpEnvelope, s as McpEnvelopeEntry, t as McpServerOptions, u as McpTarget, v as McpTraceContext, w as McpTraceRuntime, x as PACKAGE_NAME, y as PreparedPayment, z as SpendAccountPrepareResult, B as SpendAccountPrepareSession, T as TOOLS, E as buildSpendAccountPayKind, F as canonicalMcpRequestId, H as countMcpToolCalls, I as createServer, J as handleSuipayMcpHttpRequest, K as inspectMcpEnvelope, L as loadMcpConfig, Q as parseMcpTargetFlag, R as prepareSpendAccountPayment, U as resetAgentHeldProcessLedger, V as resolveAgentHeldSettlement, W as resolveGrantTarget, Y as resolveMcpTarget, Z as sameMcpGateway, _ as traceMcpHttpRequest, $ as verifySpendAccountPayReconstructs } from './http-BwtYzkbN.js';
4
4
  import { SuiGrpcClient } from '@mysten/sui/grpc';
5
5
  import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
6
6
  import '@modelcontextprotocol/sdk/server/index.js';
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  loadBootProfile,
3
3
  main
4
- } from "./chunk-TCPF3ONF.js";
4
+ } from "./chunk-CEZ3NFAR.js";
5
5
  import {
6
6
  MCP_TARGET_PRESETS,
7
7
  PACKAGE_NAME,
8
8
  TOOLS,
9
9
  buildSpendAccountPayKind,
10
10
  canonicalMcpRequestId,
11
+ countMcpToolCalls,
11
12
  createServer,
12
13
  ensureLocalSigningKey,
13
14
  handleSuipayMcpHttpRequest,
@@ -26,13 +27,14 @@ import {
26
27
  settlePreparedMcpPayment,
27
28
  traceMcpHttpRequest,
28
29
  verifySpendAccountPayReconstructs
29
- } from "./chunk-5S4MJN2A.js";
30
+ } from "./chunk-FUMH3XYC.js";
30
31
  export {
31
32
  MCP_TARGET_PRESETS,
32
33
  PACKAGE_NAME,
33
34
  TOOLS,
34
35
  buildSpendAccountPayKind,
35
36
  canonicalMcpRequestId,
37
+ countMcpToolCalls,
36
38
  createServer,
37
39
  ensureLocalSigningKey,
38
40
  handleSuipayMcpHttpRequest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay-mcp",
3
- "version": "0.3.0-dev.34",
3
+ "version": "0.3.0-dev.36",
4
4
  "type": "module",
5
5
  "description": "SuiPay MCP — pay MPP-gated APIs from a spend-account grant with an agent-held delegate key.",
6
6
  "repository": {
@@ -42,8 +42,8 @@
42
42
  "tsup": "^8.0.0",
43
43
  "typescript": "^6.0.3",
44
44
  "vitest": "^4.1.10",
45
- "@cmdoss/suipay-sdk": "0.1.0",
46
- "@cmdoss/suipay-core": "0.1.0"
45
+ "@cmdoss/suipay-core": "0.1.0",
46
+ "@cmdoss/suipay-sdk": "0.1.0"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsup",