bsv-mcp 0.0.24 → 0.0.25

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/index.ts CHANGED
@@ -7,46 +7,52 @@ import { registerResources } from "./resources/resources";
7
7
  import { registerAllTools } from "./tools";
8
8
  import { registerWalletTools } from "./tools/wallet/tools";
9
9
  import { Wallet } from "./tools/wallet/wallet";
10
+ import { registerMneeTools } from "./tools/mnee";
10
11
 
11
12
  /**
12
- * Validate the private key from environment variables
13
- * Exits the process with an error message if validation fails
13
+ * Try to initialize the private key from environment variables
14
+ * Returns the private key if valid, or undefined if not present or invalid
14
15
  */
15
- function validatePrivateKey(): PrivateKey {
16
+ function initializePrivateKey(): PrivateKey | undefined {
16
17
  const privateKeyWif = process.env.PRIVATE_KEY_WIF;
17
18
 
18
19
  // Check if private key is set
19
20
  if (!privateKeyWif) {
20
- console.error(
21
- "\x1b[31mError: PRIVATE_KEY_WIF environment variable is not set\x1b[0m",
21
+ console.warn(
22
+ "\x1b[33mWarning: PRIVATE_KEY_WIF environment variable is not set\x1b[0m",
22
23
  );
23
- console.error(
24
- "Please set this variable with a valid Bitcoin SV private key in WIF format",
24
+ console.warn(
25
+ "The server will run, but wallet operations requiring a private key will return errors.",
25
26
  );
26
- console.error(
27
+ console.warn(
28
+ "Set this variable with a valid Bitcoin SV private key in WIF format to enable all features:",
29
+ );
30
+ console.warn(
27
31
  "Example: PRIVATE_KEY_WIF=your_private_key_wif bun run index.ts",
28
32
  );
29
- process.exit(1);
33
+ return undefined;
30
34
  }
31
35
 
32
36
  // Validate the private key format
33
37
  try {
34
38
  return PrivateKey.fromWif(privateKeyWif);
35
39
  } catch (error) {
36
- console.error("\x1b[31mError: Invalid private key format\x1b[0m");
37
- console.error(
38
- "The PRIVATE_KEY_WIF provided is not a valid Bitcoin SV private key in WIF format",
40
+ console.warn("\x1b[33mWarning: Invalid private key format\x1b[0m");
41
+ console.warn(
42
+ "The PRIVATE_KEY_WIF provided is not a valid Bitcoin SV private key in WIF format.",
43
+ );
44
+ console.warn(
45
+ "The server will run, but wallet operations requiring a private key will return errors.",
39
46
  );
40
- console.error("Please check your key and try again");
41
- process.exit(1);
47
+ return undefined;
42
48
  }
43
49
  }
44
50
 
45
- // Validate private key early before starting the server
46
- const privKey = validatePrivateKey();
51
+ // Try to initialize private key but don't stop the server if missing or invalid
52
+ const privKey = initializePrivateKey();
47
53
 
48
54
  const server = new McpServer(
49
- { name: "Bitcoin SV", version: "0.0.24" },
55
+ { name: "Bitcoin SV", version: "0.0.25" },
50
56
  // {
51
57
  // // Advertise only what you actually implement
52
58
  // capabilities: {
@@ -65,11 +71,16 @@ const server = new McpServer(
65
71
  // },
66
72
  );
67
73
 
68
- // Initialize wallet with the validated private key
69
- const wallet = new Wallet(privKey);
70
-
71
- // Register wallet tools separately (needs wallet instance)
72
- registerWalletTools(server, wallet);
74
+ // Initialize wallet with the validated private key only if available
75
+ let wallet: Wallet | null = null;
76
+ if (privKey) {
77
+ // Register MNEE tools
78
+ registerMneeTools(server);
79
+ // Initialize wallet with the private key
80
+ wallet = new Wallet(privKey);
81
+ // Register wallet tools
82
+ registerWalletTools(server, wallet);
83
+ }
73
84
 
74
85
  // Register all other tools (BSV, Ordinals, Utils, etc.)
75
86
  registerAllTools(server);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bsv-mcp",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.24",
5
+ "version": "0.0.25",
6
6
  "license": "MIT",
7
7
  "author": "satchmo",
8
8
  "description": "A collection of Bitcoin SV (BSV) tools for the Model Context Protocol (MCP) framework",
package/tools/index.ts CHANGED
@@ -2,7 +2,6 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { registerA2aCallTool } from "./a2b/call";
3
3
  import { registerA2bDiscoverTool } from "./a2b/discover";
4
4
  import { registerBsvTools } from "./bsv";
5
- import { registerMneeTools } from "./mnee";
6
5
  import { registerOrdinalsTools } from "./ordinals";
7
6
  import { registerUtilsTools } from "./utils";
8
7
 
@@ -26,8 +25,6 @@ export function registerAllTools(server: McpServer): void {
26
25
  // Register agent-to-agent call tool
27
26
  // registerA2aCallTool(server);
28
27
 
29
- // Register MNEE tools
30
- registerMneeTools(server);
31
28
 
32
29
  // Add more tool categories as needed
33
30
  }
@@ -61,7 +61,19 @@ export function registerSendMneeTool(server: McpServer, mnee: Mnee): void {
61
61
  // Get WIF from environment
62
62
  const wif = process.env.PRIVATE_KEY_WIF;
63
63
  if (!wif) {
64
- throw new Error("PRIVATE_KEY_WIF environment variable is not set");
64
+ return {
65
+ content: [
66
+ {
67
+ type: "text",
68
+ text: JSON.stringify({
69
+ success: false,
70
+ error: "No private key available",
71
+ message: "Please set PRIVATE_KEY_WIF environment variable with a valid Bitcoin SV private key in WIF format.",
72
+ }, null, 2),
73
+ },
74
+ ],
75
+ isError: true,
76
+ };
65
77
  }
66
78
 
67
79
  const result: TransferResponse = await mnee.transfer(
@@ -21,7 +21,22 @@ export function registerGetAddressTool(server: McpServer): void {
21
21
  async () => {
22
22
  try {
23
23
  const wif = process.env.PRIVATE_KEY_WIF;
24
- if (!wif) throw new Error("PRIVATE_KEY_WIF env var not set");
24
+ if (!wif) {
25
+ return {
26
+ content: [
27
+ {
28
+ type: "text",
29
+ text: JSON.stringify({
30
+ error: "No private key available",
31
+ message: "Please set PRIVATE_KEY_WIF environment variable with a valid Bitcoin SV private key in WIF format.",
32
+ status: "error"
33
+ }),
34
+ },
35
+ ],
36
+ isError: true,
37
+ };
38
+ }
39
+
25
40
  const privKey = PrivateKey.fromWif(wif);
26
41
  const address = privKey.toAddress();
27
42
  return {
@@ -35,7 +50,14 @@ export function registerGetAddressTool(server: McpServer): void {
35
50
  } catch (err: unknown) {
36
51
  const msg = err instanceof Error ? err.message : String(err);
37
52
  return {
38
- content: [{ type: "text", text: msg }],
53
+ content: [{
54
+ type: "text",
55
+ text: JSON.stringify({
56
+ error: "Invalid private key",
57
+ message: msg,
58
+ status: "error"
59
+ })
60
+ }],
39
61
  isError: true,
40
62
  };
41
63
  }