@haven_ai/mcp 0.9.0-alpha.0 → 0.10.0-alpha.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/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
- import { composeDescription, toolDescriptions as toolDescriptions$1, HavenClient, havenClientIdentity, isSupportedNodeVersion, unsupportedNodeVersionMessage, resolveTokenBySymbol, formatTokenAmount, HavenApiError, HavenPaymentStateError, HavenSigningError, AgentPaymentNextAction, HavenError, AgentPaymentFailureCode, verifyPaymentReceipt, discoverMerchantMcpUrl, sameUrl, resolveTokenFromAddress, TASK_SIGN_CONTEXT_VERSION, connectorUpgradeCommand } from '@haven_ai/sdk';
4
+ import { composeDescription, toolDescriptions as toolDescriptions$1, HavenClient, havenClientIdentity, isSupportedNodeVersion, unsupportedNodeVersionMessage, resolveTokenBySymbol, formatTokenAmount, HavenApiError, HavenPaymentStateError, HavenSigningError, AgentPaymentNextAction, HavenError, AgentPaymentFailureCode, verifyPaymentReceipt, catalogFundingLegExpected, discoverMerchantMcpUrl, sameUrl, resolveTokenFromAddress, TASK_SIGN_CONTEXT_VERSION, connectorUpgradeCommand } from '@haven_ai/sdk';
5
5
  import { readFile, mkdir, writeFile, stat } from 'fs/promises';
6
6
  import { z } from 'zod/v3';
7
7
  import { createHash } from 'crypto';
@@ -725,6 +725,10 @@ function createToolHandlers(haven) {
725
725
  price_atomic: entry.priceAtomic,
726
726
  asset: entry.asset,
727
727
  network: entry.network,
728
+ // #3839: same hint the hosted surface emits — a catalog hint, the
729
+ // live quote stays authoritative; "unknown" when nothing is recorded.
730
+ asset_transfer_methods: entry.assetTransferMethods ?? null,
731
+ funding_leg_expected: catalogFundingLegExpected(entry.assetTransferMethods),
728
732
  status: entry.status,
729
733
  verified_at: entry.verifiedAt,
730
734
  source: entry.source,
@@ -990,17 +994,26 @@ function parseMaybeJson(text) {
990
994
  return text;
991
995
  }
992
996
  }
997
+ var MERCHANT_OUT_OF_GAS_REASON = "settlement_wallet_out_of_gas";
998
+ function merchantOutOfGasMessage(settlementsRemaining, failFloor) {
999
+ const remaining = typeof settlementsRemaining === "number" ? settlementsRemaining : null;
1000
+ const floor = typeof failFloor === "number" ? failFloor : null;
1001
+ const figures = remaining !== null && floor !== null ? ` It has gas for ${remaining} more settlement${remaining === 1 ? "" : "s"} and refuses new payments below ${floor} (settlements_remaining: ${remaining}, fail_floor: ${floor}).` : remaining !== null ? ` settlements_remaining: ${remaining}.` : "";
1002
+ return `The merchant refused this call: its settlement wallet is out of gas (reason_code: ${MERCHANT_OUT_OF_GAS_REASON}).` + figures + " No payment was created. The merchant's operator must top up its settlement wallet; until then every retry is refused again. Tell the user, and re-quote once the merchant has been topped up.";
1003
+ }
993
1004
  var MerchantNotReadyError = class extends Error {
1005
+ constructor(message, nextToolOmittedReason = "the merchant needs to recover first; re-quote after the retry_after_s in the message") {
1006
+ super(message);
1007
+ this.nextToolOmittedReason = nextToolOmittedReason;
1008
+ this.name = "MerchantNotReadyError";
1009
+ }
1010
+ nextToolOmittedReason;
994
1011
  code = AgentPaymentFailureCode.MerchantNotReady;
995
1012
  statusCode = 503;
996
1013
  nextAction = AgentPaymentNextAction.StopAndTellUser;
997
1014
  // Genuinely retryable — unlike a rejection, nothing about THIS call was
998
1015
  // wrong; the merchant's own wallet needs to recover first.
999
1016
  retryWithNewQuote = true;
1000
- constructor(message) {
1001
- super(message);
1002
- this.name = "MerchantNotReadyError";
1003
- }
1004
1017
  };
1005
1018
  async function merchantNotReadyErrorFor(response) {
1006
1019
  if (response.status !== 503) return null;
@@ -1013,7 +1026,14 @@ async function merchantNotReadyErrorFor(response) {
1013
1026
  if (!body || typeof body !== "object" || body.error !== "merchant_not_ready") {
1014
1027
  return null;
1015
1028
  }
1016
- const { reason_code, settlements_remaining, retry_after_s } = body;
1029
+ const { reason_code, settlements_remaining, fail_floor, retry_after_s } = body;
1030
+ if (reason_code === MERCHANT_OUT_OF_GAS_REASON) {
1031
+ return new MerchantNotReadyError(
1032
+ merchantOutOfGasMessage(settlements_remaining, fail_floor),
1033
+ // Same reason the hosted runtime returns (support/mcp-context.ts).
1034
+ "the merchant's operator must top up its settlement wallet first; re-quote after that"
1035
+ );
1036
+ }
1017
1037
  return new MerchantNotReadyError(
1018
1038
  "The merchant refused this call: it cannot settle a payment right now" + (typeof reason_code === "string" ? ` (reason_code: ${reason_code})` : "") + (typeof settlements_remaining === "number" ? `, settlements_remaining: ${settlements_remaining}` : "") + ". No payment was created." + (typeof retry_after_s === "number" ? ` Retry after approximately ${retry_after_s}s.` : " This is often transient; retry later.")
1019
1039
  );
@@ -1034,8 +1054,10 @@ function normalizeError(err) {
1034
1054
  next_action: err.nextAction,
1035
1055
  retry_with_new_quote: err.retryWithNewQuote,
1036
1056
  // #3103: the local runtime's one decision site — no tool can act until
1037
- // the merchant recovers; the message carries retry_after_s.
1038
- next_tool_omitted_reason: "the merchant needs to recover first; re-quote after the retry_after_s in the message"
1057
+ // the merchant recovers. The reason rides the error (#3834): the
1058
+ // generic one points at the message's retry_after_s, the out-of-gas
1059
+ // one at the operator top-up.
1060
+ next_tool_omitted_reason: err.nextToolOmittedReason
1039
1061
  };
1040
1062
  }
1041
1063
  if (err instanceof HavenPaymentStateError) {
@@ -1313,7 +1335,7 @@ async function resolveHavenClient(options = {}) {
1313
1335
  return { client, credentials };
1314
1336
  }
1315
1337
  var MCP_NAME = "@haven_ai/mcp";
1316
- var MCP_VERSION = "0.9.0-alpha.0";
1338
+ var MCP_VERSION = "0.10.0-alpha.0";
1317
1339
  var MCP_INSTRUCTIONS = [
1318
1340
  "Haven local MCP server: signs in-process with the delegate key it holds on",
1319
1341
  "this machine \u2014 the key never leaves this process. Call haven_get_agent",