bsv-mcp 0.2.9 → 0.2.11
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/CHANGELOG.md +19 -0
- package/README.md +26 -2
- package/dist/index.js +6777 -126216
- package/index.ts +287 -265
- package/package.json +4 -3
- package/tools/bap/generate.test.ts +17 -16
- package/tools/index.ts +8 -3
- package/tools/ordinals/getInscription.ts +15 -65
- package/tools/ordinals/getTokenByIdOrTicker.ts +14 -80
- package/tools/ordinals/index.ts +8 -7
- package/tools/ordinals/marketListings.ts +21 -188
- package/tools/ordinals/marketSales.ts +21 -127
- package/tools/ordinals/searchInscriptions.ts +21 -108
- package/tools/wallet/brc100.ts +572 -0
- package/tools/wallet/cancelListing.ts +80 -0
- package/tools/wallet/createOrdinals.ts +62 -143
- package/tools/wallet/getAddress.ts +19 -13
- package/tools/wallet/getBalance.ts +29 -25
- package/tools/wallet/getBsv21Balances.ts +28 -0
- package/tools/wallet/getLockData.ts +25 -0
- package/tools/wallet/getOrdinals.ts +35 -0
- package/tools/wallet/listOrdinal.ts +86 -0
- package/tools/wallet/listTokens.ts +28 -0
- package/tools/wallet/lockBsv.ts +69 -0
- package/tools/wallet/opnsDeregister.ts +80 -0
- package/tools/wallet/opnsRegister.ts +80 -0
- package/tools/wallet/purchaseListing.ts +89 -290
- package/tools/wallet/refreshUtxos.ts +21 -32
- package/tools/wallet/schemas.ts +7 -11
- package/tools/wallet/sendAllBsv.ts +64 -0
- package/tools/wallet/sendToAddress.ts +46 -47
- package/tools/wallet/signBsm.ts +29 -0
- package/tools/wallet/sweepBsv.ts +70 -0
- package/tools/wallet/sweepBsv21.ts +71 -0
- package/tools/wallet/sweepOrdinals.ts +69 -0
- package/tools/wallet/tools.ts +50 -88
- package/tools/wallet/transferOrdToken.ts +137 -129
- package/tools/wallet/unlockBsv.ts +57 -0
- package/tools/wallet/a2bPublishAgent.ts +0 -307
- package/tools/wallet/sendOrdinals.ts +0 -160
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { PrivateKey } from "@bsv/sdk";
|
|
2
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
-
import type {
|
|
5
|
-
ChangeResult,
|
|
6
|
-
LocalSigner,
|
|
7
|
-
SendOrdinalsConfig,
|
|
8
|
-
} from "js-1sat-ord";
|
|
9
|
-
import { sendOrdinals } from "js-1sat-ord";
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
import { V5Broadcaster } from "../../utils/broadcaster";
|
|
12
|
-
import type { Wallet } from "./wallet";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Schema for the sendOrdinals tool arguments
|
|
16
|
-
*/
|
|
17
|
-
export const sendOrdinalsArgsSchema = z.object({
|
|
18
|
-
// Outpoint of the inscription to send (txid_vout format)
|
|
19
|
-
inscriptionOutpoint: z
|
|
20
|
-
.string()
|
|
21
|
-
.describe("Inscription outpoint in format txid_vout"),
|
|
22
|
-
// Destination address to send the inscription to
|
|
23
|
-
destinationAddress: z
|
|
24
|
-
.string()
|
|
25
|
-
.describe("Destination address for the inscription"),
|
|
26
|
-
// Optional metadata for the ordinal transfer
|
|
27
|
-
metadata: z
|
|
28
|
-
.any()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe("Optional MAP metadata for the transfer"),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export type SendOrdinalsArgs = z.infer<typeof sendOrdinalsArgsSchema>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Registers the wallet_sendOrdinals tool for transferring ordinals
|
|
37
|
-
*/
|
|
38
|
-
export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
39
|
-
server.tool(
|
|
40
|
-
"wallet_sendOrdinals",
|
|
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.",
|
|
42
|
-
{ ...sendOrdinalsArgsSchema.shape },
|
|
43
|
-
async ({ inscriptionOutpoint, destinationAddress, metadata }): Promise<CallToolResult> => {
|
|
44
|
-
try {
|
|
45
|
-
// 1. Get private key from wallet
|
|
46
|
-
const paymentPk = wallet.getPrivateKey();
|
|
47
|
-
if (!paymentPk) {
|
|
48
|
-
throw new Error("No private key available in wallet");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 2. Get payment UTXOs from wallet
|
|
52
|
-
const { paymentUtxos, nftUtxos } = await wallet.getUtxos();
|
|
53
|
-
if (!paymentUtxos || paymentUtxos.length === 0) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
"No payment UTXOs available to fund this transaction",
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 3. Get the wallet address for change
|
|
60
|
-
const walletAddress = paymentPk.toAddress().toString();
|
|
61
|
-
|
|
62
|
-
// 4. Parse the inscription outpoint
|
|
63
|
-
const [txid, voutStr] = inscriptionOutpoint.split("_");
|
|
64
|
-
if (!txid || !voutStr) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
"Invalid inscription outpoint format. Expected txid_vout",
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
const vout = Number.parseInt(voutStr, 10);
|
|
70
|
-
|
|
71
|
-
// 5. Find the inscription in nftUtxos
|
|
72
|
-
const inscription = nftUtxos.find(
|
|
73
|
-
(utxo) => utxo.txid === txid && utxo.vout === vout,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
if (!inscription) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Inscription ${inscriptionOutpoint} not found in your wallet`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 6. Create config and transfer the inscription
|
|
83
|
-
const sendOrdinalsConfig: SendOrdinalsConfig = {
|
|
84
|
-
paymentPk,
|
|
85
|
-
paymentUtxos,
|
|
86
|
-
ordinals: [inscription],
|
|
87
|
-
destinations: [{ address: destinationAddress }],
|
|
88
|
-
changeAddress: walletAddress,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const identityKeyWif = process.env.IDENTITY_KEY_WIF;
|
|
92
|
-
const identityPk = identityKeyWif
|
|
93
|
-
? PrivateKey.fromWif(identityKeyWif)
|
|
94
|
-
: undefined;
|
|
95
|
-
if (identityPk) {
|
|
96
|
-
sendOrdinalsConfig.signer = {
|
|
97
|
-
idKey: identityPk,
|
|
98
|
-
} as LocalSigner;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Add metadata if provided
|
|
102
|
-
if (metadata) {
|
|
103
|
-
sendOrdinalsConfig.metaData = metadata;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Using the wallet's key for both payment and ordinals
|
|
107
|
-
sendOrdinalsConfig.ordPk = paymentPk;
|
|
108
|
-
|
|
109
|
-
const result = await sendOrdinals(sendOrdinalsConfig);
|
|
110
|
-
const changeResult = result as ChangeResult;
|
|
111
|
-
// no signing when you send since we don't emit an inscription
|
|
112
|
-
|
|
113
|
-
// 7. Broadcast the transaction
|
|
114
|
-
const disableBroadcasting = process.env.DISABLE_BROADCASTING === "true";
|
|
115
|
-
if (!disableBroadcasting) {
|
|
116
|
-
const broadcaster = new V5Broadcaster();
|
|
117
|
-
await changeResult.tx.broadcast(broadcaster);
|
|
118
|
-
|
|
119
|
-
// 8. Refresh the wallet's UTXOs after spending
|
|
120
|
-
try {
|
|
121
|
-
await wallet.refreshUtxos();
|
|
122
|
-
} catch (refreshError) {
|
|
123
|
-
console.warn(
|
|
124
|
-
"Failed to refresh UTXOs after transaction:",
|
|
125
|
-
refreshError,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// 9. Return transaction details
|
|
130
|
-
return {
|
|
131
|
-
content: [
|
|
132
|
-
{
|
|
133
|
-
type: "text",
|
|
134
|
-
text: JSON.stringify({
|
|
135
|
-
txid: changeResult.tx.id("hex"),
|
|
136
|
-
spentOutpoints: changeResult.spentOutpoints,
|
|
137
|
-
payChange: changeResult.payChange,
|
|
138
|
-
inscriptionOutpoint: inscriptionOutpoint,
|
|
139
|
-
destinationAddress: destinationAddress,
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
content: [
|
|
148
|
-
{
|
|
149
|
-
type: "text",
|
|
150
|
-
text: changeResult.tx.toHex(),
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
} catch (err: unknown) {
|
|
155
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
156
|
-
return { content: [{ type: "text", text: msg }], isError: true };
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
);
|
|
160
|
-
}
|