bsv-mcp 0.0.1 → 0.0.2
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/LICENSE +21 -0
- package/README.md +5 -1
- package/index.ts +2 -4
- package/package.json +1 -1
- package/tools/constants.ts +21 -0
- package/tools/wallet/createOrdinals.ts +117 -0
- package/tools/wallet/purchaseListing.ts +44 -4
- package/tools/wallet/sendOrdinals.ts +119 -0
- package/tools/wallet/sendToAddress.ts +10 -6
- package/tools/wallet/tools.ts +30 -19
- package/tools/wallet/wallet.ts +23 -35
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BSV-MCP Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Bitcoin SV MCP Server
|
|
2
2
|
|
|
3
|
+
> **⚠️ NOTICE: Experimental Work in Progress**
|
|
4
|
+
> This project is in an early experimental stage. Features may change, and the API is not yet stable.
|
|
5
|
+
> Contributions, feedback, and bug reports are welcome! Feel free to open issues or submit pull requests.
|
|
6
|
+
|
|
3
7
|
A collection of Bitcoin SV (BSV) tools for the Model Context Protocol (MCP) framework. This library provides wallet, ordinals, and utility functions for BSV blockchain interaction.
|
|
4
8
|
|
|
5
9
|
## Installation
|
|
@@ -255,4 +259,4 @@ bun test
|
|
|
255
259
|
|
|
256
260
|
## License
|
|
257
261
|
|
|
258
|
-
|
|
262
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
PrivateKey,
|
|
4
|
-
} from "@bsv/sdk";
|
|
2
|
+
import { PrivateKey } from "@bsv/sdk";
|
|
5
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
5
|
import { registerAllTools } from "./tools";
|
|
@@ -10,7 +8,7 @@ import { Wallet } from "./tools/wallet/wallet";
|
|
|
10
8
|
|
|
11
9
|
const server = new McpServer({
|
|
12
10
|
name: "Bitcoin SV MCP",
|
|
13
|
-
version: "
|
|
11
|
+
version: "0.0.1",
|
|
14
12
|
});
|
|
15
13
|
|
|
16
14
|
// Singleton wallet instance (for demo, could be replaced with real key management)
|
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for BSV MCP Tools
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Market fee percentage applied to all marketplace purchases
|
|
7
|
+
* Expressed as a decimal (e.g., 0.03 = 3%)
|
|
8
|
+
*/
|
|
9
|
+
export const MARKET_FEE_PERCENTAGE = 0.03;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Market wallet address where fees are sent
|
|
13
|
+
* This is the recipient address for marketplace fees
|
|
14
|
+
*/
|
|
15
|
+
export const MARKET_WALLET_ADDRESS = "15q8YQSqUa9uTh6gh4AVixxq29xkpBBP9z";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Minimum fee in satoshis
|
|
19
|
+
* Market fee will never be less than this amount
|
|
20
|
+
*/
|
|
21
|
+
export const MINIMUM_MARKET_FEE_SATOSHIS = 10000; // 10000 satoshis = 0.0001 BSV
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { createOrdinals } from "js-1sat-ord";
|
|
5
|
+
import type {
|
|
6
|
+
ChangeResult,
|
|
7
|
+
Destination,
|
|
8
|
+
Inscription,
|
|
9
|
+
PreMAP,
|
|
10
|
+
CreateOrdinalsCollectionMetadata,
|
|
11
|
+
CreateOrdinalsCollectionItemMetadata
|
|
12
|
+
} from "js-1sat-ord";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import type { Wallet } from "./wallet";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Schema for the createOrdinals tool arguments.
|
|
18
|
+
* This is a simplified interface compared to the full CreateOrdinalsConfig
|
|
19
|
+
* in js-1sat-ord. The wallet will provide UTXOs, private key, etc.
|
|
20
|
+
*/
|
|
21
|
+
export const createOrdinalsArgsSchema = z.object({
|
|
22
|
+
// Base64-encoded data to inscribe
|
|
23
|
+
dataB64: z.string().describe("Base64-encoded content to inscribe"),
|
|
24
|
+
// Content type (e.g., "image/jpeg", "text/plain", etc.)
|
|
25
|
+
contentType: z.string().describe("MIME type of the content"),
|
|
26
|
+
// Optional destination address (if not provided, uses the wallet's address)
|
|
27
|
+
destinationAddress: z.string().optional().describe("Optional destination address for the ordinal"),
|
|
28
|
+
// Optional metadata for the inscription
|
|
29
|
+
metadata: z.any().optional().describe("Optional MAP metadata for the inscription")
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type CreateOrdinalsArgs = z.infer<typeof createOrdinalsArgsSchema>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Registers the wallet_createOrdinals tool for minting ordinals/inscriptions
|
|
36
|
+
*/
|
|
37
|
+
export function registerCreateOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
38
|
+
server.tool(
|
|
39
|
+
"wallet_createOrdinals",
|
|
40
|
+
{ args: createOrdinalsArgsSchema },
|
|
41
|
+
async (
|
|
42
|
+
{ args }: { args: CreateOrdinalsArgs },
|
|
43
|
+
extra: RequestHandlerExtra,
|
|
44
|
+
): Promise<CallToolResult> => {
|
|
45
|
+
try {
|
|
46
|
+
// 1. Get private key from wallet
|
|
47
|
+
const paymentPk = wallet.getPrivateKey();
|
|
48
|
+
if (!paymentPk) {
|
|
49
|
+
throw new Error("No private key available in wallet");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 2. Get payment UTXOs from wallet
|
|
53
|
+
const { paymentUtxos } = await wallet.getUtxos();
|
|
54
|
+
if (!paymentUtxos || paymentUtxos.length === 0) {
|
|
55
|
+
throw new Error("No payment UTXOs available to fund this inscription");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 3. Get the wallet address for change/destination if not provided
|
|
59
|
+
const walletAddress = paymentPk.toAddress().toString();
|
|
60
|
+
|
|
61
|
+
// 4. Create the inscription object
|
|
62
|
+
const inscription: Inscription = {
|
|
63
|
+
dataB64: args.dataB64,
|
|
64
|
+
contentType: args.contentType,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// 5. Create the destination
|
|
68
|
+
const destinations: Destination[] = [
|
|
69
|
+
{
|
|
70
|
+
address: args.destinationAddress || walletAddress,
|
|
71
|
+
inscription,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
// 6. Create and broadcast the transaction
|
|
76
|
+
const result = await createOrdinals({
|
|
77
|
+
utxos: paymentUtxos,
|
|
78
|
+
destinations,
|
|
79
|
+
paymentPk,
|
|
80
|
+
changeAddress: walletAddress,
|
|
81
|
+
metaData: args.metadata as PreMAP | CreateOrdinalsCollectionMetadata | CreateOrdinalsCollectionItemMetadata,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const changeResult = result as ChangeResult;
|
|
85
|
+
|
|
86
|
+
// 7. Broadcast the transaction
|
|
87
|
+
await changeResult.tx.broadcast();
|
|
88
|
+
|
|
89
|
+
// 8. Refresh the wallet's UTXOs after spending
|
|
90
|
+
try {
|
|
91
|
+
await wallet.refreshUtxos();
|
|
92
|
+
} catch (refreshError) {
|
|
93
|
+
console.warn("Failed to refresh UTXOs after transaction:", refreshError);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 9. Return transaction details
|
|
97
|
+
return {
|
|
98
|
+
content: [
|
|
99
|
+
{
|
|
100
|
+
type: "text",
|
|
101
|
+
text: JSON.stringify({
|
|
102
|
+
txid: changeResult.tx.id("hex"),
|
|
103
|
+
spentOutpoints: changeResult.spentOutpoints,
|
|
104
|
+
payChange: changeResult.payChange,
|
|
105
|
+
inscriptionAddress: args.destinationAddress || walletAddress,
|
|
106
|
+
contentType: args.contentType,
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
} catch (err: unknown) {
|
|
112
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
113
|
+
return { content: [{ type: "text", text: msg }], isError: true };
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { PrivateKey } from "@bsv/sdk";
|
|
1
|
+
// import { PrivateKey } from "@bsv/sdk"; // not used here
|
|
2
2
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
5
|
import {
|
|
5
6
|
type ExistingListing,
|
|
7
|
+
type Payment,
|
|
6
8
|
type Utxo,
|
|
7
9
|
oneSatBroadcaster,
|
|
8
10
|
purchaseOrdListing,
|
|
9
11
|
} from "js-1sat-ord";
|
|
10
12
|
import type { z } from "zod";
|
|
13
|
+
import {
|
|
14
|
+
MARKET_FEE_PERCENTAGE,
|
|
15
|
+
MARKET_WALLET_ADDRESS,
|
|
16
|
+
MINIMUM_MARKET_FEE_SATOSHIS,
|
|
17
|
+
} from "../constants";
|
|
11
18
|
import { purchaseListingArgsSchema } from "./schemas";
|
|
12
19
|
import type { Wallet } from "./wallet";
|
|
13
20
|
|
|
@@ -32,7 +39,7 @@ interface ListingResponse {
|
|
|
32
39
|
* 1. Parses the listing outpoint to get the txid and vout
|
|
33
40
|
* 2. Fetches the listing UTXO from the ordinals API
|
|
34
41
|
* 3. Gets the wallet's payment UTXOs (using the wallet's internal UTXO management)
|
|
35
|
-
* 4. Uses purchaseOrdListing to create a purchase transaction
|
|
42
|
+
* 4. Uses purchaseOrdListing to create a purchase transaction with market fee
|
|
36
43
|
* 5. Broadcasts the transaction
|
|
37
44
|
* 6. Returns the transaction details
|
|
38
45
|
*/
|
|
@@ -46,7 +53,7 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
|
|
|
46
53
|
async (
|
|
47
54
|
{ args }: { args: z.infer<typeof purchaseListingArgsSchema> },
|
|
48
55
|
extra: RequestHandlerExtra,
|
|
49
|
-
) => {
|
|
56
|
+
): Promise<CallToolResult> => {
|
|
50
57
|
try {
|
|
51
58
|
console.log(`Attempting to purchase listing: ${args.listingOutpoint}`);
|
|
52
59
|
console.log("Using wallet instance:", wallet);
|
|
@@ -74,6 +81,20 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
|
|
|
74
81
|
throw new Error("Listing doesn't have payout information");
|
|
75
82
|
}
|
|
76
83
|
|
|
84
|
+
// Calculate the market fee (3% of listing price)
|
|
85
|
+
const listingPrice = listingData.data.list.price;
|
|
86
|
+
let marketFee = Math.round(listingPrice * MARKET_FEE_PERCENTAGE);
|
|
87
|
+
|
|
88
|
+
// Ensure minimum fee
|
|
89
|
+
if (marketFee < MINIMUM_MARKET_FEE_SATOSHIS) {
|
|
90
|
+
marketFee = MINIMUM_MARKET_FEE_SATOSHIS;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.log(`Listing price: ${listingPrice} satoshis`);
|
|
94
|
+
console.log(
|
|
95
|
+
`Market fee: ${marketFee} satoshis (${MARKET_FEE_PERCENTAGE * 100}%)`,
|
|
96
|
+
);
|
|
97
|
+
|
|
77
98
|
// Parse the listing outpoint to get txid and vout
|
|
78
99
|
const [txid, voutStr] = args.listingOutpoint.split("_");
|
|
79
100
|
if (!txid) {
|
|
@@ -112,16 +133,33 @@ export function registerPurchaseListingTool(server: McpServer, wallet: Wallet) {
|
|
|
112
133
|
throw new Error(
|
|
113
134
|
`No payment UTXOs available for address ${paymentAddress}.
|
|
114
135
|
Please fund this wallet address with enough BSV to cover the purchase price
|
|
115
|
-
(${listingData.data.list.price} satoshis) plus transaction fees.`,
|
|
136
|
+
(${listingData.data.list.price} satoshis) plus market fee (${marketFee} satoshis) and transaction fees.`,
|
|
116
137
|
);
|
|
117
138
|
}
|
|
118
139
|
|
|
140
|
+
// Define market fee payment
|
|
141
|
+
const additionalPayments: Payment[] = [
|
|
142
|
+
{
|
|
143
|
+
to: MARKET_WALLET_ADDRESS,
|
|
144
|
+
amount: marketFee,
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
// Define metadata for the transaction
|
|
149
|
+
const metaData = {
|
|
150
|
+
app: "bsv-mcp",
|
|
151
|
+
type: "ord",
|
|
152
|
+
op: "purchase",
|
|
153
|
+
};
|
|
154
|
+
|
|
119
155
|
// Create the purchase transaction using the library's config type
|
|
120
156
|
const transaction = await purchaseOrdListing({
|
|
121
157
|
utxos: paymentUtxos,
|
|
122
158
|
paymentPk,
|
|
123
159
|
ordAddress: args.ordAddress,
|
|
124
160
|
listing,
|
|
161
|
+
additionalPayments,
|
|
162
|
+
metaData,
|
|
125
163
|
});
|
|
126
164
|
|
|
127
165
|
// After successful transaction creation, refresh the wallet's UTXOs
|
|
@@ -162,6 +200,8 @@ Please fund this wallet address with enough BSV to cover the purchase price
|
|
|
162
200
|
listingOutpoint: args.listingOutpoint,
|
|
163
201
|
destinationAddress: args.ordAddress,
|
|
164
202
|
price: listingData.data.list.price,
|
|
203
|
+
marketFee,
|
|
204
|
+
marketFeeAddress: MARKET_WALLET_ADDRESS,
|
|
165
205
|
}),
|
|
166
206
|
},
|
|
167
207
|
],
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { sendOrdinals } from "js-1sat-ord";
|
|
5
|
+
import type { ChangeResult, SendOrdinalsConfig } from "js-1sat-ord";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import type { Wallet } from "./wallet";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Schema for the sendOrdinals tool arguments
|
|
11
|
+
*/
|
|
12
|
+
export const sendOrdinalsArgsSchema = z.object({
|
|
13
|
+
// Outpoint of the inscription to send (txid_vout format)
|
|
14
|
+
inscriptionOutpoint: z.string().describe("Inscription outpoint in format txid_vout"),
|
|
15
|
+
// Destination address to send the inscription to
|
|
16
|
+
destinationAddress: z.string().describe("Destination address for the inscription"),
|
|
17
|
+
// Optional metadata for the ordinal transfer
|
|
18
|
+
metadata: z.any().optional().describe("Optional MAP metadata for the transfer"),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type SendOrdinalsArgs = z.infer<typeof sendOrdinalsArgsSchema>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Registers the wallet_sendOrdinals tool for transferring ordinals
|
|
25
|
+
*/
|
|
26
|
+
export function registerSendOrdinalsTool(server: McpServer, wallet: Wallet) {
|
|
27
|
+
server.tool(
|
|
28
|
+
"wallet_sendOrdinals",
|
|
29
|
+
{ args: sendOrdinalsArgsSchema },
|
|
30
|
+
async (
|
|
31
|
+
{ args }: { args: SendOrdinalsArgs },
|
|
32
|
+
extra: RequestHandlerExtra,
|
|
33
|
+
): Promise<CallToolResult> => {
|
|
34
|
+
try {
|
|
35
|
+
// 1. Get private key from wallet
|
|
36
|
+
const paymentPk = wallet.getPrivateKey();
|
|
37
|
+
if (!paymentPk) {
|
|
38
|
+
throw new Error("No private key available in wallet");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 2. Get payment UTXOs from wallet
|
|
42
|
+
const { paymentUtxos, nftUtxos } = await wallet.getUtxos();
|
|
43
|
+
if (!paymentUtxos || paymentUtxos.length === 0) {
|
|
44
|
+
throw new Error("No payment UTXOs available to fund this transaction");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 3. Get the wallet address for change
|
|
48
|
+
const walletAddress = paymentPk.toAddress().toString();
|
|
49
|
+
|
|
50
|
+
// 4. Parse the inscription outpoint
|
|
51
|
+
const [txid, voutStr] = args.inscriptionOutpoint.split('_');
|
|
52
|
+
if (!txid || !voutStr) {
|
|
53
|
+
throw new Error("Invalid inscription outpoint format. Expected txid_vout");
|
|
54
|
+
}
|
|
55
|
+
const vout = Number.parseInt(voutStr, 10);
|
|
56
|
+
|
|
57
|
+
// 5. Find the inscription in nftUtxos
|
|
58
|
+
const inscription = nftUtxos.find(
|
|
59
|
+
(utxo) => utxo.txid === txid && utxo.vout === vout
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (!inscription) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Inscription ${args.inscriptionOutpoint} not found in your wallet`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 6. Create config and transfer the inscription
|
|
69
|
+
const sendOrdinalsConfig: SendOrdinalsConfig = {
|
|
70
|
+
paymentPk,
|
|
71
|
+
paymentUtxos,
|
|
72
|
+
ordinals: [inscription],
|
|
73
|
+
destinations: [{ address: args.destinationAddress }],
|
|
74
|
+
changeAddress: walletAddress,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Add metadata if provided
|
|
78
|
+
if (args.metadata) {
|
|
79
|
+
sendOrdinalsConfig.metaData = args.metadata;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Using the wallet's key for both payment and ordinals
|
|
83
|
+
sendOrdinalsConfig.ordPk = paymentPk;
|
|
84
|
+
|
|
85
|
+
const result = await sendOrdinals(sendOrdinalsConfig);
|
|
86
|
+
const changeResult = result as ChangeResult;
|
|
87
|
+
|
|
88
|
+
// 7. Broadcast the transaction
|
|
89
|
+
await changeResult.tx.broadcast();
|
|
90
|
+
|
|
91
|
+
// 8. Refresh the wallet's UTXOs after spending
|
|
92
|
+
try {
|
|
93
|
+
await wallet.refreshUtxos();
|
|
94
|
+
} catch (refreshError) {
|
|
95
|
+
console.warn("Failed to refresh UTXOs after transaction:", refreshError);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 9. Return transaction details
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: JSON.stringify({
|
|
104
|
+
txid: changeResult.tx.id("hex"),
|
|
105
|
+
spentOutpoints: changeResult.spentOutpoints,
|
|
106
|
+
payChange: changeResult.payChange,
|
|
107
|
+
inscriptionOutpoint: args.inscriptionOutpoint,
|
|
108
|
+
destinationAddress: args.destinationAddress,
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
} catch (err: unknown) {
|
|
114
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
115
|
+
return { content: [{ type: "text", text: msg }], isError: true };
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { P2PKH } from "@bsv/sdk";
|
|
2
2
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
+
import { toSatoshi } from "satoshi-token";
|
|
4
5
|
import type { z } from "zod";
|
|
5
6
|
import { sendToAddressArgsSchema } from "./schemas";
|
|
6
7
|
import type { Wallet } from "./wallet";
|
|
@@ -56,17 +57,20 @@ export function registerSendToAddressTool(server: McpServer, wallet: Wallet) {
|
|
|
56
57
|
description = "Send to address",
|
|
57
58
|
} = args;
|
|
58
59
|
|
|
59
|
-
// Convert
|
|
60
|
-
let satoshis
|
|
60
|
+
// Convert to satoshis
|
|
61
|
+
let satoshis: number;
|
|
61
62
|
if (currency === "USD") {
|
|
62
63
|
// Get current BSV price
|
|
63
64
|
const bsvPriceUsd = await getBsvPrice();
|
|
64
65
|
|
|
65
|
-
// Convert USD to BSV
|
|
66
|
-
|
|
66
|
+
// Convert USD to BSV
|
|
67
|
+
const bsvAmount = amount / bsvPriceUsd;
|
|
68
|
+
|
|
69
|
+
// Convert BSV to satoshis using the library
|
|
70
|
+
satoshis = toSatoshi(bsvAmount);
|
|
67
71
|
} else {
|
|
68
|
-
// Convert BSV to satoshis
|
|
69
|
-
satoshis =
|
|
72
|
+
// Convert BSV to satoshis using the library
|
|
73
|
+
satoshis = toSatoshi(amount);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// Create P2PKH script from address
|
package/tools/wallet/tools.ts
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
ToolCallback,
|
|
4
|
-
} from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
3
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
6
4
|
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
7
5
|
import type { z } from "zod";
|
|
8
|
-
import { convertData } from "../utils/conversion";
|
|
9
|
-
import { registerGetAddressTool } from "./getAddress";
|
|
10
|
-
import { registerPurchaseListingTool } from "./purchaseListing";
|
|
11
|
-
import {
|
|
12
|
-
createSignatureArgsSchema,
|
|
13
|
-
type emptyArgsSchema,
|
|
14
|
-
getPublicKeyArgsSchema,
|
|
15
|
-
verifySignatureArgsSchema,
|
|
16
|
-
walletDecryptArgsSchema,
|
|
17
|
-
walletEncryptArgsSchema,
|
|
18
|
-
} from "./schemas";
|
|
19
6
|
import type {
|
|
20
7
|
abortActionArgsSchema,
|
|
21
8
|
acquireCertificateArgsSchema,
|
|
22
9
|
createHmacArgsSchema,
|
|
23
10
|
discoverByAttributesArgsSchema,
|
|
24
11
|
discoverByIdentityKeyArgsSchema,
|
|
25
|
-
getAddressArgsSchema,
|
|
26
12
|
getHeaderArgsSchema,
|
|
27
13
|
internalizeActionArgsSchema,
|
|
28
14
|
listActionsArgsSchema,
|
|
29
15
|
listCertificatesArgsSchema,
|
|
30
16
|
listOutputsArgsSchema,
|
|
31
17
|
proveCertificateArgsSchema,
|
|
32
|
-
purchaseListingArgsSchema,
|
|
33
18
|
relinquishCertificateArgsSchema,
|
|
34
19
|
relinquishOutputArgsSchema,
|
|
35
20
|
revealCounterpartyKeyLinkageArgsSchema,
|
|
36
21
|
revealSpecificKeyLinkageArgsSchema,
|
|
37
|
-
sendToAddressArgsSchema,
|
|
38
22
|
verifyHmacArgsSchema,
|
|
39
23
|
} from "./schemas";
|
|
40
|
-
import { registerSendToAddressTool } from "./sendToAddress";
|
|
41
24
|
import type { Wallet } from "./wallet";
|
|
42
25
|
|
|
26
|
+
import {
|
|
27
|
+
createSignatureArgsSchema,
|
|
28
|
+
type emptyArgsSchema,
|
|
29
|
+
type getAddressArgsSchema,
|
|
30
|
+
getPublicKeyArgsSchema,
|
|
31
|
+
type purchaseListingArgsSchema,
|
|
32
|
+
type sendToAddressArgsSchema,
|
|
33
|
+
verifySignatureArgsSchema,
|
|
34
|
+
walletDecryptArgsSchema,
|
|
35
|
+
walletEncryptArgsSchema,
|
|
36
|
+
} from "./schemas";
|
|
37
|
+
|
|
38
|
+
import { registerCreateOrdinalsTool } from "./createOrdinals";
|
|
39
|
+
import type { createOrdinalsArgsSchema } from "./createOrdinals";
|
|
40
|
+
import { registerGetAddressTool } from "./getAddress";
|
|
41
|
+
import { registerPurchaseListingTool } from "./purchaseListing";
|
|
42
|
+
import { registerSendToAddressTool } from "./sendToAddress";
|
|
43
|
+
import { registerSendOrdinalsTool } from "./sendOrdinals";
|
|
44
|
+
import type { sendOrdinalsArgsSchema } from "./sendOrdinals";
|
|
45
|
+
|
|
43
46
|
// Define mapping from tool names to argument schemas
|
|
44
47
|
type ToolArgSchemas = {
|
|
45
48
|
wallet_getPublicKey: typeof getPublicKeyArgsSchema;
|
|
@@ -70,6 +73,8 @@ type ToolArgSchemas = {
|
|
|
70
73
|
wallet_getAddress: typeof getAddressArgsSchema;
|
|
71
74
|
wallet_sendToAddress: typeof sendToAddressArgsSchema;
|
|
72
75
|
wallet_purchaseListing: typeof purchaseListingArgsSchema;
|
|
76
|
+
wallet_createOrdinals: typeof createOrdinalsArgsSchema;
|
|
77
|
+
wallet_sendOrdinals: typeof sendOrdinalsArgsSchema;
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
// Define a type for the handler function with proper argument types
|
|
@@ -202,5 +207,11 @@ export function registerWalletTools(
|
|
|
202
207
|
},
|
|
203
208
|
);
|
|
204
209
|
|
|
210
|
+
// Register ordinals extension tools
|
|
211
|
+
// Register the wallet_createOrdinals tool
|
|
212
|
+
registerCreateOrdinalsTool(server, wallet);
|
|
213
|
+
// Register the wallet_sendOrdinals tool
|
|
214
|
+
registerSendOrdinalsTool(server, wallet);
|
|
215
|
+
|
|
205
216
|
return handlers;
|
|
206
217
|
}
|
package/tools/wallet/wallet.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
PrivateKey,
|
|
11
11
|
ProtoWallet,
|
|
12
12
|
Transaction,
|
|
13
|
-
Utils,
|
|
14
13
|
} from "@bsv/sdk";
|
|
15
14
|
import type {
|
|
16
15
|
AbortActionArgs,
|
|
@@ -19,10 +18,6 @@ import type {
|
|
|
19
18
|
AuthenticatedResult,
|
|
20
19
|
CreateActionArgs,
|
|
21
20
|
CreateActionResult,
|
|
22
|
-
CreateHmacArgs,
|
|
23
|
-
CreateHmacResult,
|
|
24
|
-
CreateSignatureArgs,
|
|
25
|
-
CreateSignatureResult,
|
|
26
21
|
DiscoverByAttributesArgs,
|
|
27
22
|
DiscoverByIdentityKeyArgs,
|
|
28
23
|
DiscoverCertificatesResult,
|
|
@@ -53,15 +48,7 @@ import type {
|
|
|
53
48
|
RevealSpecificKeyLinkageResult,
|
|
54
49
|
SignActionArgs,
|
|
55
50
|
SignActionResult,
|
|
56
|
-
VerifyHmacArgs,
|
|
57
|
-
VerifyHmacResult,
|
|
58
|
-
VerifySignatureArgs,
|
|
59
|
-
VerifySignatureResult,
|
|
60
51
|
WalletCertificate,
|
|
61
|
-
WalletDecryptArgs,
|
|
62
|
-
WalletDecryptResult,
|
|
63
|
-
WalletEncryptArgs,
|
|
64
|
-
WalletEncryptResult,
|
|
65
52
|
WalletInterface,
|
|
66
53
|
} from "@bsv/sdk";
|
|
67
54
|
import {
|
|
@@ -152,28 +139,29 @@ export class Wallet extends ProtoWallet implements WalletInterface {
|
|
|
152
139
|
): Promise<RevealSpecificKeyLinkageResult> {
|
|
153
140
|
return Promise.reject(new Error("Not implemented"));
|
|
154
141
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
142
|
+
// Implemented by ProtoWallet
|
|
143
|
+
// async encrypt(args: WalletEncryptArgs): Promise<WalletEncryptResult> {
|
|
144
|
+
// return this.encrypt(args);
|
|
145
|
+
// }
|
|
146
|
+
// async decrypt(args: WalletDecryptArgs): Promise<WalletDecryptResult> {
|
|
147
|
+
// return this.decrypt(args);
|
|
148
|
+
// }
|
|
149
|
+
// async createHmac(args: CreateHmacArgs): Promise<CreateHmacResult> {
|
|
150
|
+
// return this.createHmac(args);
|
|
151
|
+
// }
|
|
152
|
+
// async verifyHmac(args: VerifyHmacArgs): Promise<VerifyHmacResult> {
|
|
153
|
+
// return this.verifyHmac(args);
|
|
154
|
+
// }
|
|
155
|
+
// async createSignature(
|
|
156
|
+
// args: CreateSignatureArgs,
|
|
157
|
+
// ): Promise<CreateSignatureResult> {
|
|
158
|
+
// return Promise.reject(new Error("Not implemented"));
|
|
159
|
+
// }
|
|
160
|
+
// async verifySignature(
|
|
161
|
+
// args: VerifySignatureArgs,
|
|
162
|
+
// ): Promise<VerifySignatureResult> {
|
|
163
|
+
// return Promise.reject(new Error("Not implemented"));
|
|
164
|
+
// }
|
|
177
165
|
async createAction(args: CreateActionArgs): Promise<CreateActionResult> {
|
|
178
166
|
console.log("createAction called with", args);
|
|
179
167
|
|