bsv-mcp 0.2.15 → 0.3.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +94 -10
  2. package/README.md +95 -13
  3. package/dist/app.html +483 -106
  4. package/dist/index.js +227724 -117380
  5. package/index.ts +523 -63
  6. package/package.json +24 -15
  7. package/prompts/bsvSdk/auth.ts +1 -1
  8. package/prompts/bsvSdk/cryptography.ts +1 -1
  9. package/prompts/bsvSdk/overview.ts +1 -1
  10. package/prompts/bsvSdk/primitives.ts +1 -1
  11. package/prompts/bsvSdk/script.ts +1 -1
  12. package/prompts/bsvSdk/transaction.ts +1 -1
  13. package/prompts/bsvSdk/wallet.ts +1 -1
  14. package/prompts/ordinals.ts +1 -1
  15. package/tools/a2b/discover.ts +2 -2
  16. package/tools/bap/friend.ts +17 -24
  17. package/tools/bap/generate.test.ts +34 -32
  18. package/tools/bap/generate.ts +48 -43
  19. package/tools/bap/getCurrentAddress.ts +1 -3
  20. package/tools/bap/getId.test.ts +18 -10
  21. package/tools/bap/getId.ts +8 -6
  22. package/tools/bap/utils.ts +1 -1
  23. package/tools/bsocial/bmapReadPosts.ts +16 -2
  24. package/tools/bsocial/createPost.ts +21 -10
  25. package/tools/bsocial/readPosts.ts +10 -4
  26. package/tools/bsv/decodeTransaction.ts +1 -1
  27. package/tools/bsv/explore.ts +0 -4
  28. package/tools/bsv/getPrice.ts +1 -1
  29. package/tools/bsv/token.ts +14 -6
  30. package/tools/constants.ts +6 -2
  31. package/tools/index.ts +22 -13
  32. package/tools/mnee/getBalance.ts +1 -1
  33. package/tools/mnee/parseTx.ts +1 -1
  34. package/tools/mnee/sendMnee.ts +30 -8
  35. package/tools/ordinals/getInscription.ts +1 -3
  36. package/tools/ordinals/getTokenByIdOrTicker.ts +1 -3
  37. package/tools/ordinals/index.ts +4 -1
  38. package/tools/ordinals/marketListings.ts +1 -1
  39. package/tools/ordinals/marketSales.ts +1 -1
  40. package/tools/ordinals/searchInscriptions.ts +1 -1
  41. package/tools/utils/aip.ts +31 -22
  42. package/tools/utils/installAgentMaster.ts +8 -9
  43. package/tools/utils/toolRegistration.ts +21 -22
  44. package/tools/utils/transactionBuilder.ts +21 -14
  45. package/tools/wallet/a2bPublishMcp.ts +15 -5
  46. package/tools/wallet/brc100.ts +567 -312
  47. package/tools/wallet/cancelListing.ts +29 -37
  48. package/tools/wallet/createOrdinals.ts +43 -27
  49. package/tools/wallet/droplit.ts +124 -0
  50. package/tools/wallet/fetchPaymentUtxos.ts +7 -5
  51. package/tools/wallet/gatherCollectionInfo.ts +3 -5
  52. package/tools/wallet/getAddress.ts +1 -4
  53. package/tools/wallet/getBalance.ts +15 -15
  54. package/tools/wallet/{getBalanceDroplet.ts → getBalanceDroplit.ts} +6 -6
  55. package/tools/wallet/getBsv21Balances.ts +20 -14
  56. package/tools/wallet/getLockData.ts +11 -11
  57. package/tools/wallet/getOrdinals.ts +26 -20
  58. package/tools/wallet/integratedWallet.ts +53 -53
  59. package/tools/wallet/listOrdinal.ts +40 -39
  60. package/tools/wallet/listTokens.ts +18 -17
  61. package/tools/wallet/lockBsv.ts +36 -22
  62. package/tools/wallet/mintCollection.ts +15 -10
  63. package/tools/wallet/opnsDeregister.ts +29 -39
  64. package/tools/wallet/opnsRegister.ts +29 -39
  65. package/tools/wallet/purchaseListing.test.ts +27 -0
  66. package/tools/wallet/purchaseListing.ts +59 -40
  67. package/tools/wallet/refreshUtxos.ts +1 -1
  68. package/tools/wallet/schemas.ts +0 -13
  69. package/tools/wallet/sendAllBsv.ts +26 -20
  70. package/tools/wallet/sendBsv.ts +107 -0
  71. package/tools/wallet/setupDroplit.ts +151 -0
  72. package/tools/wallet/signBsm.ts +18 -18
  73. package/tools/wallet/sweepBsv.ts +48 -27
  74. package/tools/wallet/sweepBsv21.ts +42 -28
  75. package/tools/wallet/sweepOrdinals.ts +38 -26
  76. package/tools/wallet/tools.ts +17 -17
  77. package/tools/wallet/transactionHelper.ts +13 -5
  78. package/tools/wallet/transferOrdToken.ts +72 -84
  79. package/tools/wallet/unlockBsv.ts +23 -17
  80. package/tools/wallet/utxo.ts +1 -0
  81. package/tools/wallet/wallet.ts +1 -13
  82. package/test-mcp-server.ts +0 -157
  83. package/tools/wallet/sendToAddress.ts +0 -74
  84. package/tools/wallet/setupDroplet.ts +0 -161
@@ -2,6 +2,7 @@
2
2
  * Common tool registration utilities for the BSV MCP server
3
3
  */
4
4
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
6
  import type { z } from "zod";
6
7
 
7
8
  export interface ToolConfig<TArgs = Record<string, unknown>> {
@@ -11,13 +12,7 @@ export interface ToolConfig<TArgs = Record<string, unknown>> {
11
12
  handler: (args: TArgs) => Promise<ToolResponse>;
12
13
  }
13
14
 
14
- export interface ToolResponse {
15
- content: Array<{
16
- type: "text";
17
- text: string;
18
- }>;
19
- isError?: boolean;
20
- }
15
+ export type ToolResponse = CallToolResult;
21
16
 
22
17
  /**
23
18
  * Register a tool with standard error handling and response formatting
@@ -26,21 +21,25 @@ export function registerTool<TArgs = Record<string, unknown>>(
26
21
  server: McpServer,
27
22
  config: ToolConfig<TArgs>,
28
23
  ): void {
29
- server.tool(config.name, config.schema, async (args: TArgs) => {
30
- try {
31
- return await config.handler(args);
32
- } catch (error) {
33
- return {
34
- content: [
35
- {
36
- type: "text" as const,
37
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
38
- },
39
- ],
40
- isError: true,
41
- };
42
- }
43
- });
24
+ server.registerTool(
25
+ config.name,
26
+ { description: config.description, inputSchema: config.schema },
27
+ async (args) => {
28
+ try {
29
+ return await config.handler(args as TArgs);
30
+ } catch (error) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: "text" as const,
35
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`,
36
+ },
37
+ ],
38
+ isError: true,
39
+ };
40
+ }
41
+ },
42
+ );
44
43
  }
45
44
 
46
45
  /**
@@ -1,14 +1,15 @@
1
1
  import {
2
+ fromUtxo,
2
3
  isBroadcastFailure,
3
4
  isBroadcastResponse,
5
+ OP,
4
6
  P2PKH,
5
7
  type PrivateKey,
6
8
  Script,
7
9
  Transaction,
8
- Utils,
9
10
  } from "@bsv/sdk";
11
+ import type { Utxo } from "js-1sat-ord";
10
12
  import { V5Broadcaster } from "../../utils/broadcaster";
11
- import type { Utxo } from "../wallet/utxo";
12
13
 
13
14
  const DEFAULT_SAT_PER_BYTE = 0.05;
14
15
  const DUST_LIMIT = 546;
@@ -90,12 +91,18 @@ export async function buildAndSendTransaction(
90
91
  selectedUtxos.push(utxo);
91
92
  totalInputSatoshis += utxo.satoshis;
92
93
 
93
- const input = {
94
- sourceTransaction: utxo.tx,
95
- sourceOutputIndex: utxo.vout,
96
- unlockingScriptTemplate: p2pkh.unlock(paymentKey),
97
- };
98
- tx.addInput(input);
94
+ tx.addInput(
95
+ fromUtxo(
96
+ utxo,
97
+ p2pkh.unlock(
98
+ paymentKey,
99
+ "all",
100
+ false,
101
+ utxo.satoshis,
102
+ Script.fromHex(utxo.script),
103
+ ),
104
+ ),
105
+ );
99
106
 
100
107
  // Estimate fee with current inputs
101
108
  const estimatedSize = tx.toHex().length / 2 + 150; // rough estimate for unsigned tx
@@ -187,10 +194,10 @@ export async function buildAndSendTransaction(
187
194
  /**
188
195
  * Build OP_RETURN script from data arrays
189
196
  */
190
- export function buildOpReturnScript(dataArrays: Uint8Array[]): Script {
191
- return new Script([
192
- { op: 0 }, // OP_0
193
- { op: 106 }, // OP_RETURN
194
- ...dataArrays.map((data) => ({ data })),
195
- ]);
197
+ export function buildOpReturnScript(dataArrays: number[][]): Script {
198
+ const script = new Script([{ op: OP.OP_FALSE }, { op: OP.OP_RETURN }]);
199
+ for (const data of dataArrays) {
200
+ script.writeBin(data);
201
+ }
202
+ return script;
196
203
  }
@@ -35,7 +35,10 @@ export const McpConfigSchema = z.object({
35
35
  tools: z.array(z.string()).optional().describe("Available tool names"),
36
36
  prompts: z.array(z.string()).optional().describe("Available prompt names"),
37
37
  resources: z.array(z.string()).optional().describe("Available resource URIs"),
38
- env: z.record(z.string()).optional().describe("Environment variables"),
38
+ env: z
39
+ .record(z.string(), z.string())
40
+ .optional()
41
+ .describe("Environment variables"),
39
42
  });
40
43
 
41
44
  export type McpConfig = z.infer<typeof McpConfigSchema>;
@@ -89,7 +92,7 @@ async function callIngestEndpoint(txid: string): Promise<boolean> {
89
92
  return false;
90
93
  }
91
94
 
92
- const result = await response.json();
95
+ const _result = await response.json();
93
96
  // console.log('Ingest result:', result);
94
97
  return true;
95
98
  } catch (error) {
@@ -195,7 +198,15 @@ export function registerA2bPublishMcpTool(
195
198
  "wallet_a2bPublishMcp",
196
199
  "Publish an MCP tool configuration record on-chain via Ordinal inscription. This creates a permanent, immutable, and discoverable tool definition that can be accessed by other MCP servers. The tool is published as a JSON inscription with metadata and optional digital signatures for authenticity verification.",
197
200
  { ...a2bPublishMcpArgsSchema.shape },
198
- async ({ toolName, command, args, keywords, env, description, destinationAddress }) => {
201
+ async ({
202
+ toolName,
203
+ command,
204
+ args,
205
+ keywords,
206
+ env,
207
+ description,
208
+ destinationAddress,
209
+ }) => {
199
210
  try {
200
211
  if (!identityPk) {
201
212
  console.warn(
@@ -334,8 +345,7 @@ export function registerA2bPublishMcpTool(
334
345
  toolCount: metadata.tools.length,
335
346
  promptCount: metadata.prompts.length,
336
347
  resourceCount: metadata.resources.length,
337
- description:
338
- description || `MCP Tool: ${toolName}`,
348
+ description: description || `MCP Tool: ${toolName}`,
339
349
  address: targetAddress,
340
350
  },
341
351
  null,