@capxul/mcp 2.5.4 → 2.5.5

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.
Files changed (2) hide show
  1. package/dist/main.mjs +213 -10
  2. package/package.json +5 -5
package/dist/main.mjs CHANGED
@@ -7,7 +7,7 @@ import { createHash, randomBytes } from "node:crypto";
7
7
  import { createServer } from "node:http";
8
8
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
9
9
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
- import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, isAddress, isHex, keccak256, pad, padHex, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature, toHex, zeroAddress } from "viem";
10
+ import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeErrorResult, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, isAddress, isHex, keccak256, pad, padHex, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature, toHex, zeroAddress } from "viem";
11
11
  import { z } from "zod";
12
12
  import { Cause, Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schedule, Schema, SchemaGetter, SchemaIssue, SchemaParser, Scope, Struct, Tracer } from "effect";
13
13
  import { privateKeyToAccount, toAccount } from "viem/accounts";
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
240
240
  }
241
241
  //#endregion
242
242
  //#region package.json
243
- var version$2 = "2.5.4";
243
+ var version$2 = "2.5.5";
244
244
  //#endregion
245
245
  //#region ../../packages/errors/src/errors.ts
246
246
  const CAPXUL_ERROR_CODES = [
@@ -1491,6 +1491,24 @@ const CAPXUL_PAYMENTS_V2_ABI = [
1491
1491
  internalType: "bytes32"
1492
1492
  }]
1493
1493
  },
1494
+ {
1495
+ type: "error",
1496
+ name: "TokenCallReturnedFalse",
1497
+ inputs: [{
1498
+ name: "token",
1499
+ type: "address",
1500
+ internalType: "address"
1501
+ }]
1502
+ },
1503
+ {
1504
+ type: "error",
1505
+ name: "TokenHasNoCode",
1506
+ inputs: [{
1507
+ name: "token",
1508
+ type: "address",
1509
+ internalType: "address"
1510
+ }]
1511
+ },
1494
1512
  {
1495
1513
  type: "error",
1496
1514
  name: "ZeroAddress",
@@ -1513,7 +1531,7 @@ const CAPXUL_PAYMENTS_V2_ABI = [
1513
1531
  }
1514
1532
  ];
1515
1533
  /** Immutable CapxulPaymentsV2 deployment on Base Sepolia. */
1516
- const CAPXUL_PAYMENTS_V2_ADDRESS = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
1534
+ const CAPXUL_PAYMENTS_V2_ADDRESS = "0x7a5c25aB7ce91d7a475B71cd1ec33E230291f8a4";
1517
1535
  //#endregion
1518
1536
  //#region ../../packages/config/src/route.ts
1519
1537
  /** USDX on Base Sepolia — the only settlement token in v1. */
@@ -2774,7 +2792,7 @@ const EVM_ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
2774
2792
  * envelopes carrying it — so it MUST stay byte-identical across both. Exported
2775
2793
  * once here to remove the drift risk of a mirrored declaration.
2776
2794
  */
2777
- const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
2795
+ const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0x7a5c25aB7ce91d7a475B71cd1ec33E230291f8a4";
2778
2796
  const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
2779
2797
  const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
2780
2798
  const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
@@ -8912,7 +8930,7 @@ async function recoverRawDigestSigner(input) {
8912
8930
  }
8913
8931
  //#endregion
8914
8932
  //#region ../../packages/sdk/package.json
8915
- var version = "2.5.4";
8933
+ var version = "2.5.5";
8916
8934
  //#endregion
8917
8935
  //#region ../../packages/observability/src/engineering.ts
8918
8936
  const ENGINEERING_CAPXUL_ENVS = [
@@ -43332,6 +43350,159 @@ function optionalEnv(name) {
43332
43350
  return value && value.length > 0 ? value : void 0;
43333
43351
  }
43334
43352
  //#endregion
43353
+ //#region ../../packages/backend/convex/_shared/userOperationRevert.ts
43354
+ /** OpenZeppelin v5 ERC-20 errors (ERC-6093). The token contracts on Base Sepolia use them. */
43355
+ const ERC20_ERRORS_ABI = [
43356
+ {
43357
+ type: "error",
43358
+ name: "ERC20InsufficientBalance",
43359
+ inputs: [
43360
+ {
43361
+ name: "sender",
43362
+ type: "address"
43363
+ },
43364
+ {
43365
+ name: "balance",
43366
+ type: "uint256"
43367
+ },
43368
+ {
43369
+ name: "needed",
43370
+ type: "uint256"
43371
+ }
43372
+ ]
43373
+ },
43374
+ {
43375
+ type: "error",
43376
+ name: "ERC20InsufficientAllowance",
43377
+ inputs: [
43378
+ {
43379
+ name: "spender",
43380
+ type: "address"
43381
+ },
43382
+ {
43383
+ name: "allowance",
43384
+ type: "uint256"
43385
+ },
43386
+ {
43387
+ name: "needed",
43388
+ type: "uint256"
43389
+ }
43390
+ ]
43391
+ },
43392
+ {
43393
+ type: "error",
43394
+ name: "ERC20InvalidSender",
43395
+ inputs: [{
43396
+ name: "sender",
43397
+ type: "address"
43398
+ }]
43399
+ },
43400
+ {
43401
+ type: "error",
43402
+ name: "ERC20InvalidReceiver",
43403
+ inputs: [{
43404
+ name: "receiver",
43405
+ type: "address"
43406
+ }]
43407
+ },
43408
+ {
43409
+ type: "error",
43410
+ name: "ERC20InvalidApprover",
43411
+ inputs: [{
43412
+ name: "approver",
43413
+ type: "address"
43414
+ }]
43415
+ },
43416
+ {
43417
+ type: "error",
43418
+ name: "ERC20InvalidSpender",
43419
+ inputs: [{
43420
+ name: "spender",
43421
+ type: "address"
43422
+ }]
43423
+ }
43424
+ ];
43425
+ const REVERT_ABI = [...CAPXUL_PAYMENTS_V2_ABI, ...ERC20_ERRORS_ABI];
43426
+ const REASON_RE = /reason:\s*(0x[0-9a-fA-F]*)/u;
43427
+ const SELECTOR_LENGTH = 10;
43428
+ function stringifyArg(value) {
43429
+ if (typeof value === "bigint") return value.toString(10);
43430
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return String(value);
43431
+ return JSON.stringify(value);
43432
+ }
43433
+ /** Decode revert data. Never throws: an unknown selector yields `name: null`. */
43434
+ function decodeRevertData(data) {
43435
+ const selector = data.length >= SELECTOR_LENGTH ? data.slice(0, SELECTOR_LENGTH) : "0x";
43436
+ if (selector === "0x") return {
43437
+ data,
43438
+ selector,
43439
+ name: null,
43440
+ args: {}
43441
+ };
43442
+ try {
43443
+ const decoded = decodeErrorResult({
43444
+ abi: REVERT_ABI,
43445
+ data
43446
+ });
43447
+ const inputs = decoded.abiItem.type === "error" ? decoded.abiItem.inputs.map((input) => input.name) : [];
43448
+ const args = {};
43449
+ (decoded.args ?? []).forEach((value, index) => {
43450
+ args[inputs[index] ?? String(index)] = stringifyArg(value);
43451
+ });
43452
+ return {
43453
+ data,
43454
+ selector,
43455
+ name: decoded.errorName,
43456
+ args
43457
+ };
43458
+ } catch {
43459
+ return {
43460
+ data,
43461
+ selector,
43462
+ name: null,
43463
+ args: {}
43464
+ };
43465
+ }
43466
+ }
43467
+ /** The revert data a bundler message carries, or null when the message names none. */
43468
+ function revertDataInMessage(message) {
43469
+ const match = REASON_RE.exec(message);
43470
+ return match?.[1] === void 0 ? null : match[1];
43471
+ }
43472
+ /** `ERC20InsufficientBalance(sender=0x…, balance=1000000000, needed=50000000000000)`. */
43473
+ function describeRevert(revert) {
43474
+ if (revert.name === null) return revert.selector === "0x" ? "empty revert" : `unknown selector ${revert.selector}`;
43475
+ const args = Object.entries(revert.args).map(([name, value]) => `${name}=${value}`).join(", ");
43476
+ return `${revert.name}(${args})`;
43477
+ }
43478
+ /** Decode the revert in a bundler error message, or null when there is none. */
43479
+ function decodeUserOperationRevert(message) {
43480
+ const data = revertDataInMessage(message);
43481
+ return data === null ? null : decodeRevertData(data);
43482
+ }
43483
+ /**
43484
+ * A sponsorship failure whose decoded revert is the token's insufficient
43485
+ * balance is a product outcome, not a provider defect: return it as
43486
+ * `INSUFFICIENT_BALANCE` with the token's own numbers. Every other failure
43487
+ * passes through unchanged (an allowance failure is a route bug and stays a
43488
+ * provider error for error tracking).
43489
+ */
43490
+ function typedSponsorshipFailure(error) {
43491
+ if (!(error instanceof CapxulError) || error.details?.revert_name !== "ERC20InsufficientBalance") return error;
43492
+ const args = error.details.revert_args;
43493
+ return new CapxulError("INSUFFICIENT_BALANCE", "Insufficient token balance", {
43494
+ cause: error,
43495
+ details: {
43496
+ asset: "token",
43497
+ available: args?.balance ?? "unknown",
43498
+ required: args?.needed ?? "unknown",
43499
+ sender: args?.sender ?? "unknown",
43500
+ revert: error.details.revert
43501
+ },
43502
+ ...error.correlationId === void 0 ? {} : { correlationId: error.correlationId }
43503
+ });
43504
+ }
43505
+ //#endregion
43335
43506
  //#region ../../packages/backend/convex/_shared/alchemyRpc.ts
43336
43507
  const TX_HASH_HEX = /^0x[0-9a-fA-F]{64}$/;
43337
43508
  const ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
@@ -43426,6 +43597,31 @@ function nodeRpcUrl(chainId) {
43426
43597
  }
43427
43598
  }
43428
43599
  /**
43600
+ * Evidence sizes for a decoded simulation revert (#1685). The bundler message
43601
+ * is provider-controlled: keep the decoded name and selector whole, and cap
43602
+ * every free-form string so one oversized answer cannot inflate an exception
43603
+ * payload. The reporter masks credential-shaped values on top of this.
43604
+ */
43605
+ const REVERT_LINE_MAX = 400;
43606
+ const REVERT_ARG_MAX = 128;
43607
+ const REVERT_DATA_MAX = 522;
43608
+ const BUNDLER_MESSAGE_MAX = 300;
43609
+ function clip(value, max) {
43610
+ return value.length <= max ? value : `${value.slice(0, max)}…(${String(value.length)} chars)`;
43611
+ }
43612
+ function boundedRevertDetails(revert, bundlerMessage) {
43613
+ const args = {};
43614
+ for (const [name, value] of Object.entries(revert.args).slice(0, 8)) args[clip(name, 32)] = clip(value, REVERT_ARG_MAX);
43615
+ return {
43616
+ revert: clip(describeRevert(revert), REVERT_LINE_MAX),
43617
+ revert_name: revert.name,
43618
+ revert_selector: revert.selector,
43619
+ revert_args: args,
43620
+ revert_data: clip(revert.data, REVERT_DATA_MAX),
43621
+ bundler_message: clip(bundlerMessage, BUNDLER_MESSAGE_MAX)
43622
+ };
43623
+ }
43624
+ /**
43429
43625
  * JSON-RPC "limit exceeded". Providers use it for rate limits and the AA
43430
43626
  * Gateway returns it when alto failed while its upstream chain was exhausted
43431
43627
  * (`packages/aa-gateway/src/modules/upstream/types.ts`).
@@ -43523,7 +43719,10 @@ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSign
43523
43719
  if (json.error !== void 0) {
43524
43720
  if (!isValidJsonRpcError(json.error)) throw rpcProviderError(method, "malformed JSON-RPC error", chainId);
43525
43721
  if (json.error.code === RATE_LIMITED_RPC_CODE || RATE_LIMIT_MESSAGE.test(json.error.message)) throw transientProviderError(method, json.error.message, chainId, true);
43526
- throw rpcProviderError(method, method === "eth_sendUserOperation" ? new DefinitiveBundlerJsonRpcRejection() : json.error.message, chainId);
43722
+ const cause = method === "eth_sendUserOperation" ? new DefinitiveBundlerJsonRpcRejection() : json.error.message;
43723
+ const revert = BUNDLER_RPC_METHODS.has(method) ? decodeUserOperationRevert(json.error.message) : null;
43724
+ if (revert !== null) throw Errors.providerError(rpcProviderRole(chainId, method), method, cause, { details: boundedRevertDetails(revert, json.error.message) });
43725
+ throw rpcProviderError(method, cause, chainId);
43527
43726
  }
43528
43727
  if (json.result === void 0) throw rpcProviderError(method, "missing result", chainId);
43529
43728
  return json.result;
@@ -43827,10 +44026,14 @@ async function buildSponsoredSafeUserOp(input) {
43827
44026
  maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas),
43828
44027
  signature: safe4337StubSignature()
43829
44028
  };
43830
- request = await sponsorUserOperation({
43831
- chainId,
43832
- userOp: request
43833
- });
44029
+ try {
44030
+ request = await sponsorUserOperation({
44031
+ chainId,
44032
+ userOp: request
44033
+ });
44034
+ } catch (error) {
44035
+ throw typedSponsorshipFailure(error);
44036
+ }
43834
44037
  if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("account-abstraction", "sponsorUserOperation", "missing paymaster sponsorship");
43835
44038
  const userOp = {
43836
44039
  sender,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "2.5.4",
3
+ "version": "2.5.5",
4
4
  "private": false,
5
5
  "description": "Capxul MCP server for auth, Account readiness, identity, Organizations, relationships, requests, destinations, and testnet funding over Streamable HTTP.",
6
6
  "keywords": [
@@ -47,12 +47,12 @@
47
47
  "typescript": "npm:@typescript/typescript6@6.0.2",
48
48
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
49
49
  "vite-plus": "0.1.23",
50
- "@capxul/backend": "0.2.11",
50
+ "@capxul/backend": "0.2.12",
51
51
  "@capxul/config": "0.2.1",
52
- "@capxul/sdk": "2.5.4",
52
+ "@capxul/sdk": "2.5.5",
53
53
  "@capxul/types": "0.2.1",
54
- "@capxul/typescript-config": "0.0.0",
55
- "@capxul/wire": "0.5.1"
54
+ "@capxul/wire": "0.5.1",
55
+ "@capxul/typescript-config": "0.0.0"
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "vp exec tsx src/main.ts serve",