bsv-mcp 0.0.36 → 0.2.7
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 +124 -0
- package/README.md +233 -4
- package/dist/index.js +120082 -54669
- package/index.ts +1196 -88
- package/next-env.d.ts +6 -0
- package/package.json +58 -15
- package/prompts/bsvSdk/index.ts +5 -5
- package/prompts/bsvSdk/transaction.ts +2 -2
- package/prompts/bsvSdk/wallet.ts +1 -1
- package/prompts/index.ts +1 -1
- package/resources/bitcom.ts +132 -0
- package/resources/resources.ts +7 -3
- package/smithery.yaml +3 -0
- package/test-mcp-server.ts +157 -0
- package/tools/a2b/discover.ts +13 -13
- package/tools/bap/friend.ts +266 -0
- package/tools/bap/generate.test.ts +350 -0
- package/tools/bap/generate.ts +431 -0
- package/tools/bap/getCurrentAddress.ts +69 -0
- package/tools/bap/getId.test.ts +121 -0
- package/tools/bap/getId.ts +169 -0
- package/tools/bap/index.ts +111 -0
- package/tools/bap/types.ts +66 -0
- package/tools/bap/utils.ts +33 -0
- package/tools/bsocial/bmapFollow.ts +121 -0
- package/tools/bsocial/bmapLikes.ts +111 -0
- package/tools/bsocial/bmapReadPosts.ts +148 -0
- package/tools/bsocial/createPost.ts +136 -0
- package/tools/bsocial/index.ts +45 -0
- package/tools/bsocial/readPosts.ts +255 -0
- package/tools/bsv/decodeTransaction.ts +7 -6
- package/tools/bsv/explore.ts +2 -3
- package/tools/bsv/getPrice.ts +1 -9
- package/tools/bsv/token.ts +14 -26
- package/tools/constants.ts +21 -0
- package/tools/index.ts +91 -18
- package/tools/mnee/getBalance.ts +2 -4
- package/tools/mnee/index.ts +8 -0
- package/tools/mnee/parseTx.ts +4 -4
- package/tools/mnee/sendMnee.ts +6 -6
- package/tools/ordinals/getInscription.ts +2 -3
- package/tools/ordinals/getTokenByIdOrTicker.ts +6 -3
- package/tools/ordinals/marketListings.ts +2 -18
- package/tools/ordinals/marketSales.ts +2 -4
- package/tools/ordinals/searchInscriptions.ts +2 -4
- package/tools/utils/aip.ts +46 -0
- package/tools/utils/conversion.ts +1 -0
- package/tools/utils/errorHandler.ts +76 -0
- package/tools/utils/index.ts +56 -14
- package/tools/utils/installAgentMaster.ts +84 -0
- package/tools/utils/logger.ts +20 -0
- package/tools/utils/toolConfig.ts +80 -0
- package/tools/utils/toolRegistration.ts +66 -0
- package/tools/utils/transactionBuilder.ts +196 -0
- package/tools/wallet/a2bPublishAgent.ts +25 -30
- package/tools/wallet/a2bPublishMcp.ts +43 -44
- package/tools/wallet/createOrdinals.ts +13 -20
- package/tools/wallet/fetchPaymentUtxos.ts +48 -39
- package/tools/wallet/gatherCollectionInfo.ts +370 -0
- package/tools/wallet/getAddress.ts +14 -30
- package/tools/wallet/getBalance.ts +54 -0
- package/tools/wallet/getBalanceDroplet.ts +48 -0
- package/tools/wallet/getPublicKey.ts +3 -16
- package/tools/wallet/integratedWallet.ts +120 -0
- package/tools/wallet/mintCollection.ts +373 -0
- package/tools/wallet/purchaseListing.ts +21 -31
- package/tools/wallet/refreshUtxos.ts +2 -14
- package/tools/wallet/schemas.ts +18 -249
- package/tools/wallet/sendOrdinals.ts +14 -21
- package/tools/wallet/sendToAddress.ts +2 -18
- package/tools/wallet/setupDroplet.ts +161 -0
- package/tools/wallet/tools.ts +55 -210
- package/tools/wallet/transactionHelper.ts +121 -0
- package/tools/wallet/transferOrdToken.ts +19 -24
- package/tools/wallet/utxo.ts +62 -0
- package/tools/wallet/wallet.ts +237 -234
- package/vite.config.ts +15 -0
- package/tools/a2b/call.ts +0 -32
package/tools/wallet/schemas.ts
CHANGED
|
@@ -1,77 +1,11 @@
|
|
|
1
|
-
import type { SecurityLevel } from "@bsv/sdk";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
|
|
4
|
-
// Define SecurityLevel to match the BSV SDK exactly
|
|
5
|
-
const SecurityLevelEnum = z.union([z.literal(0), z.literal(1), z.literal(2)]);
|
|
6
|
-
|
|
7
|
-
// Create a custom validator without tuples
|
|
8
|
-
export const walletProtocolSchema = z.custom<[SecurityLevel, string]>((val) => {
|
|
9
|
-
return (
|
|
10
|
-
Array.isArray(val) &&
|
|
11
|
-
val.length === 2 &&
|
|
12
|
-
(val[0] === 0 || val[0] === 1 || val[0] === 2) &&
|
|
13
|
-
typeof val[1] === "string"
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
3
|
// Empty args schema for functions that don't take arguments
|
|
18
4
|
export const emptyArgsSchema = z.object({});
|
|
19
5
|
|
|
20
6
|
// Get public key arguments
|
|
21
7
|
export const getPublicKeyArgsSchema = z.object({});
|
|
22
8
|
|
|
23
|
-
// Create signature arguments
|
|
24
|
-
export const createSignatureArgsSchema = z.object({
|
|
25
|
-
data: z.array(z.number()).optional(),
|
|
26
|
-
hashToDirectlySign: z.array(z.number()).optional(),
|
|
27
|
-
protocolID: walletProtocolSchema,
|
|
28
|
-
keyID: z.string(),
|
|
29
|
-
privilegedReason: z.string().optional(),
|
|
30
|
-
counterparty: z
|
|
31
|
-
.union([z.string(), z.literal("self"), z.literal("anyone")])
|
|
32
|
-
.optional(),
|
|
33
|
-
privileged: z.boolean().optional(),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Verify signature arguments
|
|
37
|
-
export const verifySignatureArgsSchema = z.object({
|
|
38
|
-
data: z.array(z.number()).optional(),
|
|
39
|
-
hashToDirectlyVerify: z.array(z.number()).optional(),
|
|
40
|
-
signature: z.array(z.number()),
|
|
41
|
-
protocolID: walletProtocolSchema,
|
|
42
|
-
keyID: z.string(),
|
|
43
|
-
privilegedReason: z.string().optional(),
|
|
44
|
-
counterparty: z
|
|
45
|
-
.union([z.string(), z.literal("self"), z.literal("anyone")])
|
|
46
|
-
.optional(),
|
|
47
|
-
forSelf: z.boolean().optional(),
|
|
48
|
-
privileged: z.boolean().optional(),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Wallet encryption args
|
|
52
|
-
export const walletEncryptArgsSchema = z.object({
|
|
53
|
-
plaintext: z.array(z.number()),
|
|
54
|
-
protocolID: walletProtocolSchema,
|
|
55
|
-
keyID: z.string(),
|
|
56
|
-
privilegedReason: z.string().optional(),
|
|
57
|
-
counterparty: z
|
|
58
|
-
.union([z.string(), z.literal("self"), z.literal("anyone")])
|
|
59
|
-
.optional(),
|
|
60
|
-
privileged: z.boolean().optional(),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Wallet decryption args
|
|
64
|
-
export const walletDecryptArgsSchema = z.object({
|
|
65
|
-
ciphertext: z.array(z.number()),
|
|
66
|
-
protocolID: walletProtocolSchema,
|
|
67
|
-
keyID: z.string(),
|
|
68
|
-
privilegedReason: z.string().optional(),
|
|
69
|
-
counterparty: z
|
|
70
|
-
.union([z.string(), z.literal("self"), z.literal("anyone")])
|
|
71
|
-
.optional(),
|
|
72
|
-
privileged: z.boolean().optional(),
|
|
73
|
-
});
|
|
74
|
-
|
|
75
9
|
// Combined wallet encryption/decryption args
|
|
76
10
|
export const walletEncryptionArgsSchema = z
|
|
77
11
|
.object({
|
|
@@ -91,190 +25,25 @@ export const walletEncryptionArgsSchema = z
|
|
|
91
25
|
.optional()
|
|
92
26
|
.default("utf8")
|
|
93
27
|
.describe("Encoding of text data (default: utf8)"),
|
|
28
|
+
recipientPublicKeyHex: z
|
|
29
|
+
.string()
|
|
30
|
+
.length(66)
|
|
31
|
+
.regex(/^(02|03)[0-9a-fA-F]{64}$/)
|
|
32
|
+
.optional()
|
|
33
|
+
.describe(
|
|
34
|
+
"Recipient's public key in hex format (required for encryption mode)",
|
|
35
|
+
),
|
|
94
36
|
})
|
|
95
|
-
.describe("Schema for encryption and decryption operations")
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
message: z.string(),
|
|
106
|
-
hmac: z.string(),
|
|
107
|
-
publicKey: z.string(),
|
|
108
|
-
encoding: z.enum(["utf8", "hex", "base64"]).optional(),
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// Transaction input schema
|
|
112
|
-
export const transactionInputSchema = z.object({
|
|
113
|
-
outpoint: z.string(),
|
|
114
|
-
inputDescription: z.string(), // Required field
|
|
115
|
-
sequence: z.number().optional(),
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Transaction output schema
|
|
119
|
-
export const transactionOutputSchema = z.object({
|
|
120
|
-
lockingScript: z.string(),
|
|
121
|
-
satoshis: z.number(),
|
|
122
|
-
outputDescription: z.string(), // Required field
|
|
123
|
-
change: z.boolean().optional(),
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Create action args
|
|
127
|
-
export const createActionArgsSchema = z.object({
|
|
128
|
-
description: z.string(),
|
|
129
|
-
labels: z.array(z.string()).optional(),
|
|
130
|
-
lockTime: z.number().optional(),
|
|
131
|
-
version: z.number().optional(),
|
|
132
|
-
inputBEEF: z.array(z.number()).optional(),
|
|
133
|
-
inputs: z.array(transactionInputSchema).optional(),
|
|
134
|
-
outputs: z.array(transactionOutputSchema).optional(),
|
|
135
|
-
options: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Sign action args
|
|
139
|
-
export const signActionArgsSchema = z.object({
|
|
140
|
-
reference: z.string(),
|
|
141
|
-
spends: z.record(z.any()).optional(),
|
|
142
|
-
options: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// List actions args
|
|
146
|
-
export const listActionsArgsSchema = z.object({
|
|
147
|
-
labels: z.array(z.string()),
|
|
148
|
-
labelQueryMode: z.enum(["any", "all"]).optional(),
|
|
149
|
-
limit: z.number().optional(),
|
|
150
|
-
offset: z.number().optional(),
|
|
151
|
-
includeInputs: z.boolean().optional(),
|
|
152
|
-
includeOutputs: z.boolean().optional(),
|
|
153
|
-
includeLabels: z.boolean().optional(),
|
|
154
|
-
includeInputSourceLockingScripts: z.boolean().optional(),
|
|
155
|
-
includeInputUnlockingScripts: z.boolean().optional(),
|
|
156
|
-
seekPermission: z.boolean().optional(),
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// List outputs args
|
|
160
|
-
export const listOutputsArgsSchema = z.object({
|
|
161
|
-
basket: z.string(),
|
|
162
|
-
tags: z.array(z.string()).optional(),
|
|
163
|
-
tagQueryMode: z.enum(["all", "any"]).optional(),
|
|
164
|
-
limit: z.number().optional(),
|
|
165
|
-
offset: z.number().optional(),
|
|
166
|
-
include: z.enum(["locking scripts", "entire transactions"]).optional(),
|
|
167
|
-
includeLabels: z.boolean().optional(),
|
|
168
|
-
includeTags: z.boolean().optional(),
|
|
169
|
-
includeCustomInstructions: z.boolean().optional(),
|
|
170
|
-
seekPermission: z.boolean().optional(),
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Reveal counterparty key linkage args
|
|
174
|
-
export const revealCounterpartyKeyLinkageArgsSchema = z.object({
|
|
175
|
-
counterparty: z.string(),
|
|
176
|
-
verifier: z.string(),
|
|
177
|
-
privileged: z.boolean().optional(),
|
|
178
|
-
privilegedReason: z.string().optional(),
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Reveal specific key linkage args
|
|
182
|
-
export const revealSpecificKeyLinkageArgsSchema = z.object({
|
|
183
|
-
keyID: z.number(),
|
|
184
|
-
verifier: z.string(),
|
|
185
|
-
privileged: z.boolean().optional(),
|
|
186
|
-
privilegedReason: z.string().optional(),
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Abort action args
|
|
190
|
-
export const abortActionArgsSchema = z.object({
|
|
191
|
-
reference: z.string(),
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Internalize action args
|
|
195
|
-
export const internalizeActionArgsSchema = z.object({
|
|
196
|
-
tx: z.array(z.number()),
|
|
197
|
-
outputs: z.array(
|
|
198
|
-
z.object({
|
|
199
|
-
outputIndex: z.number(),
|
|
200
|
-
protocol: z.enum(["wallet payment", "basket insertion"]),
|
|
201
|
-
lockingScript: z.string(),
|
|
202
|
-
satoshis: z.number(),
|
|
203
|
-
}),
|
|
204
|
-
),
|
|
205
|
-
description: z.string(),
|
|
206
|
-
labels: z.array(z.string()).optional(),
|
|
207
|
-
seekPermission: z.boolean().optional(),
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
// Relinquish output args
|
|
211
|
-
export const relinquishOutputArgsSchema = z.object({
|
|
212
|
-
basket: z.string(),
|
|
213
|
-
output: z.string(),
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Acquire certificate args
|
|
217
|
-
export const acquireCertificateArgsSchema = z.object({
|
|
218
|
-
type: z.string(),
|
|
219
|
-
certifier: z.string(),
|
|
220
|
-
acquisitionProtocol: z.enum(["direct", "issuance"]),
|
|
221
|
-
fields: z.record(z.string()),
|
|
222
|
-
certifierUrl: z.string().optional(),
|
|
223
|
-
serialNumber: z.string().optional(),
|
|
224
|
-
signature: z.string().optional(),
|
|
225
|
-
revocationOutpoint: z.string().optional(),
|
|
226
|
-
keyringForSubject: z.record(z.string()).optional(),
|
|
227
|
-
keyringRevealer: z.string().optional(),
|
|
228
|
-
privileged: z.boolean().optional(),
|
|
229
|
-
privilegedReason: z.string().optional(),
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// List certificates args
|
|
233
|
-
export const listCertificatesArgsSchema = z.object({
|
|
234
|
-
certifiers: z.array(z.string()),
|
|
235
|
-
types: z.array(z.string()),
|
|
236
|
-
limit: z.number().optional(),
|
|
237
|
-
offset: z.number().optional(),
|
|
238
|
-
privileged: z.boolean().optional(),
|
|
239
|
-
privilegedReason: z.string().optional(),
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// Prove certificate args
|
|
243
|
-
export const proveCertificateArgsSchema = z.object({
|
|
244
|
-
certificate: z.object({}),
|
|
245
|
-
fieldsToReveal: z.array(z.string()),
|
|
246
|
-
verifier: z.string(),
|
|
247
|
-
privileged: z.boolean().optional(),
|
|
248
|
-
privilegedReason: z.string().optional(),
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// Relinquish certificate args
|
|
252
|
-
export const relinquishCertificateArgsSchema = z.object({
|
|
253
|
-
type: z.string(),
|
|
254
|
-
serialNumber: z.string(),
|
|
255
|
-
certifier: z.string(),
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// Discover by identity key args
|
|
259
|
-
export const discoverByIdentityKeyArgsSchema = z.object({
|
|
260
|
-
identityKey: z.string(),
|
|
261
|
-
limit: z.number().optional(),
|
|
262
|
-
offset: z.number().optional(),
|
|
263
|
-
seekPermission: z.boolean().optional(),
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
// Discover by attributes args
|
|
267
|
-
export const discoverByAttributesArgsSchema = z.object({
|
|
268
|
-
attributes: z.record(z.string()),
|
|
269
|
-
limit: z.number().optional(),
|
|
270
|
-
offset: z.number().optional(),
|
|
271
|
-
seekPermission: z.boolean().optional(),
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// Get header for height args
|
|
275
|
-
export const getHeaderArgsSchema = z.object({
|
|
276
|
-
height: z.number(),
|
|
277
|
-
});
|
|
37
|
+
.describe("Schema for encryption and decryption operations")
|
|
38
|
+
.superRefine((val, ctx) => {
|
|
39
|
+
if (val.mode === "encrypt" && !val.recipientPublicKeyHex) {
|
|
40
|
+
ctx.addIssue({
|
|
41
|
+
code: z.ZodIssueCode.custom,
|
|
42
|
+
message: "recipientPublicKeyHex is required when mode is 'encrypt'",
|
|
43
|
+
path: ["recipientPublicKeyHex"],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
278
47
|
|
|
279
48
|
// Get address args
|
|
280
49
|
export const getAddressArgsSchema = z.object({});
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { PrivateKey } from "@bsv/sdk";
|
|
2
2
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
CallToolResult,
|
|
6
|
-
ServerNotification,
|
|
7
|
-
ServerRequest,
|
|
8
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
-
import { sendOrdinals } from "js-1sat-ord";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
10
4
|
import type {
|
|
11
5
|
ChangeResult,
|
|
12
6
|
LocalSigner,
|
|
13
7
|
SendOrdinalsConfig,
|
|
14
8
|
} from "js-1sat-ord";
|
|
15
|
-
import {
|
|
9
|
+
import { sendOrdinals } from "js-1sat-ord";
|
|
16
10
|
import { z } from "zod";
|
|
11
|
+
import { V5Broadcaster } from "../../utils/broadcaster";
|
|
17
12
|
import type { Wallet } from "./wallet";
|
|
18
13
|
|
|
19
14
|
/**
|
|
@@ -44,11 +39,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
44
39
|
server.tool(
|
|
45
40
|
"wallet_sendOrdinals",
|
|
46
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.",
|
|
47
|
-
{
|
|
48
|
-
async (
|
|
49
|
-
{ args }: { args: SendOrdinalsArgs },
|
|
50
|
-
extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
|
|
51
|
-
): Promise<CallToolResult> => {
|
|
42
|
+
{ ...sendOrdinalsArgsSchema.shape },
|
|
43
|
+
async ({ inscriptionOutpoint, destinationAddress, metadata }): Promise<CallToolResult> => {
|
|
52
44
|
try {
|
|
53
45
|
// 1. Get private key from wallet
|
|
54
46
|
const paymentPk = wallet.getPrivateKey();
|
|
@@ -68,7 +60,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
68
60
|
const walletAddress = paymentPk.toAddress().toString();
|
|
69
61
|
|
|
70
62
|
// 4. Parse the inscription outpoint
|
|
71
|
-
const [txid, voutStr] =
|
|
63
|
+
const [txid, voutStr] = inscriptionOutpoint.split("_");
|
|
72
64
|
if (!txid || !voutStr) {
|
|
73
65
|
throw new Error(
|
|
74
66
|
"Invalid inscription outpoint format. Expected txid_vout",
|
|
@@ -83,7 +75,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
83
75
|
|
|
84
76
|
if (!inscription) {
|
|
85
77
|
throw new Error(
|
|
86
|
-
`Inscription ${
|
|
78
|
+
`Inscription ${inscriptionOutpoint} not found in your wallet`,
|
|
87
79
|
);
|
|
88
80
|
}
|
|
89
81
|
|
|
@@ -92,7 +84,7 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
92
84
|
paymentPk,
|
|
93
85
|
paymentUtxos,
|
|
94
86
|
ordinals: [inscription],
|
|
95
|
-
destinations: [{ address:
|
|
87
|
+
destinations: [{ address: destinationAddress }],
|
|
96
88
|
changeAddress: walletAddress,
|
|
97
89
|
};
|
|
98
90
|
|
|
@@ -107,8 +99,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
107
99
|
}
|
|
108
100
|
|
|
109
101
|
// Add metadata if provided
|
|
110
|
-
if (
|
|
111
|
-
sendOrdinalsConfig.metaData =
|
|
102
|
+
if (metadata) {
|
|
103
|
+
sendOrdinalsConfig.metaData = metadata;
|
|
112
104
|
}
|
|
113
105
|
|
|
114
106
|
// Using the wallet's key for both payment and ordinals
|
|
@@ -121,7 +113,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
121
113
|
// 7. Broadcast the transaction
|
|
122
114
|
const disableBroadcasting = process.env.DISABLE_BROADCASTING === "true";
|
|
123
115
|
if (!disableBroadcasting) {
|
|
124
|
-
|
|
116
|
+
const broadcaster = new V5Broadcaster();
|
|
117
|
+
await changeResult.tx.broadcast(broadcaster);
|
|
125
118
|
|
|
126
119
|
// 8. Refresh the wallet's UTXOs after spending
|
|
127
120
|
try {
|
|
@@ -142,8 +135,8 @@ export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
|
142
135
|
txid: changeResult.tx.id("hex"),
|
|
143
136
|
spentOutpoints: changeResult.spentOutpoints,
|
|
144
137
|
payChange: changeResult.payChange,
|
|
145
|
-
inscriptionOutpoint:
|
|
146
|
-
destinationAddress:
|
|
138
|
+
inscriptionOutpoint: inscriptionOutpoint,
|
|
139
|
+
destinationAddress: destinationAddress,
|
|
147
140
|
}),
|
|
148
141
|
},
|
|
149
142
|
],
|
|
@@ -1,15 +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
3
|
import { toSatoshi } from "satoshi-token";
|
|
5
|
-
import type { z } from "zod";
|
|
6
4
|
import { getBsvPriceWithCache } from "../bsv/getPrice";
|
|
7
5
|
import { sendToAddressArgsSchema } from "./schemas";
|
|
8
6
|
import type { Wallet } from "./wallet";
|
|
9
7
|
|
|
10
|
-
// Use the schema imported from schemas.ts
|
|
11
|
-
export type SendToAddressArgs = z.infer<typeof sendToAddressArgsSchema>;
|
|
12
|
-
|
|
13
8
|
/**
|
|
14
9
|
* Register the sendToAddress tool
|
|
15
10
|
*/
|
|
@@ -17,20 +12,9 @@ export function registerSendToAddressTool(server: McpServer, wallet: Wallet) {
|
|
|
17
12
|
server.tool(
|
|
18
13
|
"wallet_sendToAddress",
|
|
19
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.",
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
async (
|
|
24
|
-
{ args }: { args: SendToAddressArgs },
|
|
25
|
-
extra: RequestHandlerExtra,
|
|
26
|
-
) => {
|
|
15
|
+
{ ...sendToAddressArgsSchema.shape },
|
|
16
|
+
async ({ address, amount, currency = "BSV", description = "Send to address" }) => {
|
|
27
17
|
try {
|
|
28
|
-
const {
|
|
29
|
-
address,
|
|
30
|
-
amount,
|
|
31
|
-
currency = "BSV",
|
|
32
|
-
description = "Send to address",
|
|
33
|
-
} = args;
|
|
34
18
|
|
|
35
19
|
// Convert to satoshis
|
|
36
20
|
let satoshis: number;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { IntegratedWallet } from "./integratedWallet";
|
|
4
|
+
|
|
5
|
+
const setupDropletArgsSchema = z.object({
|
|
6
|
+
action: z.enum(["register_key", "create_faucet", "check_status"]),
|
|
7
|
+
faucetName: z.string().optional(),
|
|
8
|
+
fixedDropSats: z.number().optional(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type SetupDropletArgs = z.infer<typeof setupDropletArgsSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Register the setupDroplet tool for Droplet API initialization
|
|
15
|
+
*/
|
|
16
|
+
export function registerSetupDropletTool(
|
|
17
|
+
server: McpServer,
|
|
18
|
+
integratedWallet: IntegratedWallet,
|
|
19
|
+
) {
|
|
20
|
+
server.tool(
|
|
21
|
+
"wallet_setupDroplet",
|
|
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)",
|
|
23
|
+
{ ...setupDropletArgsSchema.shape },
|
|
24
|
+
async ({ action, faucetName, fixedDropSats }) => {
|
|
25
|
+
try {
|
|
26
|
+
const dropletClient = integratedWallet.getDropletClient();
|
|
27
|
+
if (!dropletClient) {
|
|
28
|
+
throw new Error("Droplet client not configured");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const config = dropletClient.getConfig();
|
|
32
|
+
const apiUrl = config.apiUrl;
|
|
33
|
+
const authKey = config.authKey;
|
|
34
|
+
|
|
35
|
+
switch (action) {
|
|
36
|
+
case "register_key": {
|
|
37
|
+
if (!authKey) {
|
|
38
|
+
throw new Error("No auth key configured");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const pubkey = authKey.toPublicKey().toString();
|
|
42
|
+
|
|
43
|
+
// Register the key with the Droplet API
|
|
44
|
+
const response = await fetch(`${apiUrl}/auth/register`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({ publicKey: pubkey }),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const error = await response.text();
|
|
54
|
+
throw new Error(`Failed to register key: ${error}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: JSON.stringify({
|
|
62
|
+
status: "success",
|
|
63
|
+
message: "Key registered successfully",
|
|
64
|
+
publicKey: pubkey,
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
case "create_faucet": {
|
|
72
|
+
if (!faucetName) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"faucetName is required for create_faucet action",
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// First, ensure the key is registered
|
|
79
|
+
if (authKey) {
|
|
80
|
+
const pubkey = authKey.toPublicKey().toString();
|
|
81
|
+
await fetch(`${apiUrl}/auth/register`, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
},
|
|
86
|
+
body: JSON.stringify({ publicKey: pubkey }),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Create the faucet
|
|
91
|
+
const body = {
|
|
92
|
+
name: faucetName,
|
|
93
|
+
fixed_drop_sats: fixedDropSats || 1000,
|
|
94
|
+
max_consolidation_inputs: 20,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const headers = authKey
|
|
98
|
+
? await dropletClient.getAuthHeaders("POST", "/faucets", body)
|
|
99
|
+
: {};
|
|
100
|
+
|
|
101
|
+
const response = await fetch(`${apiUrl}/faucets`, {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: {
|
|
104
|
+
"Content-Type": "application/json",
|
|
105
|
+
...headers,
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(body),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
const error = await response.text();
|
|
112
|
+
throw new Error(`Failed to create faucet: ${error}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const result = await response.json();
|
|
116
|
+
return {
|
|
117
|
+
content: [
|
|
118
|
+
{
|
|
119
|
+
type: "text",
|
|
120
|
+
text: JSON.stringify({
|
|
121
|
+
status: "success",
|
|
122
|
+
message: "Faucet created successfully",
|
|
123
|
+
faucet: result,
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
case "check_status": {
|
|
131
|
+
const status = await dropletClient.getFaucetStatus();
|
|
132
|
+
return {
|
|
133
|
+
content: [
|
|
134
|
+
{
|
|
135
|
+
type: "text",
|
|
136
|
+
text: JSON.stringify({
|
|
137
|
+
status: "success",
|
|
138
|
+
faucetStatus: status,
|
|
139
|
+
}),
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
default:
|
|
146
|
+
throw new Error(`Unknown action: ${action}`);
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return {
|
|
150
|
+
content: [
|
|
151
|
+
{
|
|
152
|
+
type: "text",
|
|
153
|
+
text: error instanceof Error ? error.message : String(error),
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
isError: true,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
}
|