@haven_ai/mcp 0.0.0-dev.202610142033.0d2f50f → 0.0.0-dev.202610151444.5ef2d94

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
@@ -105,6 +105,44 @@ Environment variable form:
105
105
  }
106
106
  ```
107
107
 
108
+ ## Per-chain RPC endpoints
109
+
110
+ When an x402 payment hits an idempotency collision, the server can tell a
111
+ finished payment from a stuck one only by reading the agent delegate's balance
112
+ on chain. Without an RPC endpoint it cannot, so every collision is refused as
113
+ `unverifiable`, including the recoverable case where the delegate is still
114
+ funded and the payment could resume.
115
+
116
+ Give the server a read-only RPC endpoint per chain and it can check:
117
+
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "haven": {
122
+ "command": "npx",
123
+ "args": ["@haven_ai/mcp"],
124
+ "env": {
125
+ "HAVEN_CREDENTIALS": "/absolute/path/to/haven-agent.json",
126
+ "HAVEN_RPC_URL_8453": "https://your-rpc.example/v3/key",
127
+ "HAVEN_RPC_URL_84532": "https://your-rpc.example/sepolia/v3/key"
128
+ }
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ One variable per chain: the suffix is the chain id (`8453` is Base mainnet,
135
+ `84532` is Base Sepolia). An unset variable changes nothing: collisions are
136
+ refused exactly as before. A value whose suffix is not a positive integer is
137
+ ignored, and a malformed or unreachable URL degrades to the same refusal.
138
+ Nothing is written to stdout in any of these cases, because stdout is the
139
+ protocol channel.
140
+
141
+ With an endpoint wired for the payment's chain, a collision where the delegate
142
+ is still funded resumes: the balance says the merchant never pulled the
143
+ payment, so the server mints a fresh authorization. A drained delegate still
144
+ refuses, with a settled basis, because the payment already completed.
145
+
108
146
  ## Tools
109
147
 
110
148
  - `haven_quote_x402`
package/dist/cli.cjs CHANGED
@@ -238,6 +238,18 @@ async function warnIfCredentialFilePermissive(path, log = (message) => process.s
238
238
  );
239
239
  }
240
240
  }
241
+ function chainRpcsFromEnv(env) {
242
+ const chainRpcs = {};
243
+ for (const [name, value] of Object.entries(env)) {
244
+ const match = /^HAVEN_RPC_URL_(\d+)$/.exec(name);
245
+ if (!match) continue;
246
+ const chainId = Number.parseInt(match[1], 10);
247
+ if (!Number.isSafeInteger(chainId) || chainId <= 0) continue;
248
+ const url = value?.trim();
249
+ if (url) chainRpcs[chainId] = url;
250
+ }
251
+ return chainRpcs;
252
+ }
241
253
  var TASK_BUDGET_MIN_SIGNER_VERSION = "0.6.0-alpha.0";
242
254
  var SIGNER_CAPABILITY_KEY = "haven/signer-compatibility";
243
255
  function taskSignerCompatibilityNotice() {
@@ -250,6 +262,20 @@ function taskSignerCompatibilityNotice() {
250
262
  };
251
263
  }
252
264
  var headersSchema = v3.z.record(v3.z.string(), v3.z.string()).optional();
265
+ function selectQuoteOption(accepts, agent) {
266
+ if (agent.executionRail === "delegation") {
267
+ const erc7710 = sdk.selectErc7710PaymentOption(accepts);
268
+ if (erc7710) return erc7710;
269
+ }
270
+ return sdk.selectStandardPaymentOption(accepts);
271
+ }
272
+ function humanDecimalToAtomic(human, decimals) {
273
+ const match = /^([0-9]+)(?:\.([0-9]+))?$/.exec(human);
274
+ if (!match) return null;
275
+ const fraction = match[2] ?? "";
276
+ if (fraction.length > decimals) return null;
277
+ return BigInt(match[1] + fraction.padEnd(decimals, "0"));
278
+ }
253
279
  var toolSchemas = {
254
280
  haven_send: {
255
281
  asset: v3.z.enum(["ETH", "USDC"]),
@@ -281,6 +307,17 @@ var toolSchemas = {
281
307
  headers: headersSchema,
282
308
  body: v3.z.string().optional(),
283
309
  idempotency_key: v3.z.string().optional(),
310
+ /**
311
+ * #3967: the price the agent EXPECTS, in whole tokens ("0.10" = 0.1 USDC),
312
+ * compared against the amount of the option pay will actually select. A
313
+ * mismatch stops the agent — the same stop signals the hosted quote
314
+ * carries. Local parity: a hosted-only input would split the two tools'
315
+ * contracts. Same shape and name as the hosted surface's.
316
+ */
317
+ expected_amount: v3.z.string().regex(
318
+ /^[0-9]+(\.[0-9]+)?$/,
319
+ 'expected_amount must be a plain decimal amount in whole tokens, e.g. "0.10"'
320
+ ).optional(),
284
321
  /** REMOVED (#3411): declared only so the resolver can refuse it by name, never accepted. */
285
322
  idempotencyKey: v3.z.string().optional().describe("REMOVED (#3411): refused \u2014 send idempotency_key")
286
323
  },
@@ -627,8 +664,39 @@ function createToolHandlers(haven) {
627
664
  const pf = preflight("haven_quote_x402", input);
628
665
  if ("success" in pf) return pf;
629
666
  const { args, warnings } = pf;
667
+ const agentPromise = args.expected_amount !== void 0 ? haven.getAgent().then(
668
+ (a) => a,
669
+ () => void 0
670
+ ) : null;
630
671
  try {
631
672
  const data = await haven.quoteX402(args.url, requestInit(args), { idempotencyKey: args.resolvedIdempotencyKey });
673
+ if (args.expected_amount !== void 0) {
674
+ const agent = agentPromise ? await agentPromise : void 0;
675
+ const option = agent ? selectQuoteOption(data.paymentRequired.accepts, agent) : null;
676
+ if (option && data.decimals !== null) {
677
+ const expectedAtomic = humanDecimalToAtomic(args.expected_amount, data.decimals);
678
+ let optionAmount = null;
679
+ try {
680
+ optionAmount = BigInt(sdk.x402AuthorizationAmount(option));
681
+ } catch {
682
+ optionAmount = null;
683
+ }
684
+ if (optionAmount !== null && expectedAtomic !== null) {
685
+ const priceDiffers = optionAmount !== expectedAtomic;
686
+ const payload = {
687
+ ...data,
688
+ price_differs_from_expected: priceDiffers,
689
+ ...priceDiffers ? {
690
+ safe_to_continue: false,
691
+ next_action: sdk.AgentPaymentNextAction.StopAndTellUser,
692
+ next_tool_omitted_reason: "no Haven tool follows: the quoted price does not match the stated expectation \u2014 the user decides before any payment",
693
+ reason: `The merchant's quoted price (${data.amount} ${data.asset}) does not match the expected price (${args.expected_amount}) stated with this quote. Stop and tell the user before any payment; do not re-quote, re-pay, or poll. If the x402 challenge itself is wrong and nothing has been paid via x402 on this invoice, the invoice's own deposit address MAY be an alternative \u2014 but only with the user's explicit go-ahead, never automatically, and never once anything has been paid via x402.`
694
+ } : {}
695
+ };
696
+ return warnings.length > 0 ? { success: true, data: payload, warnings } : { success: true, data: payload };
697
+ }
698
+ }
699
+ }
632
700
  return warnings.length > 0 ? { success: true, data, warnings } : { success: true, data };
633
701
  } catch (err) {
634
702
  return normalizeError(err);
@@ -1326,10 +1394,14 @@ async function resolveHavenClient(options = {}) {
1326
1394
  signerPath: options.signerPath
1327
1395
  } : void 0;
1328
1396
  const credentials = options.credentials ?? await loadCredentials(credentialSource);
1397
+ const chainRpcs = chainRpcsFromEnv(process.env);
1329
1398
  const client = new sdk.HavenClient({
1330
1399
  apiKey: credentials.apiKey,
1331
1400
  delegateKey: credentials.delegateKey,
1332
1401
  baseUrl: credentials.apiUrl,
1402
+ // Only added when non-empty so the unset-variable construction is byte-for-byte
1403
+ // today's: the SDK defaults `chainRpcs` to `{}` either way.
1404
+ ...Object.keys(chainRpcs).length > 0 ? { chainRpcs } : {},
1333
1405
  // #3303: name this package, not the SDK inside it, so the backend's
1334
1406
  // update hint and refusal speak about what the user actually installed.
1335
1407
  clientIdentity: sdk.havenClientIdentity(MCP_NAME, MCP_VERSION)
@@ -1337,7 +1409,7 @@ async function resolveHavenClient(options = {}) {
1337
1409
  return { client, credentials };
1338
1410
  }
1339
1411
  var MCP_NAME = "@haven_ai/mcp";
1340
- var MCP_VERSION = "0.0.0-dev.202610142033.0d2f50f";
1412
+ var MCP_VERSION = "0.0.0-dev.202610151444.5ef2d94";
1341
1413
  var MCP_INSTRUCTIONS = [
1342
1414
  "Haven local MCP server: signs in-process with the delegate key it holds on",
1343
1415
  "this machine \u2014 the key never leaves this process. Call haven_get_agent",