@haven_ai/mcp 0.3.0-alpha.0 → 0.5.0-alpha.1

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, isSupportedNodeVersion, unsupportedNodeVersionMessage, HavenPaymentStateError, HavenSigningError, HavenApiError, AgentPaymentNextAction, HavenError, AgentPaymentFailureCode, verifyPaymentReceipt, discoverMerchantMcpUrl, sameUrl } from '@haven_ai/sdk';
4
+ import { composeDescription, toolDescriptions as toolDescriptions$1, HavenClient, havenClientIdentity, isSupportedNodeVersion, unsupportedNodeVersionMessage, HavenPaymentStateError, HavenSigningError, HavenApiError, AgentPaymentNextAction, HavenError, AgentPaymentFailureCode, verifyPaymentReceipt, discoverMerchantMcpUrl, sameUrl } 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';
@@ -302,11 +302,14 @@ var toolSchemas = {
302
302
  website: z.string().optional()
303
303
  },
304
304
  haven_list_receipts: {
305
- limit: z.number().int().min(1).max(100).optional()
305
+ limit: z.number().int().min(1).max(100).optional(),
306
+ /** #3128: the previous page's next_cursor (a receipt id). */
307
+ cursor: z.string().min(1).optional()
306
308
  },
307
309
  haven_verify_receipt: {
308
310
  receipt: z.unknown()
309
311
  }
312
+ // #3101: keys survive on the type (see the hosted server's contracts.ts).
310
313
  };
311
314
  var toolDescriptions = {
312
315
  haven_send: composeDescription(toolDescriptions$1.send),
@@ -497,12 +500,32 @@ function createToolHandlers(haven) {
497
500
  source: entry.source,
498
501
  domain_verified: entry.domainVerified,
499
502
  verified_payable: entry.verifiedPayable,
500
- // Which Haven pay tool reaches this entry from the local MCP surface.
503
+ // Which Haven pay tool reaches this entry from the local MCP surface,
504
+ // and — #3100 (epic #3105, decision 4) — the arguments that tool
505
+ // accepts VERBATIM, spelled in ITS vocabulary (`merchant_url`, not
506
+ // the entry's `resource_url`). The local surface keeps pointing at
507
+ // its pay tools: they need no cap, so a verbatim hint exists.
501
508
  // #1328: the 'mpp' rail's only-ever catalog row (the Haven MPP demo
502
509
  // resource) is delisted with the mpp_demo retirement, so this
503
510
  // fallback is unreachable today; it stays x402 rather than naming a
504
511
  // deleted tool in case a future non-demo 'mpp' rail entry appears.
505
- suggested_tool: entry.protocol === "mcp" ? "haven_pay_mcp_tool" : "haven_pay_x402"
512
+ // A row without a tool_name cannot get a verbatim hint —
513
+ // haven_pay_mcp_tool requires tool_name — so it gets the REASON
514
+ // instead of a hint its own tool refuses (haven-reviewer on #3113;
515
+ // the epic's "omitted + reason, never null" shape, decision 3).
516
+ ...entry.protocol === "mcp" ? entry.toolName ? {
517
+ suggested_tool: "haven_pay_mcp_tool",
518
+ suggested_arguments: {
519
+ merchant_url: entry.resourceUrl,
520
+ tool_name: entry.toolName,
521
+ ...entry.toolArguments ? { arguments: entry.toolArguments } : {}
522
+ }
523
+ } : {
524
+ suggested_tool_omitted_reason: "this catalog row carries no tool_name, which haven_pay_mcp_tool requires; read the merchant's tool list yourself, then call haven_pay_mcp_tool with merchant_url, tool_name and arguments"
525
+ } : {
526
+ suggested_tool: "haven_pay_x402",
527
+ suggested_arguments: { url: entry.resourceUrl }
528
+ }
506
529
  }));
507
530
  });
508
531
  },
@@ -522,7 +545,7 @@ function createToolHandlers(haven) {
522
545
  },
523
546
  haven_list_receipts: async (input) => {
524
547
  const args = objectInput("haven_list_receipts", input);
525
- return runTool(async () => haven.listReceipts({ limit: args.limit }));
548
+ return runTool(async () => haven.listReceiptsPage({ limit: args.limit, cursor: args.cursor }));
526
549
  },
527
550
  haven_verify_receipt: async (input) => {
528
551
  const args = objectInput("haven_verify_receipt", input);
@@ -667,7 +690,11 @@ function normalizeError(err) {
667
690
  message: err.message,
668
691
  statusCode: err.statusCode,
669
692
  nextAction: err.nextAction,
670
- retry_with_new_quote: err.retryWithNewQuote
693
+ next_action: err.nextAction,
694
+ retry_with_new_quote: err.retryWithNewQuote,
695
+ // #3103: the local runtime's one decision site — no tool can act until
696
+ // the merchant recovers; the message carries retry_after_s.
697
+ next_tool_omitted_reason: "the merchant needs to recover first; re-quote after the retry_after_s in the message"
671
698
  };
672
699
  }
673
700
  if (err instanceof HavenPaymentStateError) {
@@ -680,6 +707,7 @@ function normalizeError(err) {
680
707
  status: err.status,
681
708
  phase: err.phase,
682
709
  nextAction: err.nextAction,
710
+ next_action: err.nextAction,
683
711
  resume_state: err.resumeState,
684
712
  body: err.body
685
713
  };
@@ -701,6 +729,10 @@ function normalizeError(err) {
701
729
  paymentId: err.paymentId,
702
730
  phase: stringOrUndefined(body?.phase),
703
731
  nextAction: stringOrUndefined(body?.nextAction) ?? stringOrUndefined(body?.next_action) ?? AgentPaymentNextAction.StopAndTellUser,
732
+ next_action: stringOrUndefined(body?.nextAction) ?? stringOrUndefined(body?.next_action) ?? AgentPaymentNextAction.StopAndTellUser,
733
+ // #3303: a backend refusal that already names why no tool follows (the
734
+ // 426 `client_outdated` does) keeps that reason at the top level.
735
+ ...typeof body?.next_tool_omitted_reason === "string" ? { next_tool_omitted_reason: body.next_tool_omitted_reason } : {},
704
736
  body: err.body
705
737
  };
706
738
  }
@@ -717,7 +749,11 @@ function normalizeError(err) {
717
749
  success: false,
718
750
  code: "UNKNOWN_ERROR",
719
751
  message: err instanceof Error ? err.message : String(err),
720
- nextAction: AgentPaymentNextAction.StopAndTellUser
752
+ nextAction: AgentPaymentNextAction.StopAndTellUser,
753
+ next_action: AgentPaymentNextAction.StopAndTellUser,
754
+ // #3103: the second local decision site — nothing structured can follow an
755
+ // error this runtime did not recognise.
756
+ next_tool_omitted_reason: "an error this runtime does not recognise; tell the user what the message says"
721
757
  };
722
758
  }
723
759
  function stringOrUndefined(value) {
@@ -749,7 +785,7 @@ function renderConsentBlock(input, hash) {
749
785
  ];
750
786
  if (input.apiUrl) lines.push(`Haven API: ${input.apiUrl}`);
751
787
  if (input.agentId) lines.push(`Agent ID: ${input.agentId}`);
752
- if (input.accountAddress) lines.push(`Haven wallet (Safe): ${input.accountAddress}`);
788
+ if (input.accountAddress) lines.push(`Haven wallet: ${input.accountAddress}`);
753
789
  if (input.delegateAddress) lines.push(`Delegate (local signer): ${input.delegateAddress}`);
754
790
  if (typeof input.chainId === "number") lines.push(`Chain ID: ${input.chainId}`);
755
791
  lines.push("");
@@ -908,12 +944,15 @@ async function resolveHavenClient(options = {}) {
908
944
  const client = new HavenClient({
909
945
  apiKey: credentials.apiKey,
910
946
  delegateKey: credentials.delegateKey,
911
- baseUrl: credentials.apiUrl
947
+ baseUrl: credentials.apiUrl,
948
+ // #3303: name this package, not the SDK inside it, so the backend's
949
+ // update hint and refusal speak about what the user actually installed.
950
+ clientIdentity: havenClientIdentity(MCP_NAME, MCP_VERSION)
912
951
  });
913
952
  return { client, credentials };
914
953
  }
915
954
  var MCP_NAME = "@haven_ai/mcp";
916
- var MCP_VERSION = "0.3.0-alpha.0";
955
+ var MCP_VERSION = "0.5.0-alpha.1";
917
956
  var MCP_INSTRUCTIONS = [
918
957
  "Haven local MCP server: signs in-process with the delegate key it holds on",
919
958
  "this machine \u2014 the key never leaves this process. Call haven_get_agent",
@@ -922,7 +961,8 @@ var MCP_INSTRUCTIONS = [
922
961
  "",
923
962
  "To pay: haven_discover_tools to find a payable service, then",
924
963
  "haven_pay_mcp_tool for MCP merchants or haven_pay_x402 for any x402",
925
- "paywall. Tool responses carry nextAction \u2014 follow it; description prose",
964
+ "paywall. Tool responses carry next_action (nextAction is the same value, kept one more",
965
+ "release) and, when no tool follows, next_tool_omitted_reason \u2014 follow them; description prose",
926
966
  "is fallback, not the source of truth.",
927
967
  "",
928
968
  "A payment outside the agent budget is declined before any money moves. Haven",
@@ -949,7 +989,7 @@ function buildMcpServer(haven) {
949
989
  toolSchemas[name],
950
990
  async (args) => haven.withRequestContext(
951
991
  { "X-Haven-MCP-Tool": name },
952
- async () => toMcpResult(await handlers[name](args))
992
+ async () => toMcpResult(withClientUpdate(await handlers[name](args), haven.clientUpdate()))
953
993
  )
954
994
  );
955
995
  }
@@ -999,6 +1039,10 @@ async function runConsentGate(haven, credentials, options) {
999
1039
  writeAck: options.writeAck
1000
1040
  });
1001
1041
  }
1042
+ function withClientUpdate(payload, hint) {
1043
+ if (!hint || payload.client_update) return payload;
1044
+ return { ...payload, client_update: hint };
1045
+ }
1002
1046
  function toMcpResult(payload) {
1003
1047
  return {
1004
1048
  isError: !payload.success,