@gvnrdao/dh-mcp 0.5.9 → 0.5.10

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/boundary.js CHANGED
@@ -42135,11 +42135,10 @@ var World = class {
42135
42135
  const spend = BigInt(p.amountSats);
42136
42136
  const fee = BigInt(p.networkFeeSats);
42137
42137
  const available = this.availableSats(p.positionId);
42138
- if (spend + fee > available) {
42139
- const maxSpend = available > fee ? available - fee : 0n;
42138
+ if (spend > available) {
42140
42139
  return {
42141
42140
  ok: false,
42142
- reason: `withdrawal of ${spend.toString()} sats leaves no room for the ${fee.toString()}-sat network fee (TargetMustLeaveFeeRoom) \u2014 max amountSats now is ${maxSpend.toString()} (destination then receives ${(maxSpend > fee ? maxSpend - fee : 0n).toString()} after the fee)`
42141
+ reason: `withdrawal of ${spend.toString()} sats exceeds the ${available.toString()} sats available (TargetExceedsInputValue) \u2014 max amountSats now is ${available.toString()} (destination then receives ${(available > fee ? available - fee : 0n).toString()} after the fee)`
42143
42142
  };
42144
42143
  }
42145
42144
  const debt = BigInt(pos.debtUcdWei);
@@ -51311,9 +51310,9 @@ var init_deployment_addresses = __esm2({
51311
51310
  reason: "Shared upgrade script: LiquidationManagerModule implementation update"
51312
51311
  },
51313
51312
  BTCSpendAuthorizer: {
51314
- previousImplementation: "0x8775a520cAA18c03Cc3f51ee254cAB830960f80E",
51315
- newImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51316
- upgradedAt: "2026-07-03T20:09:36.466Z",
51313
+ previousImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51314
+ newImplementation: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51315
+ upgradedAt: "2026-09-06T15:03:13.627Z",
51317
51316
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51318
51317
  reason: "Shared upgrade script: BTCSpendAuthorizer implementation update"
51319
51318
  },
@@ -51379,6 +51378,13 @@ var init_deployment_addresses = __esm2({
51379
51378
  upgradedAt: "2026-07-07T16:56:49.844Z",
51380
51379
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51381
51380
  reason: "Shared upgrade script: BitcoinWithdrawalAddressRegistry implementation update"
51381
+ },
51382
+ AgentDelegationRegistry: {
51383
+ previousImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51384
+ newImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51385
+ upgradedAt: "2026-09-06T15:06:02.814Z",
51386
+ upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51387
+ reason: "Reconciled implementation from chain"
51382
51388
  }
51383
51389
  },
51384
51390
  history: {
@@ -51464,7 +51470,7 @@ var init_deployment_addresses = __esm2({
51464
51470
  LIQUIDATION_MANAGER_MODULE: "0xC4AB00f39e7ceD812F5C67058C9fa44e15d40e76",
51465
51471
  LIQUIDATION_MANAGER_MODULE_IMPL: "0xCe7587C47094BBb3dCa13D7a2299Ec9beA6cd759",
51466
51472
  BTC_SPEND_AUTHORIZER: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
51467
- BTC_SPEND_AUTHORIZER_IMPL: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51473
+ BTC_SPEND_AUTHORIZER_IMPL: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51468
51474
  UPGRADE_VALIDATOR: "0x592e650edD9bA26ecc407989fdd6F9cdcDeC27A6",
51469
51475
  UPGRADE_VALIDATOR_IMPL: "0x9E70e1D07AB11ac9dD37B67AA091Efe97d7Ed84b",
51470
51476
  BITCOIN_PROVIDER_REGISTRY: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
@@ -58582,12 +58588,12 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
58582
58588
  { txid: spend.txid, vout: spend.vout }
58583
58589
  );
58584
58590
  }
58585
- if (spend.targetAmount >= spend.satoshis) {
58591
+ if (spend.targetAmount > spend.satoshis) {
58586
58592
  return {
58587
58593
  spend,
58588
58594
  status: "CORRUPT",
58589
58595
  onChainOutputValue,
58590
- reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58596
+ reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58591
58597
  };
58592
58598
  }
58593
58599
  const outspendRes = await httpGetJson(
@@ -42775,11 +42775,10 @@ var World = class {
42775
42775
  const spend = BigInt(p.amountSats);
42776
42776
  const fee = BigInt(p.networkFeeSats);
42777
42777
  const available = this.availableSats(p.positionId);
42778
- if (spend + fee > available) {
42779
- const maxSpend = available > fee ? available - fee : 0n;
42778
+ if (spend > available) {
42780
42779
  return {
42781
42780
  ok: false,
42782
- reason: `withdrawal of ${spend.toString()} sats leaves no room for the ${fee.toString()}-sat network fee (TargetMustLeaveFeeRoom) \u2014 max amountSats now is ${maxSpend.toString()} (destination then receives ${(maxSpend > fee ? maxSpend - fee : 0n).toString()} after the fee)`
42781
+ reason: `withdrawal of ${spend.toString()} sats exceeds the ${available.toString()} sats available (TargetExceedsInputValue) \u2014 max amountSats now is ${available.toString()} (destination then receives ${(available > fee ? available - fee : 0n).toString()} after the fee)`
42783
42782
  };
42784
42783
  }
42785
42784
  const debt = BigInt(pos.debtUcdWei);
@@ -51960,9 +51959,9 @@ var init_deployment_addresses = __esm2({
51960
51959
  reason: "Shared upgrade script: LiquidationManagerModule implementation update"
51961
51960
  },
51962
51961
  BTCSpendAuthorizer: {
51963
- previousImplementation: "0x8775a520cAA18c03Cc3f51ee254cAB830960f80E",
51964
- newImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51965
- upgradedAt: "2026-07-03T20:09:36.466Z",
51962
+ previousImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51963
+ newImplementation: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51964
+ upgradedAt: "2026-09-06T15:03:13.627Z",
51966
51965
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51967
51966
  reason: "Shared upgrade script: BTCSpendAuthorizer implementation update"
51968
51967
  },
@@ -52028,6 +52027,13 @@ var init_deployment_addresses = __esm2({
52028
52027
  upgradedAt: "2026-07-07T16:56:49.844Z",
52029
52028
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
52030
52029
  reason: "Shared upgrade script: BitcoinWithdrawalAddressRegistry implementation update"
52030
+ },
52031
+ AgentDelegationRegistry: {
52032
+ previousImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
52033
+ newImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
52034
+ upgradedAt: "2026-09-06T15:06:02.814Z",
52035
+ upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
52036
+ reason: "Reconciled implementation from chain"
52031
52037
  }
52032
52038
  },
52033
52039
  history: {
@@ -52113,7 +52119,7 @@ var init_deployment_addresses = __esm2({
52113
52119
  LIQUIDATION_MANAGER_MODULE: "0xC4AB00f39e7ceD812F5C67058C9fa44e15d40e76",
52114
52120
  LIQUIDATION_MANAGER_MODULE_IMPL: "0xCe7587C47094BBb3dCa13D7a2299Ec9beA6cd759",
52115
52121
  BTC_SPEND_AUTHORIZER: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
52116
- BTC_SPEND_AUTHORIZER_IMPL: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
52122
+ BTC_SPEND_AUTHORIZER_IMPL: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
52117
52123
  UPGRADE_VALIDATOR: "0x592e650edD9bA26ecc407989fdd6F9cdcDeC27A6",
52118
52124
  UPGRADE_VALIDATOR_IMPL: "0x9E70e1D07AB11ac9dD37B67AA091Efe97d7Ed84b",
52119
52125
  BITCOIN_PROVIDER_REGISTRY: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
@@ -59231,12 +59237,12 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
59231
59237
  { txid: spend.txid, vout: spend.vout }
59232
59238
  );
59233
59239
  }
59234
- if (spend.targetAmount >= spend.satoshis) {
59240
+ if (spend.targetAmount > spend.satoshis) {
59235
59241
  return {
59236
59242
  spend,
59237
59243
  status: "CORRUPT",
59238
59244
  onChainOutputValue,
59239
- reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
59245
+ reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
59240
59246
  };
59241
59247
  }
59242
59248
  const outspendRes = await httpGetJson(
@@ -82744,7 +82750,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
82744
82750
  positionId: positionIdSchema,
82745
82751
  btcAddress: import_zod.z.string().min(1).describe("Destination BTC address (must match the configured BTC network)"),
82746
82752
  amountSats: import_zod.z.number().int().positive().describe(
82747
- "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. You cannot spend the whole balance \u2014 the vault must keep room for the fee (TargetMustLeaveFeeRoom), so max amountSats = available \u2212 fee and a withdrawal always leaves fee-sized dust behind."
82753
+ "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. amountSats may be up to the whole available balance (a full sweep leaves 0 sats; anything above available reverts TargetExceedsInputValue). position_status.maxWithdrawableSats is a ready-to-use value that already leaves the default fee aside."
82748
82754
  ),
82749
82755
  networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); deducted FROM amountSats, not added on top"),
82750
82756
  confirmed: confirmedSchema
@@ -83723,7 +83729,7 @@ Connections / Connected sites).`,
83723
83729
  reduced by unused origination-fee credit from the current term.
83724
83730
  6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
83725
83731
  BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
83726
- The vault always keeps room for the network fee (you cannot drain to zero).
83732
+ amountSats is gross (fee comes out of it) and may be the whole available balance.
83727
83733
  7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
83728
83734
  \`position_events\` (history), \`btc_price\`, \`protocol_status\`.
83729
83735
 
@@ -84377,7 +84383,7 @@ function registerBoundaryInfoResource(server, getB) {
84377
84383
  }
84378
84384
 
84379
84385
  // src/server.ts
84380
- var SERVER_VERSION = "0.5.3";
84386
+ var SERVER_VERSION = "0.5.9";
84381
84387
  var SERVER_INSTRUCTIONS = "Diamond Hands MCP \u2014 Bitcoin-collateralized borrowing. Before promising ANY flow, read the boundary://info resource and honor its `capabilities` block: it states which network this server is on, whether money is real (practiceWorld), whether writes are enabled (and the true reason when they are not), and which signer modes this build actually offers \u2014 never describe a flow outside it. State the network and whether funds are real when the user first acts. Authorization is chosen by conversation via the signer_setup tool (when listed); writes always require confirmed:true after showing the human-readable card. For walkthroughs consult the guide tool / guide:// resources instead of inventing steps; when a tool refuses, relay its stated reason and remedy \u2014 do not improvise alternatives. When a network_switch tool is listed, the network can change mid-session \u2014 after ANY switch, re-read boundary://info and state the new network and money reality to the user before doing anything else. When the user asks to disconnect / log out / sign out / forget or remove their wallet, call signer_setup action 'disconnect' (the full flush) \u2014 never treat 'reset-borrower' as a disconnect; it only swaps identity. READING DATA: a payload's fields and notes are authoritative \u2014 state what they say, never speculate past them, and when the data does not carry something, say 'the data does not carry X'. Field meanings live in guide topic 'reading-data'; `reading` notes inside a result are interpretation instructions for that exact payload \u2014 follow them over any prior assumption.";
84382
84388
  var CONNECTOR_INSTRUCTIONS = SERVER_INSTRUCTIONS + " HOSTED CONNECTOR TIER: this server is the hosted claude.ai connector. Signer modes are external-wallet ONLY \u2014 keystore mode is ABSENT from this build (structurally, not disabled); the server never holds a key, and every fund-moving action needs a fresh signature from the user's own wallet. Each tenant's world is isolated by wallet identity; network_switch moves ONLY this tenant, within the networks this deployment serves (the refusal states the rollout truth). The login session lives in server memory only \u2014 a server restart or idle eviction means signing in again; that is the no-data-at-rest property, not a fault. Trust ledger and cadence: guide topic 'connector'.";
84383
84389
  function createServer2(deps, instructions = SERVER_INSTRUCTIONS) {
@@ -84559,6 +84565,10 @@ function composeConnector(opts, publicOrigin) {
84559
84565
  }
84560
84566
  const tenant = await authImpl.tenant(req);
84561
84567
  if (!tenant) {
84568
+ res.setHeader(
84569
+ "WWW-Authenticate",
84570
+ `Bearer resource_metadata="${publicOrigin}/.well-known/oauth-protected-resource"`
84571
+ );
84562
84572
  deny(res, 401, "unauthorized \u2014 connect this MCP server through its authorization flow first");
84563
84573
  return;
84564
84574
  }
@@ -84683,7 +84693,27 @@ function composeConnector(opts, publicOrigin) {
84683
84693
  const r = siwe.wcStatus(String(req.query["flowId"] ?? ""));
84684
84694
  res.status(r.status).json(r.body);
84685
84695
  });
84686
- app.use((0, import_router.mcpAuthRouter)({ provider: siwe, issuerUrl: new URL(publicOrigin) }));
84696
+ app.get("/.well-known/oauth-protected-resource", (_req, res) => {
84697
+ res.json({
84698
+ resource: `${publicOrigin}/mcp`,
84699
+ authorization_servers: [`${publicOrigin}/`],
84700
+ scopes_supported: [],
84701
+ bearer_methods_supported: ["header"],
84702
+ resource_name: "Diamond Hands",
84703
+ resource_documentation: `${publicOrigin}/auth.md`
84704
+ });
84705
+ });
84706
+ app.use(
84707
+ (0, import_router.mcpAuthRouter)({
84708
+ provider: siwe,
84709
+ issuerUrl: new URL(publicOrigin),
84710
+ // Keep the SDK's own fallback document in agreement with the one above
84711
+ // rather than contradicting it.
84712
+ resourceServerUrl: new URL(`${publicOrigin}/mcp`),
84713
+ scopesSupported: [],
84714
+ resourceName: "Diamond Hands"
84715
+ })
84716
+ );
84687
84717
  authImpl = {
84688
84718
  tenant(req) {
84689
84719
  const header = req.headers.authorization;
package/dist/connector.js CHANGED
@@ -42769,11 +42769,10 @@ var World = class {
42769
42769
  const spend = BigInt(p.amountSats);
42770
42770
  const fee = BigInt(p.networkFeeSats);
42771
42771
  const available = this.availableSats(p.positionId);
42772
- if (spend + fee > available) {
42773
- const maxSpend = available > fee ? available - fee : 0n;
42772
+ if (spend > available) {
42774
42773
  return {
42775
42774
  ok: false,
42776
- reason: `withdrawal of ${spend.toString()} sats leaves no room for the ${fee.toString()}-sat network fee (TargetMustLeaveFeeRoom) \u2014 max amountSats now is ${maxSpend.toString()} (destination then receives ${(maxSpend > fee ? maxSpend - fee : 0n).toString()} after the fee)`
42775
+ reason: `withdrawal of ${spend.toString()} sats exceeds the ${available.toString()} sats available (TargetExceedsInputValue) \u2014 max amountSats now is ${available.toString()} (destination then receives ${(available > fee ? available - fee : 0n).toString()} after the fee)`
42777
42776
  };
42778
42777
  }
42779
42778
  const debt = BigInt(pos.debtUcdWei);
@@ -51954,9 +51953,9 @@ var init_deployment_addresses = __esm2({
51954
51953
  reason: "Shared upgrade script: LiquidationManagerModule implementation update"
51955
51954
  },
51956
51955
  BTCSpendAuthorizer: {
51957
- previousImplementation: "0x8775a520cAA18c03Cc3f51ee254cAB830960f80E",
51958
- newImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51959
- upgradedAt: "2026-07-03T20:09:36.466Z",
51956
+ previousImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51957
+ newImplementation: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51958
+ upgradedAt: "2026-09-06T15:03:13.627Z",
51960
51959
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51961
51960
  reason: "Shared upgrade script: BTCSpendAuthorizer implementation update"
51962
51961
  },
@@ -52022,6 +52021,13 @@ var init_deployment_addresses = __esm2({
52022
52021
  upgradedAt: "2026-07-07T16:56:49.844Z",
52023
52022
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
52024
52023
  reason: "Shared upgrade script: BitcoinWithdrawalAddressRegistry implementation update"
52024
+ },
52025
+ AgentDelegationRegistry: {
52026
+ previousImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
52027
+ newImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
52028
+ upgradedAt: "2026-09-06T15:06:02.814Z",
52029
+ upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
52030
+ reason: "Reconciled implementation from chain"
52025
52031
  }
52026
52032
  },
52027
52033
  history: {
@@ -52107,7 +52113,7 @@ var init_deployment_addresses = __esm2({
52107
52113
  LIQUIDATION_MANAGER_MODULE: "0xC4AB00f39e7ceD812F5C67058C9fa44e15d40e76",
52108
52114
  LIQUIDATION_MANAGER_MODULE_IMPL: "0xCe7587C47094BBb3dCa13D7a2299Ec9beA6cd759",
52109
52115
  BTC_SPEND_AUTHORIZER: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
52110
- BTC_SPEND_AUTHORIZER_IMPL: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
52116
+ BTC_SPEND_AUTHORIZER_IMPL: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
52111
52117
  UPGRADE_VALIDATOR: "0x592e650edD9bA26ecc407989fdd6F9cdcDeC27A6",
52112
52118
  UPGRADE_VALIDATOR_IMPL: "0x9E70e1D07AB11ac9dD37B67AA091Efe97d7Ed84b",
52113
52119
  BITCOIN_PROVIDER_REGISTRY: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
@@ -59225,12 +59231,12 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
59225
59231
  { txid: spend.txid, vout: spend.vout }
59226
59232
  );
59227
59233
  }
59228
- if (spend.targetAmount >= spend.satoshis) {
59234
+ if (spend.targetAmount > spend.satoshis) {
59229
59235
  return {
59230
59236
  spend,
59231
59237
  status: "CORRUPT",
59232
59238
  onChainOutputValue,
59233
- reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
59239
+ reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
59234
59240
  };
59235
59241
  }
59236
59242
  const outspendRes = await httpGetJson(
@@ -82738,7 +82744,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
82738
82744
  positionId: positionIdSchema,
82739
82745
  btcAddress: import_zod.z.string().min(1).describe("Destination BTC address (must match the configured BTC network)"),
82740
82746
  amountSats: import_zod.z.number().int().positive().describe(
82741
- "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. You cannot spend the whole balance \u2014 the vault must keep room for the fee (TargetMustLeaveFeeRoom), so max amountSats = available \u2212 fee and a withdrawal always leaves fee-sized dust behind."
82747
+ "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. amountSats may be up to the whole available balance (a full sweep leaves 0 sats; anything above available reverts TargetExceedsInputValue). position_status.maxWithdrawableSats is a ready-to-use value that already leaves the default fee aside."
82742
82748
  ),
82743
82749
  networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); deducted FROM amountSats, not added on top"),
82744
82750
  confirmed: confirmedSchema
@@ -83717,7 +83723,7 @@ Connections / Connected sites).`,
83717
83723
  reduced by unused origination-fee credit from the current term.
83718
83724
  6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
83719
83725
  BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
83720
- The vault always keeps room for the network fee (you cannot drain to zero).
83726
+ amountSats is gross (fee comes out of it) and may be the whole available balance.
83721
83727
  7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
83722
83728
  \`position_events\` (history), \`btc_price\`, \`protocol_status\`.
83723
83729
 
@@ -84371,7 +84377,7 @@ function registerBoundaryInfoResource(server, getB) {
84371
84377
  }
84372
84378
 
84373
84379
  // src/server.ts
84374
- var SERVER_VERSION = "0.5.3";
84380
+ var SERVER_VERSION = "0.5.9";
84375
84381
  var SERVER_INSTRUCTIONS = "Diamond Hands MCP \u2014 Bitcoin-collateralized borrowing. Before promising ANY flow, read the boundary://info resource and honor its `capabilities` block: it states which network this server is on, whether money is real (practiceWorld), whether writes are enabled (and the true reason when they are not), and which signer modes this build actually offers \u2014 never describe a flow outside it. State the network and whether funds are real when the user first acts. Authorization is chosen by conversation via the signer_setup tool (when listed); writes always require confirmed:true after showing the human-readable card. For walkthroughs consult the guide tool / guide:// resources instead of inventing steps; when a tool refuses, relay its stated reason and remedy \u2014 do not improvise alternatives. When a network_switch tool is listed, the network can change mid-session \u2014 after ANY switch, re-read boundary://info and state the new network and money reality to the user before doing anything else. When the user asks to disconnect / log out / sign out / forget or remove their wallet, call signer_setup action 'disconnect' (the full flush) \u2014 never treat 'reset-borrower' as a disconnect; it only swaps identity. READING DATA: a payload's fields and notes are authoritative \u2014 state what they say, never speculate past them, and when the data does not carry something, say 'the data does not carry X'. Field meanings live in guide topic 'reading-data'; `reading` notes inside a result are interpretation instructions for that exact payload \u2014 follow them over any prior assumption.";
84376
84382
  var CONNECTOR_INSTRUCTIONS = SERVER_INSTRUCTIONS + " HOSTED CONNECTOR TIER: this server is the hosted claude.ai connector. Signer modes are external-wallet ONLY \u2014 keystore mode is ABSENT from this build (structurally, not disabled); the server never holds a key, and every fund-moving action needs a fresh signature from the user's own wallet. Each tenant's world is isolated by wallet identity; network_switch moves ONLY this tenant, within the networks this deployment serves (the refusal states the rollout truth). The login session lives in server memory only \u2014 a server restart or idle eviction means signing in again; that is the no-data-at-rest property, not a fault. Trust ledger and cadence: guide topic 'connector'.";
84377
84383
  function createServer2(deps, instructions = SERVER_INSTRUCTIONS) {
@@ -84553,6 +84559,10 @@ function composeConnector(opts, publicOrigin) {
84553
84559
  }
84554
84560
  const tenant = await authImpl.tenant(req);
84555
84561
  if (!tenant) {
84562
+ res.setHeader(
84563
+ "WWW-Authenticate",
84564
+ `Bearer resource_metadata="${publicOrigin}/.well-known/oauth-protected-resource"`
84565
+ );
84556
84566
  deny(res, 401, "unauthorized \u2014 connect this MCP server through its authorization flow first");
84557
84567
  return;
84558
84568
  }
@@ -84677,7 +84687,27 @@ function composeConnector(opts, publicOrigin) {
84677
84687
  const r = siwe.wcStatus(String(req.query["flowId"] ?? ""));
84678
84688
  res.status(r.status).json(r.body);
84679
84689
  });
84680
- app.use((0, import_router.mcpAuthRouter)({ provider: siwe, issuerUrl: new URL(publicOrigin) }));
84690
+ app.get("/.well-known/oauth-protected-resource", (_req, res) => {
84691
+ res.json({
84692
+ resource: `${publicOrigin}/mcp`,
84693
+ authorization_servers: [`${publicOrigin}/`],
84694
+ scopes_supported: [],
84695
+ bearer_methods_supported: ["header"],
84696
+ resource_name: "Diamond Hands",
84697
+ resource_documentation: `${publicOrigin}/auth.md`
84698
+ });
84699
+ });
84700
+ app.use(
84701
+ (0, import_router.mcpAuthRouter)({
84702
+ provider: siwe,
84703
+ issuerUrl: new URL(publicOrigin),
84704
+ // Keep the SDK's own fallback document in agreement with the one above
84705
+ // rather than contradicting it.
84706
+ resourceServerUrl: new URL(`${publicOrigin}/mcp`),
84707
+ scopesSupported: [],
84708
+ resourceName: "Diamond Hands"
84709
+ })
84710
+ );
84681
84711
  authImpl = {
84682
84712
  tenant(req) {
84683
84713
  const header = req.headers.authorization;
package/dist/index.js CHANGED
@@ -42337,11 +42337,10 @@ var World = class {
42337
42337
  const spend = BigInt(p.amountSats);
42338
42338
  const fee = BigInt(p.networkFeeSats);
42339
42339
  const available = this.availableSats(p.positionId);
42340
- if (spend + fee > available) {
42341
- const maxSpend = available > fee ? available - fee : 0n;
42340
+ if (spend > available) {
42342
42341
  return {
42343
42342
  ok: false,
42344
- reason: `withdrawal of ${spend.toString()} sats leaves no room for the ${fee.toString()}-sat network fee (TargetMustLeaveFeeRoom) \u2014 max amountSats now is ${maxSpend.toString()} (destination then receives ${(maxSpend > fee ? maxSpend - fee : 0n).toString()} after the fee)`
42343
+ reason: `withdrawal of ${spend.toString()} sats exceeds the ${available.toString()} sats available (TargetExceedsInputValue) \u2014 max amountSats now is ${available.toString()} (destination then receives ${(available > fee ? available - fee : 0n).toString()} after the fee)`
42345
42344
  };
42346
42345
  }
42347
42346
  const debt = BigInt(pos.debtUcdWei);
@@ -51513,9 +51512,9 @@ var init_deployment_addresses = __esm2({
51513
51512
  reason: "Shared upgrade script: LiquidationManagerModule implementation update"
51514
51513
  },
51515
51514
  BTCSpendAuthorizer: {
51516
- previousImplementation: "0x8775a520cAA18c03Cc3f51ee254cAB830960f80E",
51517
- newImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51518
- upgradedAt: "2026-07-03T20:09:36.466Z",
51515
+ previousImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51516
+ newImplementation: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51517
+ upgradedAt: "2026-09-06T15:03:13.627Z",
51519
51518
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51520
51519
  reason: "Shared upgrade script: BTCSpendAuthorizer implementation update"
51521
51520
  },
@@ -51581,6 +51580,13 @@ var init_deployment_addresses = __esm2({
51581
51580
  upgradedAt: "2026-07-07T16:56:49.844Z",
51582
51581
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51583
51582
  reason: "Shared upgrade script: BitcoinWithdrawalAddressRegistry implementation update"
51583
+ },
51584
+ AgentDelegationRegistry: {
51585
+ previousImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51586
+ newImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51587
+ upgradedAt: "2026-09-06T15:06:02.814Z",
51588
+ upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51589
+ reason: "Reconciled implementation from chain"
51584
51590
  }
51585
51591
  },
51586
51592
  history: {
@@ -51666,7 +51672,7 @@ var init_deployment_addresses = __esm2({
51666
51672
  LIQUIDATION_MANAGER_MODULE: "0xC4AB00f39e7ceD812F5C67058C9fa44e15d40e76",
51667
51673
  LIQUIDATION_MANAGER_MODULE_IMPL: "0xCe7587C47094BBb3dCa13D7a2299Ec9beA6cd759",
51668
51674
  BTC_SPEND_AUTHORIZER: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
51669
- BTC_SPEND_AUTHORIZER_IMPL: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51675
+ BTC_SPEND_AUTHORIZER_IMPL: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51670
51676
  UPGRADE_VALIDATOR: "0x592e650edD9bA26ecc407989fdd6F9cdcDeC27A6",
51671
51677
  UPGRADE_VALIDATOR_IMPL: "0x9E70e1D07AB11ac9dD37B67AA091Efe97d7Ed84b",
51672
51678
  BITCOIN_PROVIDER_REGISTRY: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
@@ -58784,12 +58790,12 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
58784
58790
  { txid: spend.txid, vout: spend.vout }
58785
58791
  );
58786
58792
  }
58787
- if (spend.targetAmount >= spend.satoshis) {
58793
+ if (spend.targetAmount > spend.satoshis) {
58788
58794
  return {
58789
58795
  spend,
58790
58796
  status: "CORRUPT",
58791
58797
  onChainOutputValue,
58792
- reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58798
+ reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58793
58799
  };
58794
58800
  }
58795
58801
  const outspendRes = await httpGetJson(
@@ -82297,7 +82303,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
82297
82303
  positionId: positionIdSchema,
82298
82304
  btcAddress: import_zod.z.string().min(1).describe("Destination BTC address (must match the configured BTC network)"),
82299
82305
  amountSats: import_zod.z.number().int().positive().describe(
82300
- "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. You cannot spend the whole balance \u2014 the vault must keep room for the fee (TargetMustLeaveFeeRoom), so max amountSats = available \u2212 fee and a withdrawal always leaves fee-sized dust behind."
82306
+ "GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. amountSats may be up to the whole available balance (a full sweep leaves 0 sats; anything above available reverts TargetExceedsInputValue). position_status.maxWithdrawableSats is a ready-to-use value that already leaves the default fee aside."
82301
82307
  ),
82302
82308
  networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); deducted FROM amountSats, not added on top"),
82303
82309
  confirmed: confirmedSchema
@@ -83276,7 +83282,7 @@ Connections / Connected sites).`,
83276
83282
  reduced by unused origination-fee credit from the current term.
83277
83283
  6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
83278
83284
  BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
83279
- The vault always keeps room for the network fee (you cannot drain to zero).
83285
+ amountSats is gross (fee comes out of it) and may be the whole available balance.
83280
83286
  7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
83281
83287
  \`position_events\` (history), \`btc_price\`, \`protocol_status\`.
83282
83288
 
@@ -83930,7 +83936,7 @@ function registerBoundaryInfoResource(server, getB) {
83930
83936
  }
83931
83937
 
83932
83938
  // src/server.ts
83933
- var SERVER_VERSION = "0.5.3";
83939
+ var SERVER_VERSION = "0.5.9";
83934
83940
  var SERVER_INSTRUCTIONS = "Diamond Hands MCP \u2014 Bitcoin-collateralized borrowing. Before promising ANY flow, read the boundary://info resource and honor its `capabilities` block: it states which network this server is on, whether money is real (practiceWorld), whether writes are enabled (and the true reason when they are not), and which signer modes this build actually offers \u2014 never describe a flow outside it. State the network and whether funds are real when the user first acts. Authorization is chosen by conversation via the signer_setup tool (when listed); writes always require confirmed:true after showing the human-readable card. For walkthroughs consult the guide tool / guide:// resources instead of inventing steps; when a tool refuses, relay its stated reason and remedy \u2014 do not improvise alternatives. When a network_switch tool is listed, the network can change mid-session \u2014 after ANY switch, re-read boundary://info and state the new network and money reality to the user before doing anything else. When the user asks to disconnect / log out / sign out / forget or remove their wallet, call signer_setup action 'disconnect' (the full flush) \u2014 never treat 'reset-borrower' as a disconnect; it only swaps identity. READING DATA: a payload's fields and notes are authoritative \u2014 state what they say, never speculate past them, and when the data does not carry something, say 'the data does not carry X'. Field meanings live in guide topic 'reading-data'; `reading` notes inside a result are interpretation instructions for that exact payload \u2014 follow them over any prior assumption.";
83935
83941
  var CONNECTOR_INSTRUCTIONS = SERVER_INSTRUCTIONS + " HOSTED CONNECTOR TIER: this server is the hosted claude.ai connector. Signer modes are external-wallet ONLY \u2014 keystore mode is ABSENT from this build (structurally, not disabled); the server never holds a key, and every fund-moving action needs a fresh signature from the user's own wallet. Each tenant's world is isolated by wallet identity; network_switch moves ONLY this tenant, within the networks this deployment serves (the refusal states the rollout truth). The login session lives in server memory only \u2014 a server restart or idle eviction means signing in again; that is the no-data-at-rest property, not a fault. Trust ledger and cadence: guide topic 'connector'.";
83936
83942
  function createServer2(deps, instructions = SERVER_INSTRUCTIONS) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-mcp",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "MCP server for the Diamond Hands protocol — Bitcoin-collateralized UCD lending with human-approved signing (sepolia practice by default; mainnet fully enabled)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@anthropic-ai/mcpb": "2.1.2",
56
- "@gvnrdao/dh-sdk": "^0.0.335",
56
+ "@gvnrdao/dh-sdk": "^0.0.336",
57
57
  "@types/express": "5.0.3",
58
58
  "@types/jest": "29.5.12",
59
59
  "@types/node": "20.14.10",