bsv-mcp 0.2.14 → 0.2.15

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/index.ts CHANGED
@@ -52,6 +52,7 @@ let server: McpServer | undefined;
52
52
  interface ServerFactoryOptions {
53
53
  toolsConfig: ToolsConfig;
54
54
  wallet?: Wallet;
55
+ ctx?: import("@1sat/actions").OneSatContext;
55
56
  loadPrompts: boolean;
56
57
  loadResources: boolean;
57
58
  }
@@ -80,7 +81,7 @@ function createConfiguredServer(opts: ServerFactoryOptions): McpServer {
80
81
  );
81
82
 
82
83
  registerAllTools(srv, opts.toolsConfig);
83
- registerMcpAppTools(srv, opts.wallet);
84
+ registerMcpAppTools(srv, opts.wallet, opts.ctx);
84
85
  if (opts.loadPrompts) registerAllPrompts(srv);
85
86
  if (opts.loadResources) registerResources(srv);
86
87
 
@@ -278,7 +279,7 @@ async function initializeKeys(): Promise<{
278
279
  const APP_RESOURCE_URI = "ui://bsv-mcp/app.html";
279
280
  const __appDirname = dirname(fileURLToPath(import.meta.url));
280
281
 
281
- function registerMcpAppTools(server: McpServer, wallet?: Wallet) {
282
+ function registerMcpAppTools(server: McpServer, wallet?: Wallet, ctx?: import("@1sat/actions").OneSatContext) {
282
283
  // Primary dashboard tool — model calls this to open the UI
283
284
  registerAppTool(
284
285
  server,
@@ -468,7 +469,7 @@ function registerMcpAppTools(server: McpServer, wallet?: Wallet) {
468
469
  },
469
470
  );
470
471
 
471
- // App-only: fetch wallet data
472
+ // App-only: fetch wallet data (uses BRC-100 context to match direct tools)
472
473
  registerAppTool(
473
474
  server,
474
475
  "app_wallet_data",
@@ -481,7 +482,7 @@ function registerMcpAppTools(server: McpServer, wallet?: Wallet) {
481
482
  },
482
483
  },
483
484
  async () => {
484
- if (!wallet) {
485
+ if (!ctx && !wallet) {
485
486
  return {
486
487
  content: [
487
488
  {
@@ -497,11 +498,42 @@ function registerMcpAppTools(server: McpServer, wallet?: Wallet) {
497
498
  }
498
499
 
499
500
  try {
500
- const { paymentUtxos } = await wallet.getUtxos();
501
- const address = wallet.getAddress();
501
+ let address: string | undefined;
502
502
  let totalSatoshis = 0;
503
- for (const utxo of paymentUtxos) {
504
- totalSatoshis += utxo.satoshis || 0;
503
+ let utxoCount = 0;
504
+ let utxos: Array<{ txid: string; vout: number; satoshis: number }> = [];
505
+
506
+ // Use BRC-100 context (same source as wallet_getAddress / wallet_getBalance)
507
+ if (ctx) {
508
+ const { deriveDepositAddresses } = await import("@1sat/actions");
509
+ const { derivations } = await deriveDepositAddresses.execute(ctx, {
510
+ prefix: "mcp",
511
+ });
512
+ address = derivations[0]?.address;
513
+
514
+ const result = await ctx.wallet.listOutputs({ basket: "default" });
515
+ totalSatoshis = result.outputs.reduce(
516
+ (sum, output) => sum + output.satoshis,
517
+ 0,
518
+ );
519
+ utxoCount = result.totalOutputs;
520
+ utxos = result.outputs.slice(0, 50).map((o) => {
521
+ const [txid = "", voutStr = "0"] = (o.outpoint ?? "").split(".");
522
+ return { txid, vout: Number(voutStr), satoshis: o.satoshis };
523
+ });
524
+ } else if (wallet) {
525
+ // Fallback to local wallet if no BRC-100 context
526
+ address = wallet.getAddress();
527
+ const { paymentUtxos } = await wallet.getUtxos();
528
+ for (const utxo of paymentUtxos) {
529
+ totalSatoshis += utxo.satoshis || 0;
530
+ }
531
+ utxoCount = paymentUtxos.length;
532
+ utxos = paymentUtxos.slice(0, 50).map((u) => ({
533
+ txid: u.txid,
534
+ vout: u.vout,
535
+ satoshis: u.satoshis,
536
+ }));
505
537
  }
506
538
 
507
539
  let price: number | undefined;
@@ -525,14 +557,10 @@ function registerMcpAppTools(server: McpServer, wallet?: Wallet) {
525
557
  balance: {
526
558
  satoshis: totalSatoshis,
527
559
  bsv: bsvAmount,
528
- utxoCount: paymentUtxos.length,
560
+ utxoCount,
529
561
  },
530
562
  address,
531
- utxos: paymentUtxos.slice(0, 50).map((u) => ({
532
- txid: u.txid,
533
- vout: u.vout,
534
- satoshis: u.satoshis,
535
- })),
563
+ utxos,
536
564
  price,
537
565
  },
538
566
  _meta: { viewUUID: crypto.randomUUID() },
@@ -1013,6 +1041,7 @@ Authentication:
1013
1041
  const serverFactoryOpts: ServerFactoryOptions = {
1014
1042
  toolsConfig,
1015
1043
  wallet,
1044
+ ctx: remoteCtx,
1016
1045
  loadPrompts: effectiveConfig.loadPrompts,
1017
1046
  loadResources: effectiveConfig.loadResources,
1018
1047
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bsv-mcp",
3
3
  "module": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.2.14",
5
+ "version": "0.2.15",
6
6
  "license": "MIT",
7
7
  "author": "satchmo",
8
8
  "description": "A collection of Bitcoin SV (BSV) tools for the Model Context Protocol (MCP) framework",