bsv-mcp 0.2.0 → 0.2.8

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/index.js +87290 -70731
  3. package/index.ts +422 -22
  4. package/package.json +28 -24
  5. package/tools/a2b/discover.ts +13 -13
  6. package/tools/bap/friend.ts +2 -3
  7. package/tools/bap/generate.ts +7 -9
  8. package/tools/bap/getCurrentAddress.ts +1 -8
  9. package/tools/bap/getId.ts +3 -3
  10. package/tools/bsocial/bmapFollow.ts +3 -7
  11. package/tools/bsocial/bmapLikes.ts +3 -3
  12. package/tools/bsocial/bmapReadPosts.ts +3 -3
  13. package/tools/bsocial/createPost.ts +8 -7
  14. package/tools/bsocial/readPosts.ts +3 -3
  15. package/tools/bsv/decodeTransaction.ts +2 -5
  16. package/tools/bsv/explore.ts +2 -3
  17. package/tools/bsv/getPrice.ts +1 -9
  18. package/tools/bsv/token.ts +14 -26
  19. package/tools/index.ts +0 -13
  20. package/tools/mnee/getBalance.ts +2 -4
  21. package/tools/mnee/parseTx.ts +3 -3
  22. package/tools/mnee/sendMnee.ts +5 -5
  23. package/tools/ordinals/getInscription.ts +2 -3
  24. package/tools/ordinals/getTokenByIdOrTicker.ts +6 -3
  25. package/tools/ordinals/marketListings.ts +2 -18
  26. package/tools/ordinals/marketSales.ts +2 -4
  27. package/tools/ordinals/searchInscriptions.ts +2 -4
  28. package/tools/utils/index.ts +14 -16
  29. package/tools/wallet/a2bPublishAgent.ts +18 -27
  30. package/tools/wallet/a2bPublishMcp.ts +17 -22
  31. package/tools/wallet/createOrdinals.ts +11 -20
  32. package/tools/wallet/fetchPaymentUtxos.ts +9 -1
  33. package/tools/wallet/gatherCollectionInfo.ts +9 -13
  34. package/tools/wallet/getAddress.ts +1 -9
  35. package/tools/wallet/getBalance.ts +2 -14
  36. package/tools/wallet/getBalanceDroplet.ts +2 -13
  37. package/tools/wallet/getPublicKey.ts +3 -16
  38. package/tools/wallet/mintCollection.ts +21 -24
  39. package/tools/wallet/purchaseListing.ts +19 -29
  40. package/tools/wallet/refreshUtxos.ts +2 -14
  41. package/tools/wallet/sendOrdinals.ts +11 -20
  42. package/tools/wallet/sendToAddress.ts +2 -22
  43. package/tools/wallet/setupDroplet.ts +7 -18
  44. package/tools/wallet/tools.ts +10 -80
  45. package/tools/wallet/transferOrdToken.ts +12 -20
  46. package/vite.config.ts +15 -0
  47. package/tools/bigblocks/components.ts +0 -304
  48. package/tools/bigblocks/docs.ts +0 -488
  49. package/tools/bigblocks/examples.ts +0 -527
  50. package/tools/bigblocks/generator.ts +0 -485
  51. package/tools/bigblocks/index.ts +0 -23
  52. package/tools/bsocial/bigblocksApiClient.ts +0 -189
@@ -1,11 +1,6 @@
1
1
  import { PrivateKey } from "@bsv/sdk";
2
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
- import type {
5
- CallToolResult,
6
- ServerNotification,
7
- ServerRequest,
8
- } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
9
4
  import {
10
5
  type ChangeResult,
11
6
  type ExistingListing,
@@ -20,8 +15,6 @@ import {
20
15
  type TokenUtxo,
21
16
  type Utxo,
22
17
  } from "js-1sat-ord";
23
- import { Sigma } from "sigma-protocol";
24
- import type { z } from "zod";
25
18
  import {
26
19
  MARKET_FEE_PERCENTAGE,
27
20
  MARKET_WALLET_ADDRESS,
@@ -86,11 +79,8 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
86
79
  server.tool(
87
80
  "wallet_purchaseListing",
88
81
  "Purchases a listing from the Bitcoin SV ordinals marketplace. Supports both NFT purchases (with royalty payments to original creators) and BSV-20/BSV-21 token purchases. The tool handles all aspects of the transaction - from fetching listing details, calculating fees, creating and broadcasting the transaction.",
89
- { args: purchaseListingArgsSchema },
90
- async (
91
- { args }: { args: z.infer<typeof purchaseListingArgsSchema> },
92
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
93
- ): Promise<CallToolResult> => {
82
+ { ...purchaseListingArgsSchema.shape },
83
+ async ({ listingOutpoint, ordAddress, listingType, tokenProtocol, tokenID, description }): Promise<CallToolResult> => {
94
84
  try {
95
85
  // Load optional identity key for sigma signing
96
86
  const identityKeyWif = process.env.IDENTITY_KEY_WIF;
@@ -108,7 +98,7 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
108
98
 
109
99
  // Fetch the listing info directly from the API
110
100
  const response = await fetch(
111
- `https://ordinals.gorillapool.io/api/txos/${args.listingOutpoint}?script=true`,
101
+ `https://ordinals.gorillapool.io/api/txos/${listingOutpoint}?script=true`,
112
102
  );
113
103
  if (!response.ok) {
114
104
  throw new Error(
@@ -138,7 +128,7 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
138
128
  }
139
129
 
140
130
  // Parse the listing outpoint to get txid and vout
141
- const [txid, voutStr] = args.listingOutpoint.split("_");
131
+ const [txid, voutStr] = listingOutpoint.split("_");
142
132
  if (!txid) {
143
133
  throw new Error("Invalid outpoint format. Expected txid_vout");
144
134
  }
@@ -182,12 +172,12 @@ Please fund this wallet address with enough BSV to cover the purchase price
182
172
  // Create the purchase transaction based on listing type
183
173
  let transaction: ChangeResult;
184
174
 
185
- if (args.listingType === "token") {
186
- if (!args.tokenProtocol) {
175
+ if (listingType === "token") {
176
+ if (!tokenProtocol) {
187
177
  throw new Error("tokenProtocol is required for token listings");
188
178
  }
189
179
 
190
- if (!args.tokenID) {
180
+ if (!tokenID) {
191
181
  throw new Error("tokenID is required for token listings");
192
182
  }
193
183
 
@@ -203,7 +193,7 @@ Please fund this wallet address with enough BSV to cover the purchase price
203
193
 
204
194
  // Convert the token protocol to the enum type expected by js-1sat-ord
205
195
  const protocol =
206
- args.tokenProtocol === "bsv-20" ? TokenType.BSV20 : TokenType.BSV21;
196
+ tokenProtocol === "bsv-20" ? TokenType.BSV20 : TokenType.BSV21;
207
197
 
208
198
  // Create a TokenUtxo with the required fields
209
199
  const listingUtxo: TokenUtxo = {
@@ -212,17 +202,17 @@ Please fund this wallet address with enough BSV to cover the purchase price
212
202
  script: listingData.script,
213
203
  satoshis: 1, // TokenUtxo's satoshis must be exactly 1
214
204
  amt: listingData.data.bsv20.amt,
215
- id: args.tokenID,
205
+ id: tokenID,
216
206
  payout: listingData.data.list.payout,
217
207
  };
218
208
 
219
209
  transaction = await purchaseOrdTokenListing({
220
210
  protocol,
221
- tokenID: args.tokenID,
211
+ tokenID: tokenID,
222
212
  utxos: paymentUtxos,
223
213
  paymentPk,
224
214
  listingUtxo,
225
- ordAddress: args.ordAddress,
215
+ ordAddress: ordAddress,
226
216
  additionalPayments,
227
217
  metaData,
228
218
  });
@@ -257,7 +247,7 @@ Please fund this wallet address with enough BSV to cover the purchase price
257
247
  const purchaseOrdListingConfig: PurchaseOrdListingConfig = {
258
248
  utxos: paymentUtxos,
259
249
  paymentPk,
260
- ordAddress: args.ordAddress,
250
+ ordAddress: ordAddress,
261
251
  listing,
262
252
  additionalPayments,
263
253
  metaData,
@@ -301,16 +291,16 @@ Please fund this wallet address with enough BSV to cover the purchase price
301
291
  status: resultStatus,
302
292
  message: resultMessage,
303
293
  txid: transaction.tx.id("hex"),
304
- listingOutpoint: args.listingOutpoint,
305
- destinationAddress: args.ordAddress,
306
- listingType: args.listingType,
307
- tokenProtocol: args.tokenID ? args.tokenProtocol : undefined,
308
- tokenID: args.tokenID,
294
+ listingOutpoint: listingOutpoint,
295
+ destinationAddress: ordAddress,
296
+ listingType: listingType,
297
+ tokenProtocol: tokenID ? tokenProtocol : undefined,
298
+ tokenID: tokenID,
309
299
  price: listingData.data.list.price,
310
300
  marketFee,
311
301
  marketFeeAddress: MARKET_WALLET_ADDRESS,
312
302
  royaltiesPaid:
313
- args.listingType === "nft" &&
303
+ listingType === "nft" &&
314
304
  listingData.origin?.data?.map?.royalties
315
305
  ? JSON.parse(listingData.origin.data.map.royalties)
316
306
  : undefined,
@@ -1,16 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
- import type {
4
- ServerNotification,
5
- ServerRequest,
6
- } from "@modelcontextprotocol/sdk/types.js";
7
2
  import { toBitcoin } from "satoshi-token";
8
- import { z } from "zod";
9
3
  import type { Wallet } from "./wallet";
10
4
 
11
- const refreshUtxosArgsSchema = z.object({});
12
- type RefreshUtxosArgs = z.infer<typeof refreshUtxosArgsSchema>;
13
-
14
5
  /**
15
6
  * Registers the wallet_refreshUtxos tool that refreshes and returns the UTXOs for the wallet
16
7
  */
@@ -18,11 +9,8 @@ export function registerRefreshUtxosTool(server: McpServer, wallet: Wallet) {
18
9
  server.tool(
19
10
  "wallet_refreshUtxos",
20
11
  "Refreshes and returns the wallet's UTXOs. This is useful for debugging UTXO issues, ensuring the wallet has the latest transaction outputs, and for verifying available funds before making transactions.",
21
- { args: refreshUtxosArgsSchema },
22
- async (
23
- { args }: { args: RefreshUtxosArgs },
24
- _extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
25
- ) => {
12
+ {},
13
+ async () => {
26
14
  try {
27
15
  // Force refresh the UTXOs
28
16
  await wallet.refreshUtxos();
@@ -1,18 +1,12 @@
1
1
  import { PrivateKey } from "@bsv/sdk";
2
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
- import type {
5
- CallToolResult,
6
- ServerNotification,
7
- ServerRequest,
8
- } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
9
4
  import type {
10
5
  ChangeResult,
11
6
  LocalSigner,
12
7
  SendOrdinalsConfig,
13
8
  } from "js-1sat-ord";
14
- import { OneSatBroadcaster, sendOrdinals } from "js-1sat-ord";
15
- import { Sigma } from "sigma-protocol";
9
+ import { sendOrdinals } from "js-1sat-ord";
16
10
  import { z } from "zod";
17
11
  import { V5Broadcaster } from "../../utils/broadcaster";
18
12
  import type { Wallet } from "./wallet";
@@ -45,11 +39,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
45
39
  server.tool(
46
40
  "wallet_sendOrdinals",
47
41
  "Transfers ordinals (NFTs) from your wallet to another address on the Bitcoin SV blockchain. This tool enables sending inscriptions you own to any valid BSV address. The transaction is created, signed, and broadcast automatically, with appropriate fee calculation and change handling.",
48
- { args: sendOrdinalsArgsSchema },
49
- async (
50
- { args }: { args: SendOrdinalsArgs },
51
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
52
- ): Promise<CallToolResult> => {
42
+ { ...sendOrdinalsArgsSchema.shape },
43
+ async ({ inscriptionOutpoint, destinationAddress, metadata }): Promise<CallToolResult> => {
53
44
  try {
54
45
  // 1. Get private key from wallet
55
46
  const paymentPk = wallet.getPrivateKey();
@@ -69,7 +60,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
69
60
  const walletAddress = paymentPk.toAddress().toString();
70
61
 
71
62
  // 4. Parse the inscription outpoint
72
- const [txid, voutStr] = args.inscriptionOutpoint.split("_");
63
+ const [txid, voutStr] = inscriptionOutpoint.split("_");
73
64
  if (!txid || !voutStr) {
74
65
  throw new Error(
75
66
  "Invalid inscription outpoint format. Expected txid_vout",
@@ -84,7 +75,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
84
75
 
85
76
  if (!inscription) {
86
77
  throw new Error(
87
- `Inscription ${args.inscriptionOutpoint} not found in your wallet`,
78
+ `Inscription ${inscriptionOutpoint} not found in your wallet`,
88
79
  );
89
80
  }
90
81
 
@@ -93,7 +84,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
93
84
  paymentPk,
94
85
  paymentUtxos,
95
86
  ordinals: [inscription],
96
- destinations: [{ address: args.destinationAddress }],
87
+ destinations: [{ address: destinationAddress }],
97
88
  changeAddress: walletAddress,
98
89
  };
99
90
 
@@ -108,8 +99,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
108
99
  }
109
100
 
110
101
  // Add metadata if provided
111
- if (args.metadata) {
112
- sendOrdinalsConfig.metaData = args.metadata;
102
+ if (metadata) {
103
+ sendOrdinalsConfig.metaData = metadata;
113
104
  }
114
105
 
115
106
  // Using the wallet's key for both payment and ordinals
@@ -144,8 +135,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
144
135
  txid: changeResult.tx.id("hex"),
145
136
  spentOutpoints: changeResult.spentOutpoints,
146
137
  payChange: changeResult.payChange,
147
- inscriptionOutpoint: args.inscriptionOutpoint,
148
- destinationAddress: args.destinationAddress,
138
+ inscriptionOutpoint: inscriptionOutpoint,
139
+ destinationAddress: destinationAddress,
149
140
  }),
150
141
  },
151
142
  ],
@@ -1,19 +1,10 @@
1
1
  import { P2PKH } from "@bsv/sdk";
2
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
- import type {
5
- ServerNotification,
6
- ServerRequest,
7
- } from "@modelcontextprotocol/sdk/types.js";
8
3
  import { toSatoshi } from "satoshi-token";
9
- import type { z } from "zod";
10
4
  import { getBsvPriceWithCache } from "../bsv/getPrice";
11
5
  import { sendToAddressArgsSchema } from "./schemas";
12
6
  import type { Wallet } from "./wallet";
13
7
 
14
- // Use the schema imported from schemas.ts
15
- export type SendToAddressArgs = z.infer<typeof sendToAddressArgsSchema>;
16
-
17
8
  /**
18
9
  * Register the sendToAddress tool
19
10
  */
@@ -21,20 +12,9 @@ export function registerSendToAddressTool(server: McpServer, wallet: Wallet) {
21
12
  server.tool(
22
13
  "wallet_sendToAddress",
23
14
  "Sends Bitcoin SV (BSV) to a specified address. This tool supports payments in both BSV and USD amounts (with automatic conversion using current exchange rates). Transaction fees are automatically calculated and a confirmation with transaction ID is returned upon success.",
24
- {
25
- args: sendToAddressArgsSchema,
26
- },
27
- async (
28
- { args }: { args: SendToAddressArgs },
29
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
30
- ) => {
15
+ { ...sendToAddressArgsSchema.shape },
16
+ async ({ address, amount, currency = "BSV", description = "Send to address" }) => {
31
17
  try {
32
- const {
33
- address,
34
- amount,
35
- currency = "BSV",
36
- description = "Send to address",
37
- } = args;
38
18
 
39
19
  // Convert to satoshis
40
20
  let satoshis: number;
@@ -1,11 +1,5 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
- import type {
4
- ServerNotification,
5
- ServerRequest,
6
- } from "@modelcontextprotocol/sdk/types.js";
7
2
  import { z } from "zod";
8
- import { DropletClient } from "../../utils/droplet";
9
3
  import type { IntegratedWallet } from "./integratedWallet";
10
4
 
11
5
  const setupDropletArgsSchema = z.object({
@@ -26,13 +20,8 @@ export function registerSetupDropletTool(
26
20
  server.tool(
27
21
  "wallet_setupDroplet",
28
22
  "Setup and manage Droplet API integration. Actions: register_key (registers your public key), create_faucet (creates a new faucet), check_status (checks faucet status)",
29
- {
30
- args: setupDropletArgsSchema,
31
- },
32
- async (
33
- { args }: { args: SetupDropletArgs },
34
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
35
- ) => {
23
+ { ...setupDropletArgsSchema.shape },
24
+ async ({ action, faucetName, fixedDropSats }) => {
36
25
  try {
37
26
  const dropletClient = integratedWallet.getDropletClient();
38
27
  if (!dropletClient) {
@@ -43,7 +32,7 @@ export function registerSetupDropletTool(
43
32
  const apiUrl = config.apiUrl;
44
33
  const authKey = config.authKey;
45
34
 
46
- switch (args.action) {
35
+ switch (action) {
47
36
  case "register_key": {
48
37
  if (!authKey) {
49
38
  throw new Error("No auth key configured");
@@ -80,7 +69,7 @@ export function registerSetupDropletTool(
80
69
  }
81
70
 
82
71
  case "create_faucet": {
83
- if (!args.faucetName) {
72
+ if (!faucetName) {
84
73
  throw new Error(
85
74
  "faucetName is required for create_faucet action",
86
75
  );
@@ -100,8 +89,8 @@ export function registerSetupDropletTool(
100
89
 
101
90
  // Create the faucet
102
91
  const body = {
103
- name: args.faucetName,
104
- fixed_drop_sats: args.fixedDropSats || 1000,
92
+ name: faucetName,
93
+ fixed_drop_sats: fixedDropSats || 1000,
105
94
  max_consolidation_inputs: 20,
106
95
  };
107
96
 
@@ -154,7 +143,7 @@ export function registerSetupDropletTool(
154
143
  }
155
144
 
156
145
  default:
157
- throw new Error(`Unknown action: ${args.action}`);
146
+ throw new Error(`Unknown action: ${action}`);
158
147
  }
159
148
  } catch (error) {
160
149
  return {
@@ -1,23 +1,7 @@
1
1
  import { type PrivateKey, Utils } from "@bsv/sdk";
2
- import type {
3
- McpServer,
4
- ToolCallback,
5
- } from "@modelcontextprotocol/sdk/server/mcp.js";
6
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
7
- import type {
8
- CallToolResult,
9
- ServerNotification,
10
- ServerRequest,
11
- } from "@modelcontextprotocol/sdk/types.js";
12
- import type { z } from "zod";
13
- import {
14
- type a2bPublishMcpArgsSchema,
15
- registerA2bPublishMcpTool,
16
- } from "./a2bPublishMcp";
17
- import {
18
- type createOrdinalsArgsSchema,
19
- registerCreateOrdinalsTool,
20
- } from "./createOrdinals";
2
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { registerA2bPublishMcpTool } from "./a2bPublishMcp";
4
+ import { registerCreateOrdinalsTool } from "./createOrdinals";
21
5
  import { registerGatherCollectionInfoTool } from "./gatherCollectionInfo";
22
6
  import { registerGetAddressTool } from "./getAddress";
23
7
  import { registerWalletGetBalanceTool } from "./getBalance";
@@ -25,46 +9,11 @@ import { registerGetPublicKeyTool } from "./getPublicKey";
25
9
  import { registerMintCollectionTool } from "./mintCollection";
26
10
  import { registerPurchaseListingTool } from "./purchaseListing";
27
11
  import { registerRefreshUtxosTool } from "./refreshUtxos";
28
- import {
29
- type emptyArgsSchema,
30
- type getAddressArgsSchema,
31
- type getPublicKeyArgsSchema,
32
- type purchaseListingArgsSchema,
33
- type sendToAddressArgsSchema,
34
- walletEncryptionArgsSchema,
35
- } from "./schemas";
12
+ import { walletEncryptionArgsSchema } from "./schemas";
36
13
  import { registerSendToAddressTool } from "./sendToAddress";
37
- import {
38
- registerTransferOrdTokenTool,
39
- type transferOrdTokenArgsSchema,
40
- } from "./transferOrdToken";
14
+ import { registerTransferOrdTokenTool } from "./transferOrdToken";
41
15
  import type { Wallet } from "./wallet";
42
16
 
43
- // Define mapping from tool names to argument schemas
44
- type ToolArgSchemas = {
45
- wallet_getPublicKey: typeof getPublicKeyArgsSchema;
46
- wallet_encryption: typeof walletEncryptionArgsSchema;
47
- wallet_getAddress: typeof getAddressArgsSchema;
48
- wallet_sendToAddress: typeof sendToAddressArgsSchema;
49
- wallet_purchaseListing: typeof purchaseListingArgsSchema;
50
- wallet_transferOrdToken: typeof transferOrdTokenArgsSchema;
51
- wallet_a2bPublish: typeof a2bPublishMcpArgsSchema;
52
- wallet_createOrdinals: typeof createOrdinalsArgsSchema;
53
- wallet_refreshUtxos: typeof emptyArgsSchema;
54
- wallet_getBalance: typeof emptyArgsSchema;
55
- };
56
-
57
- // Define a type for the handler function with proper argument types
58
- type ToolHandler = (
59
- params: { args: unknown },
60
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
61
- ) => Promise<CallToolResult>;
62
-
63
- // Define a map type for tool name to handler functions
64
- type ToolHandlerMap = {
65
- [K in keyof ToolArgSchemas]: ToolHandler;
66
- };
67
-
68
17
  export function registerWalletTools(
69
18
  server: McpServer,
70
19
  wallet: Wallet,
@@ -73,21 +22,7 @@ export function registerWalletTools(
73
22
  enableA2bTools: boolean;
74
23
  identityPk?: PrivateKey;
75
24
  },
76
- ): ToolHandlerMap {
77
- const handlers = {} as ToolHandlerMap;
78
-
79
- // Handle tools registration with properly typed parameters
80
- function registerTool<T extends z.ZodType>(
81
- name: keyof ToolArgSchemas,
82
- description: string,
83
- schema: { args: T },
84
- handler: ToolCallback<{ args: T }>,
85
- ): void {
86
- // Register all tools normally
87
- server.tool(name, description, schema, handler);
88
- handlers[name] = handler as ToolHandler;
89
- }
90
-
25
+ ): void {
91
26
  // Register the wallet_sendToAddress tool
92
27
  registerSendToAddressTool(server, wallet);
93
28
 
@@ -118,7 +53,7 @@ export function registerWalletTools(
118
53
  }
119
54
 
120
55
  // Register combined wallet_encryption tool
121
- registerTool(
56
+ server.tool(
122
57
  "wallet_encryption",
123
58
  "Combined tool for encrypting and decrypting data using the wallet's cryptographic keys.\n\n" +
124
59
  "PARAMETERS:\n" +
@@ -139,13 +74,9 @@ export function registerWalletTools(
139
74
  ' "mode": "decrypt",\n' +
140
75
  ' "data": [encrypted bytes from previous response]\n' +
141
76
  " }",
142
- { args: walletEncryptionArgsSchema },
143
- async (
144
- { args }: { args: z.infer<typeof walletEncryptionArgsSchema> },
145
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
146
- ) => {
77
+ { ...walletEncryptionArgsSchema.shape },
78
+ async ({ mode, data, encoding, recipientPublicKeyHex }) => {
147
79
  try {
148
- const { mode, data, encoding, recipientPublicKeyHex } = args;
149
80
 
150
81
  let inputData: number[];
151
82
  if (typeof data === "string") {
@@ -187,7 +118,7 @@ export function registerWalletTools(
187
118
  content: [
188
119
  {
189
120
  type: "text",
190
- text: `Error during ${args.mode}: ${errorMessage}`,
121
+ text: `Error during ${mode}: ${errorMessage}`,
191
122
  },
192
123
  ],
193
124
  isError: true,
@@ -203,5 +134,4 @@ export function registerWalletTools(
203
134
  registerGatherCollectionInfoTool(server, wallet);
204
135
  registerMintCollectionTool(server, wallet);
205
136
 
206
- return handlers;
207
137
  }
@@ -1,10 +1,5 @@
1
1
  import { PrivateKey } from "@bsv/sdk";
2
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
- import type {
5
- ServerNotification,
6
- ServerRequest,
7
- } from "@modelcontextprotocol/sdk/types.js";
8
3
  import {
9
4
  type Distribution,
10
5
  type LocalSigner,
@@ -65,11 +60,8 @@ export function registerTransferOrdTokenTool(
65
60
  server.tool(
66
61
  "wallet_transferOrdToken",
67
62
  "Transfers BSV-20 or BSV-21 tokens from your wallet via js-1sat-ord transferOrdTokens.",
68
- { args: transferOrdTokenArgsSchema },
69
- async (
70
- { args }: { args: TransferOrdTokenArgs },
71
- extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
72
- ) => {
63
+ { ...transferOrdTokenArgsSchema.shape },
64
+ async ({ protocol, tokenID, sendAmount, paymentUtxos, tokenUtxos, distributions, decimals, additionalPayments }) => {
73
65
  try {
74
66
  // fetch keys
75
67
  const paymentPk = wallet.getPaymentKey();
@@ -80,9 +72,9 @@ export function registerTransferOrdTokenTool(
80
72
 
81
73
  // select token UTXOs
82
74
  const { selectedUtxos: inputTokens } = selectTokenUtxos(
83
- args.tokenUtxos as TokenUtxo[],
84
- args.sendAmount,
85
- args.decimals,
75
+ tokenUtxos as TokenUtxo[],
76
+ sendAmount,
77
+ decimals,
86
78
  {
87
79
  inputStrategy: TokenSelectionStrategy.SmallestFirst,
88
80
  outputStrategy: TokenSelectionStrategy.LargestFirst,
@@ -92,21 +84,21 @@ export function registerTransferOrdTokenTool(
92
84
  // build config
93
85
  const config: TransferOrdTokensConfig = {
94
86
  protocol:
95
- args.protocol === "bsv-20" ? TokenType.BSV20 : TokenType.BSV21,
96
- tokenID: args.tokenID,
97
- utxos: args.paymentUtxos as Utxo[],
87
+ protocol === "bsv-20" ? TokenType.BSV20 : TokenType.BSV21,
88
+ tokenID,
89
+ utxos: paymentUtxos as Utxo[],
98
90
  inputTokens,
99
- distributions: args.distributions as Distribution[],
91
+ distributions: distributions as Distribution[],
100
92
  tokenChangeAddress: ordAddress,
101
93
  changeAddress,
102
94
  paymentPk,
103
95
  ordPk,
104
- additionalPayments: (args.additionalPayments as Payment[]) || [],
105
- decimals: args.decimals,
96
+ additionalPayments: (additionalPayments as Payment[]) || [],
97
+ decimals,
106
98
  inputMode: TokenInputMode.Needed,
107
99
  splitConfig: {
108
100
  outputs: inputTokens.length === 1 ? 2 : 1,
109
- threshold: args.sendAmount,
101
+ threshold: sendAmount,
110
102
  },
111
103
  };
112
104
 
package/vite.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { resolve } from "node:path";
2
+ import { defineConfig } from "vite";
3
+ import { viteSingleFile } from "vite-plugin-singlefile";
4
+
5
+ export default defineConfig({
6
+ root: resolve(__dirname, "src/views"),
7
+ plugins: [viteSingleFile()],
8
+ build: {
9
+ rollupOptions: {
10
+ input: resolve(__dirname, "src/views/app.html"),
11
+ },
12
+ outDir: resolve(__dirname, "dist"),
13
+ emptyOutDir: false,
14
+ },
15
+ });