@mcp-dockmaster/mcp-cryptowallet-evm 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-dockmaster/mcp-cryptowallet-evm",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "MCP server for EVM crypto wallet operations using ethers.js v5",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "build": "tsc",
12
12
  "start": "node build/index.js",
13
- "test": "jest",
13
+ "test": "node --test ./tests/**/*.test.ts",
14
14
  "lint": "eslint src/**/*.ts"
15
15
  },
16
16
  "repository": {
@@ -0,0 +1,53 @@
1
+ # Required Methods for EVM Crypto Wallet MCP Server
2
+
3
+ Based on the ethers.js v5 documentation and the example MCP servers, the following methods should be implemented for our crypto wallet MCP server:
4
+
5
+ ## Wallet Creation and Management
6
+ - `wallet_create_random` - Create a new wallet with a random private key
7
+ - `wallet_from_private_key` - Create a wallet from a private key
8
+ - `wallet_from_mnemonic` - Create a wallet from a mnemonic phrase
9
+ - `wallet_from_encrypted_json` - Create a wallet by decrypting an encrypted JSON wallet
10
+ - `wallet_encrypt` - Encrypt a wallet with a password
11
+
12
+ ## Wallet Properties
13
+ - `wallet_get_address` - Get the wallet address
14
+ - `wallet_get_public_key` - Get the wallet public key
15
+ - `wallet_get_private_key` - Get the wallet private key (with appropriate security warnings)
16
+ - `wallet_get_mnemonic` - Get the wallet mnemonic phrase (if available)
17
+
18
+ ## Blockchain Methods
19
+ - `wallet_get_balance` - Get the balance of the wallet
20
+ - `wallet_get_chain_id` - Get the chain ID the wallet is connected to
21
+ - `wallet_get_gas_price` - Get the current gas price
22
+ - `wallet_get_transaction_count` - Get the number of transactions sent from this account (nonce)
23
+ - `wallet_call` - Call a contract method without sending a transaction
24
+
25
+ ## Transaction Methods
26
+ - `wallet_send_transaction` - Send a transaction
27
+ - `wallet_sign_transaction` - Sign a transaction without sending it
28
+ - `wallet_populate_transaction` - Populate a transaction with missing fields
29
+
30
+ ## Signing Methods
31
+ - `wallet_sign_message` - Sign a message
32
+ - `wallet_sign_typed_data` - Sign typed data (EIP-712)
33
+ - `wallet_verify_message` - Verify a signed message
34
+ - `wallet_verify_typed_data` - Verify signed typed data
35
+
36
+ ## Provider Methods
37
+ - `provider_get_block` - Get a block by number or hash
38
+ - `provider_get_transaction` - Get a transaction by hash
39
+ - `provider_get_transaction_receipt` - Get a transaction receipt
40
+ - `provider_get_code` - Get the code at an address
41
+ - `provider_get_storage_at` - Get the storage at a position for an address
42
+ - `provider_estimate_gas` - Estimate the gas required for a transaction
43
+ - `provider_get_logs` - Get logs that match a filter
44
+ - `provider_get_ens_resolver` - Get the ENS resolver for a name
45
+ - `provider_lookup_address` - Lookup the ENS name for an address
46
+ - `provider_resolve_name` - Resolve an ENS name to an address
47
+
48
+ ## Network Methods
49
+ - `network_get_network` - Get the current network information
50
+ - `network_get_block_number` - Get the current block number
51
+ - `network_get_fee_data` - Get the current fee data (base fee, max priority fee, etc.)
52
+
53
+ These methods cover the core functionality needed for a comprehensive EVM crypto wallet implementation using ethers.js v5.
@@ -12,12 +12,11 @@ try {
12
12
  }
13
13
 
14
14
  /**
15
- * Creates a success response with the given result
16
- * @param result The result to include in the response
15
+ * Creates a success response with the given message
17
16
  * @param message Optional message to include in the response
18
- * @returns A ToolResultSchema with the result and message
17
+ * @returns A ToolResultSchema with the message
19
18
  */
20
- export const createSuccessResponse = <T>(result: T, message?: string): ToolResultSchema<T> => {
19
+ export const createSuccessResponse = (message?: string): ToolResultSchema => {
21
20
  return {
22
21
  content: [
23
22
  {
@@ -26,7 +25,6 @@ export const createSuccessResponse = <T>(result: T, message?: string): ToolResul
26
25
  }
27
26
  ],
28
27
  isError: false,
29
- toolResult: result
30
28
  };
31
29
  };
32
30
 
@@ -35,7 +33,7 @@ export const createSuccessResponse = <T>(result: T, message?: string): ToolResul
35
33
  * @param message The error message
36
34
  * @returns A ToolResultSchema with the error message
37
35
  */
38
- export const createErrorResponse = (message: string): ToolResultSchema<any> => {
36
+ export const createErrorResponse = (message: string): ToolResultSchema => {
39
37
  return {
40
38
  content: [
41
39
  {
@@ -43,8 +41,7 @@ export const createErrorResponse = (message: string): ToolResultSchema<any> => {
43
41
  text: message
44
42
  }
45
43
  ],
46
- isError: true,
47
- toolResult: { error: message }
44
+ isError: true
48
45
  };
49
46
  };
50
47
 
@@ -6,10 +6,10 @@ import { generateMnemonic, } from '@scure/bip39';
6
6
 
7
7
  // Provider handlers
8
8
 
9
- export const setProviderHandler = async (input: any): Promise<ToolResultSchema<any>> => {
9
+ export const setProviderHandler = async (input: any): Promise<ToolResultSchema> => {
10
10
  try {
11
11
  setProvider(input.providerURL);
12
- return createSuccessResponse({}, `Provider set successfully:
12
+ return createSuccessResponse(`Provider set successfully:
13
13
  Provider URL: ${input.providerURL}
14
14
  `);
15
15
  } catch (error) {
@@ -19,7 +19,7 @@ export const setProviderHandler = async (input: any): Promise<ToolResultSchema<a
19
19
 
20
20
 
21
21
  // Wallet Creation and Management
22
- export const createWalletHandler = async (input: any): Promise<ToolResultSchema<any>> => {
22
+ export const createWalletHandler = async (input: any): Promise<ToolResultSchema> => {
23
23
  try {
24
24
  const options: any = {};
25
25
 
@@ -46,7 +46,7 @@ export const createWalletHandler = async (input: any): Promise<ToolResultSchema<
46
46
  result.encryptedWallet = encryptedWallet;
47
47
  }
48
48
 
49
- return createSuccessResponse(result, `Wallet created successfully:
49
+ return createSuccessResponse(`Wallet created successfully:
50
50
  Address: ${wallet.address}
51
51
  Private Key: ${wallet.privateKey}
52
52
  Public Key: ${wallet.publicKey}
@@ -58,7 +58,7 @@ export const createWalletHandler = async (input: any): Promise<ToolResultSchema<
58
58
  }
59
59
  };
60
60
 
61
- export const fromPrivateKeyHandler = async (input: fromPrivateKeyHandlerInput): Promise<ToolResultSchema<any>> => {
61
+ export const fromPrivateKeyHandler = async (input: fromPrivateKeyHandlerInput): Promise<ToolResultSchema> => {
62
62
  try {
63
63
  if (!input.privateKey) {
64
64
  return createErrorResponse("Private key is required");
@@ -67,11 +67,8 @@ export const fromPrivateKeyHandler = async (input: fromPrivateKeyHandlerInput):
67
67
  const provider = getProvider()
68
68
  const wallet = new ethers.Wallet(input.privateKey, provider);
69
69
 
70
- return createSuccessResponse({
71
- address: wallet.address,
72
- privateKey: wallet.privateKey,
73
- publicKey: wallet.publicKey
74
- }, `Wallet created from private key successfully:
70
+ return createSuccessResponse(
71
+ `Wallet created from private key successfully:
75
72
  Address: ${wallet.address}
76
73
  Private Key: ${wallet.privateKey}
77
74
  Public Key: ${wallet.publicKey}
@@ -81,7 +78,7 @@ export const fromPrivateKeyHandler = async (input: fromPrivateKeyHandlerInput):
81
78
  }
82
79
  };
83
80
 
84
- export const createMnemonicPhraseHandler = async (input: createMnemonicPhraseHandlerInput): Promise<ToolResultSchema<any>> => {
81
+ export const createMnemonicPhraseHandler = async (input: createMnemonicPhraseHandlerInput): Promise<ToolResultSchema> => {
85
82
  try {
86
83
  const { wordlist } = await import(`@scure/bip39/wordlists/${input.locale || 'english'}`);
87
84
  if (!wordlist) {
@@ -91,9 +88,8 @@ export const createMnemonicPhraseHandler = async (input: createMnemonicPhraseHan
91
88
  const entropyBits = ((input.length ?? 12) / 3) * 32;
92
89
  const mnemonic = generateMnemonic(wordlist, entropyBits);
93
90
 
94
- return createSuccessResponse({
95
- mnemonic: mnemonic
96
- }, `Mnemonic phrase created successfully:
91
+ return createSuccessResponse(
92
+ `Mnemonic phrase created successfully:
97
93
  Mnemonic: "${mnemonic}"
98
94
  `);
99
95
  } catch (error) {
@@ -101,7 +97,7 @@ export const createMnemonicPhraseHandler = async (input: createMnemonicPhraseHan
101
97
  }
102
98
  };
103
99
 
104
- export const fromMnemonicHandler = async (input: any): Promise<ToolResultSchema<any>> => {
100
+ export const fromMnemonicHandler = async (input: any): Promise<ToolResultSchema> => {
105
101
  try {
106
102
  if (!input.mnemonic) {
107
103
  return createErrorResponse("Mnemonic is required");
@@ -117,13 +113,10 @@ export const fromMnemonicHandler = async (input: any): Promise<ToolResultSchema<
117
113
 
118
114
  if (provider) wallet.connect(provider);
119
115
 
120
- return createSuccessResponse({
121
- address: wallet.address,
122
- mnemonic: wallet.mnemonic?.phrase,
123
- privateKey: wallet.privateKey,
124
- publicKey: wallet.publicKey
125
- }, `Wallet created from mnemonic successfully:
116
+ return createSuccessResponse(
117
+ `Wallet created from mnemonic successfully:
126
118
  Address: ${wallet.address}
119
+ Mnemonic: ${input.mnemonic}
127
120
  Private Key: ${wallet.privateKey}
128
121
  Public Key: ${wallet.publicKey}
129
122
  `);
@@ -132,7 +125,7 @@ export const fromMnemonicHandler = async (input: any): Promise<ToolResultSchema<
132
125
  }
133
126
  };
134
127
 
135
- export const fromEncryptedJsonHandler = async (input: any): Promise<ToolResultSchema<any>> => {
128
+ export const fromEncryptedJsonHandler = async (input: any): Promise<ToolResultSchema> => {
136
129
  try {
137
130
  if (!input.json) {
138
131
  return createErrorResponse("Encrypted JSON is required");
@@ -149,17 +142,18 @@ export const fromEncryptedJsonHandler = async (input: any): Promise<ToolResultSc
149
142
  wallet.connect(provider);
150
143
  }
151
144
 
152
- return createSuccessResponse({
153
- address: wallet.address,
154
- privateKey: wallet.privateKey,
155
- publicKey: wallet.publicKey
156
- }, "Wallet created from encrypted JSON successfully");
145
+ return createSuccessResponse(
146
+ `Wallet created from encrypted JSON successfully
147
+ Address: ${wallet.address}
148
+ Private Key: ${wallet.privateKey}
149
+ Public Key: ${wallet.publicKey}
150
+ `);
157
151
  } catch (error) {
158
152
  return createErrorResponse(`Failed to create wallet from encrypted JSON: ${(error as Error).message}`);
159
153
  }
160
154
  };
161
155
 
162
- export const encryptWalletHandler = async (input: any): Promise<ToolResultSchema<any>> => {
156
+ export const encryptWalletHandler = async (input: any): Promise<ToolResultSchema> => {
163
157
  try {
164
158
  if (!input.wallet) {
165
159
  return createErrorResponse("Wallet is required");
@@ -172,9 +166,10 @@ export const encryptWalletHandler = async (input: any): Promise<ToolResultSchema
172
166
  const wallet = await getWallet(input.wallet);
173
167
  const encryptedWallet = await wallet.encrypt(input.password, input.options);
174
168
 
175
- return createSuccessResponse({
176
- encryptedWallet
177
- }, "Wallet encrypted successfully");
169
+ return createSuccessResponse(
170
+ `Wallet encrypted successfully
171
+ Encrypted Wallet: ${encryptedWallet}
172
+ `);
178
173
  } catch (error) {
179
174
  return createErrorResponse(`Failed to encrypt wallet: ${(error as Error).message}`);
180
175
  }
@@ -182,13 +177,12 @@ export const encryptWalletHandler = async (input: any): Promise<ToolResultSchema
182
177
 
183
178
  // Wallet Properties
184
179
 
185
- export const getAddressHandler = async (input: any): Promise<ToolResultSchema<any>> => {
180
+ export const getAddressHandler = async (input: any): Promise<ToolResultSchema> => {
186
181
  try {
187
182
  const wallet = await getWallet(input.wallet);
188
183
 
189
- return createSuccessResponse({
190
- address: wallet.address
191
- }, `Wallet address retrieved successfully:
184
+ return createSuccessResponse(
185
+ `Wallet address retrieved successfully:
192
186
  Address: ${wallet.address}
193
187
  `);
194
188
  } catch (error) {
@@ -196,13 +190,12 @@ export const getAddressHandler = async (input: any): Promise<ToolResultSchema<an
196
190
  }
197
191
  };
198
192
 
199
- export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema<any>> => {
193
+ export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema> => {
200
194
  try {
201
195
  const wallet = await getWallet(input.wallet);
202
196
 
203
- return createSuccessResponse({
204
- publicKey: wallet.publicKey
205
- }, `Wallet public key retrieved successfully:
197
+ return createSuccessResponse(
198
+ `Wallet public key retrieved successfully:
206
199
  Public Key: ${wallet.publicKey}
207
200
  `);
208
201
  } catch (error) {
@@ -210,13 +203,12 @@ export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema<
210
203
  }
211
204
  };
212
205
 
213
- export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema<any>> => {
206
+ export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema> => {
214
207
  try {
215
208
  const wallet = await getWallet(input.wallet, input.password);
216
209
 
217
- return createSuccessResponse({
218
- privateKey: wallet.privateKey
219
- }, `Wallet private key retrieved successfully:
210
+ return createSuccessResponse(
211
+ `Wallet private key retrieved successfully:
220
212
  Private Key: ${wallet.privateKey}
221
213
  `);
222
214
  } catch (error) {
@@ -225,16 +217,14 @@ export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema
225
217
  };
226
218
  // Blockchain Methods
227
219
 
228
- export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
220
+ export const getBalanceHandler = async (input: any): Promise<ToolResultSchema> => {
229
221
  try {
230
222
  const wallet = await getWallet(input.wallet, input.password);
231
223
 
232
224
  const balance = await wallet.getBalance(input.blockTag ?? "latest");
233
225
 
234
- return createSuccessResponse({
235
- balance: balance.toString(),
236
- balanceInEth: ethers.utils.formatEther(balance)
237
- }, `Wallet balance retrieved successfully
226
+ return createSuccessResponse(
227
+ `Wallet balance retrieved successfully
238
228
  Balance: ${balance.toString()}
239
229
  Balance in ETH: ${ethers.utils.formatEther(balance)}
240
230
  `);
@@ -243,7 +233,7 @@ export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<an
243
233
  }
244
234
  };
245
235
 
246
- export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<any>> => {
236
+ export const getChainIdHandler = async (input: any): Promise<ToolResultSchema> => {
247
237
  try {
248
238
  const wallet = await getWallet(input.wallet, input.password);
249
239
 
@@ -253,9 +243,8 @@ export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<an
253
243
 
254
244
  const chainId = await wallet.getChainId();
255
245
 
256
- return createSuccessResponse({
257
- chainId
258
- }, `Chain ID retrieved successfully
246
+ return createSuccessResponse(
247
+ `Chain ID retrieved successfully
259
248
  Chain ID: ${chainId.toString()}
260
249
  `);
261
250
  } catch (error) {
@@ -263,7 +252,7 @@ export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<an
263
252
  }
264
253
  };
265
254
 
266
- export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
255
+ export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema> => {
267
256
  try {
268
257
  const wallet = await getWallet(input.wallet, input.password);
269
258
 
@@ -273,10 +262,8 @@ export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<a
273
262
 
274
263
  const gasPrice = await wallet.getGasPrice();
275
264
 
276
- return createSuccessResponse({
277
- gasPrice: gasPrice.toString(),
278
- gasPriceInGwei: ethers.utils.formatUnits(gasPrice, "gwei")
279
- }, `Gas price retrieved successfully
265
+ return createSuccessResponse(
266
+ `Gas price retrieved successfully
280
267
  Gas price: ${gasPrice.toString()}
281
268
  Gas price in Gwei: ${ethers.utils.formatUnits(gasPrice, "gwei")}
282
269
  `);
@@ -285,7 +272,7 @@ export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<a
285
272
  }
286
273
  };
287
274
 
288
- export const getTransactionCountHandler = async (input: any): Promise<ToolResultSchema<any>> => {
275
+ export const getTransactionCountHandler = async (input: any): Promise<ToolResultSchema> => {
289
276
  try {
290
277
  const wallet = await getWallet(input.wallet, input.password);
291
278
 
@@ -295,9 +282,8 @@ export const getTransactionCountHandler = async (input: any): Promise<ToolResult
295
282
 
296
283
  const transactionCount = await wallet.getTransactionCount(input.blockTag);
297
284
 
298
- return createSuccessResponse({
299
- transactionCount
300
- }, `Transaction count retrieved successfully
285
+ return createSuccessResponse(
286
+ `Transaction count retrieved successfully
301
287
  Transaction count: ${transactionCount.toString()}
302
288
  `);
303
289
  } catch (error) {
@@ -305,7 +291,7 @@ export const getTransactionCountHandler = async (input: any): Promise<ToolResult
305
291
  }
306
292
  };
307
293
 
308
- export const callHandler = async (input: any): Promise<ToolResultSchema<any>> => {
294
+ export const callHandler = async (input: any): Promise<ToolResultSchema> => {
309
295
  try {
310
296
  if (!input.transaction) {
311
297
  return createErrorResponse("Transaction is required");
@@ -319,9 +305,8 @@ export const callHandler = async (input: any): Promise<ToolResultSchema<any>> =>
319
305
 
320
306
  const result = await wallet.call(input.transaction, input.blockTag);
321
307
 
322
- return createSuccessResponse({
323
- result
324
- }, `Contract call executed successfully
308
+ return createSuccessResponse(
309
+ `Contract call executed successfully
325
310
  Result: ${result}
326
311
  `);
327
312
  } catch (error) {
@@ -331,7 +316,7 @@ export const callHandler = async (input: any): Promise<ToolResultSchema<any>> =>
331
316
 
332
317
  // Transaction Methods
333
318
 
334
- export const sendTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
319
+ export const sendTransactionHandler = async (input: any): Promise<ToolResultSchema> => {
335
320
  try {
336
321
  if (!input.transaction) {
337
322
  return createErrorResponse("Transaction is required");
@@ -344,18 +329,8 @@ export const sendTransactionHandler = async (input: any): Promise<ToolResultSche
344
329
 
345
330
  const tx = await wallet.sendTransaction(input.transaction);
346
331
 
347
- return createSuccessResponse({
348
- hash: tx.hash,
349
- nonce: tx.nonce,
350
- gasLimit: tx.gasLimit.toString(),
351
- gasPrice: tx.gasPrice?.toString(),
352
- data: tx.data,
353
- value: tx.value.toString(),
354
- chainId: tx.chainId,
355
- from: tx.from,
356
- to: tx.to,
357
- type: tx.type
358
- }, `Transaction sent successfully
332
+ return createSuccessResponse(
333
+ `Transaction sent successfully
359
334
  Hash: ${tx.hash}
360
335
  Nonce: ${tx.nonce.toString()}
361
336
  Gas limit: ${tx.gasLimit.toString()}
@@ -367,7 +342,7 @@ export const sendTransactionHandler = async (input: any): Promise<ToolResultSche
367
342
  }
368
343
  };
369
344
 
370
- export const signTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
345
+ export const signTransactionHandler = async (input: any): Promise<ToolResultSchema> => {
371
346
  try {
372
347
  if (!input.transaction) {
373
348
  return createErrorResponse("Transaction is required");
@@ -379,9 +354,8 @@ export const signTransactionHandler = async (input: any): Promise<ToolResultSche
379
354
  const populatedTx = await wallet.populateTransaction(input.transaction);
380
355
  const signedTx = await wallet.signTransaction(populatedTx);
381
356
 
382
- return createSuccessResponse({
383
- signedTransaction: signedTx
384
- }, `Transaction signed successfully
357
+ return createSuccessResponse(
358
+ `Transaction signed successfully
385
359
  Signed transaction: ${signedTx}
386
360
  `);
387
361
  } catch (error) {
@@ -389,7 +363,7 @@ export const signTransactionHandler = async (input: any): Promise<ToolResultSche
389
363
  }
390
364
  };
391
365
 
392
- export const populateTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
366
+ export const populateTransactionHandler = async (input: any): Promise<ToolResultSchema> => {
393
367
  try {
394
368
  if (!input.transaction) {
395
369
  return createErrorResponse("Transaction is required");
@@ -403,21 +377,8 @@ export const populateTransactionHandler = async (input: any): Promise<ToolResult
403
377
 
404
378
  const populatedTx = await wallet.populateTransaction(input.transaction);
405
379
 
406
- return createSuccessResponse({
407
- populatedTransaction: {
408
- to: populatedTx.to,
409
- from: populatedTx.from,
410
- nonce: populatedTx.nonce,
411
- gasLimit: populatedTx.gasLimit?.toString(),
412
- gasPrice: populatedTx.gasPrice?.toString(),
413
- data: populatedTx.data,
414
- value: populatedTx.value?.toString(),
415
- chainId: populatedTx.chainId,
416
- type: populatedTx.type,
417
- maxFeePerGas: populatedTx.maxFeePerGas?.toString(),
418
- maxPriorityFeePerGas: populatedTx.maxPriorityFeePerGas?.toString()
419
- }
420
- }, `Transaction populated successfully
380
+ return createSuccessResponse(
381
+ `Transaction populated successfully
421
382
  To: ${populatedTx.to}
422
383
  From: ${populatedTx.from}
423
384
  Nonce: ${populatedTx.nonce?.toString() ?? "Not specified"}
@@ -431,7 +392,7 @@ export const populateTransactionHandler = async (input: any): Promise<ToolResult
431
392
 
432
393
  // Signing Methods
433
394
 
434
- export const signMessageHandler = async (input: any): Promise<ToolResultSchema<any>> => {
395
+ export const signMessageHandler = async (input: any): Promise<ToolResultSchema> => {
435
396
  try {
436
397
  if (!input.message) {
437
398
  return createErrorResponse("Message is required");
@@ -440,10 +401,7 @@ export const signMessageHandler = async (input: any): Promise<ToolResultSchema<a
440
401
  const wallet = await getWallet(input.wallet, input.password);
441
402
  const signature = await wallet.signMessage(input.message);
442
403
 
443
- return createSuccessResponse({
444
- signature,
445
- message: input.message
446
- }, `Message signed successfully
404
+ return createSuccessResponse(`Message signed successfully
447
405
  Signature: ${signature}
448
406
  Message: "${input.message}"
449
407
  `);
@@ -452,7 +410,7 @@ export const signMessageHandler = async (input: any): Promise<ToolResultSchema<a
452
410
  }
453
411
  };
454
412
 
455
- export const signTypedDataHandler = async (input: any): Promise<ToolResultSchema<any>> => {
413
+ export const signTypedDataHandler = async (input: any): Promise<ToolResultSchema> => {
456
414
  try {
457
415
  if (!input.wallet) {
458
416
  return createErrorResponse("Wallet is required");
@@ -468,12 +426,8 @@ export const signTypedDataHandler = async (input: any): Promise<ToolResultSchema
468
426
  // @ts-ignore - _signTypedData is not in the type definitions but is available
469
427
  const signature = await wallet._signTypedData(input.domain, input.types, input.value);
470
428
 
471
- return createSuccessResponse({
472
- signature,
473
- domain: input.domain,
474
- types: input.types,
475
- value: input.value
476
- }, `Typed data signed successfully
429
+ return createSuccessResponse(
430
+ `Typed data signed successfully
477
431
  Signature: ${signature}
478
432
  Domain: ${input.domain}
479
433
  Types: ${input.types}
@@ -484,7 +438,7 @@ export const signTypedDataHandler = async (input: any): Promise<ToolResultSchema
484
438
  }
485
439
  };
486
440
 
487
- export const verifyMessageHandler = async (input: any): Promise<ToolResultSchema<any>> => {
441
+ export const verifyMessageHandler = async (input: any): Promise<ToolResultSchema> => {
488
442
  try {
489
443
  if (!input.message || !input.signature || !input.address) {
490
444
  return createErrorResponse("Message, signature, and address are required");
@@ -493,10 +447,8 @@ export const verifyMessageHandler = async (input: any): Promise<ToolResultSchema
493
447
  const recoveredAddress = ethers.utils.verifyMessage(input.message, input.signature);
494
448
  const isValid = recoveredAddress.toLowerCase() === input.address.toLowerCase();
495
449
 
496
- return createSuccessResponse({
497
- isValid,
498
- recoveredAddress
499
- }, isValid ? `Signature verified successfully
450
+ return createSuccessResponse(
451
+ isValid ? `Signature verified successfully
500
452
  Message: "${input.message}"
501
453
  Signature: ${input.signature}
502
454
  Address: ${input.address}
@@ -510,7 +462,7 @@ export const verifyMessageHandler = async (input: any): Promise<ToolResultSchema
510
462
  }
511
463
  };
512
464
 
513
- export const verifyTypedDataHandler = async (input: any): Promise<ToolResultSchema<any>> => {
465
+ export const verifyTypedDataHandler = async (input: any): Promise<ToolResultSchema> => {
514
466
  try {
515
467
  if (!input.domain || !input.types || !input.value || !input.signature || !input.address) {
516
468
  return createErrorResponse("Domain, types, value, signature, and address are required");
@@ -526,10 +478,8 @@ export const verifyTypedDataHandler = async (input: any): Promise<ToolResultSche
526
478
 
527
479
  const isValid = recoveredAddress.toLowerCase() === input.address.toLowerCase();
528
480
 
529
- return createSuccessResponse({
530
- isValid,
531
- recoveredAddress
532
- }, isValid ? `Typed data signature is valid
481
+ return createSuccessResponse(
482
+ isValid ? `Typed data signature is valid
533
483
  Domain: ${input.domain}
534
484
  Types: ${input.types}
535
485
  Value: ${input.value}
@@ -543,7 +493,7 @@ export const verifyTypedDataHandler = async (input: any): Promise<ToolResultSche
543
493
 
544
494
  // Provider Methods
545
495
 
546
- export const getBlockHandler = async (input: any): Promise<ToolResultSchema<any>> => {
496
+ export const getBlockHandler = async (input: any): Promise<ToolResultSchema> => {
547
497
  try {
548
498
  if (!input.blockHashOrBlockTag) {
549
499
  return createErrorResponse("Block hash or block tag is required");
@@ -554,9 +504,8 @@ export const getBlockHandler = async (input: any): Promise<ToolResultSchema<any>
554
504
  // but TypeScript definitions might not reflect this
555
505
  const block = await (provider as any).getBlock(input.blockHashOrBlockTag, input.includeTransactions);
556
506
 
557
- return createSuccessResponse({
558
- block
559
- }, `Block retrieved successfully
507
+ return createSuccessResponse(
508
+ `Block retrieved successfully
560
509
  Block hash: ${block.hash}
561
510
  Block number: ${block.number?.toString() ?? "Not specified"}
562
511
  Block timestamp: ${block.timestamp?.toString() ?? "Not specified"}
@@ -567,7 +516,7 @@ export const getBlockHandler = async (input: any): Promise<ToolResultSchema<any>
567
516
  }
568
517
  };
569
518
 
570
- export const getTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
519
+ export const getTransactionHandler = async (input: any): Promise<ToolResultSchema> => {
571
520
  try {
572
521
  if (!input.transactionHash) {
573
522
  return createErrorResponse("Transaction hash is required");
@@ -576,9 +525,8 @@ export const getTransactionHandler = async (input: any): Promise<ToolResultSchem
576
525
  const provider = getProvider();
577
526
  const transaction = await provider.getTransaction(input.transactionHash);
578
527
 
579
- return createSuccessResponse({
580
- transaction
581
- }, `Transaction retrieved successfully
528
+ return createSuccessResponse(
529
+ `Transaction retrieved successfully
582
530
  Transaction hash: ${input.transactionHash}
583
531
  Transaction: ${transaction}
584
532
  `);
@@ -587,7 +535,7 @@ export const getTransactionHandler = async (input: any): Promise<ToolResultSchem
587
535
  }
588
536
  };
589
537
 
590
- export const getTransactionReceiptHandler = async (input: any): Promise<ToolResultSchema<any>> => {
538
+ export const getTransactionReceiptHandler = async (input: any): Promise<ToolResultSchema> => {
591
539
  try {
592
540
  if (!input.transactionHash) {
593
541
  return createErrorResponse("Transaction hash is required");
@@ -596,9 +544,8 @@ export const getTransactionReceiptHandler = async (input: any): Promise<ToolResu
596
544
  const provider = getProvider();
597
545
  const receipt = await provider.getTransactionReceipt(input.transactionHash);
598
546
 
599
- return createSuccessResponse({
600
- receipt
601
- }, `Transaction receipt retrieved successfully
547
+ return createSuccessResponse(
548
+ `Transaction receipt retrieved successfully
602
549
  Transaction hash: ${input.transactionHash}
603
550
  Transaction receipt: ${receipt}
604
551
  `);
@@ -607,7 +554,7 @@ export const getTransactionReceiptHandler = async (input: any): Promise<ToolResu
607
554
  }
608
555
  };
609
556
 
610
- export const getCodeHandler = async (input: any): Promise<ToolResultSchema<any>> => {
557
+ export const getCodeHandler = async (input: any): Promise<ToolResultSchema> => {
611
558
  try {
612
559
  if (!input.address) {
613
560
  return createErrorResponse("Address is required");
@@ -616,9 +563,8 @@ export const getCodeHandler = async (input: any): Promise<ToolResultSchema<any>>
616
563
  const provider = getProvider();
617
564
  const code = await provider.getCode(input.address, input.blockTag);
618
565
 
619
- return createSuccessResponse({
620
- code
621
- }, `Code retrieved successfully
566
+ return createSuccessResponse(
567
+ `Code retrieved successfully
622
568
  Address: ${input.address}
623
569
  Code: ${code}
624
570
  `);
@@ -627,7 +573,7 @@ export const getCodeHandler = async (input: any): Promise<ToolResultSchema<any>>
627
573
  }
628
574
  };
629
575
 
630
- export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<any>> => {
576
+ export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema> => {
631
577
  try {
632
578
  if (!input.address) {
633
579
  return createErrorResponse("Address is required");
@@ -640,9 +586,8 @@ export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<
640
586
  const provider = getProvider();
641
587
  const storage = await provider.getStorageAt(input.address, input.position, input.blockTag);
642
588
 
643
- return createSuccessResponse({
644
- storage
645
- }, `Storage retrieved successfully
589
+ return createSuccessResponse(
590
+ `Storage retrieved successfully
646
591
  Address: ${input.address}
647
592
  Position: ${input.position}
648
593
  Storage: ${storage}
@@ -652,7 +597,7 @@ export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<
652
597
  }
653
598
  };
654
599
 
655
- export const estimateGasHandler = async (input: any): Promise<ToolResultSchema<any>> => {
600
+ export const estimateGasHandler = async (input: any): Promise<ToolResultSchema> => {
656
601
  try {
657
602
  if (!input.transaction) {
658
603
  return createErrorResponse("Transaction is required");
@@ -664,9 +609,8 @@ export const estimateGasHandler = async (input: any): Promise<ToolResultSchema<a
664
609
  }
665
610
  const gasEstimate = await provider.estimateGas(input.transaction);
666
611
 
667
- return createSuccessResponse({
668
- gasEstimate: gasEstimate.toString()
669
- }, `Gas estimate retrieved successfully
612
+ return createSuccessResponse(
613
+ `Gas estimate retrieved successfully
670
614
  Gas estimate: ${gasEstimate.toString()}
671
615
  `);
672
616
  } catch (error) {
@@ -674,7 +618,7 @@ export const estimateGasHandler = async (input: any): Promise<ToolResultSchema<a
674
618
  }
675
619
  };
676
620
 
677
- export const getLogsHandler = async (input: any): Promise<ToolResultSchema<any>> => {
621
+ export const getLogsHandler = async (input: any): Promise<ToolResultSchema> => {
678
622
  try {
679
623
  if (!input.filter) {
680
624
  return createErrorResponse("Filter is required");
@@ -686,9 +630,8 @@ export const getLogsHandler = async (input: any): Promise<ToolResultSchema<any>>
686
630
  }
687
631
  const logs = await provider.getLogs(input.filter);
688
632
 
689
- return createSuccessResponse({
690
- logs
691
- }, `Logs retrieved successfully
633
+ return createSuccessResponse(
634
+ `Logs retrieved successfully
692
635
  Logs: ${logs}
693
636
  `);
694
637
  } catch (error) {
@@ -696,7 +639,7 @@ export const getLogsHandler = async (input: any): Promise<ToolResultSchema<any>>
696
639
  }
697
640
  };
698
641
 
699
- export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchema<any>> => {
642
+ export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchema> => {
700
643
  try {
701
644
  if (!input.name) {
702
645
  return createErrorResponse("ENS name is required");
@@ -710,12 +653,8 @@ export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchem
710
653
  // but it's available in the implementation
711
654
  const resolver = await (provider as any).getResolver(input.name);
712
655
 
713
- return createSuccessResponse({
714
- resolver: resolver ? {
715
- address: resolver.address,
716
- name: resolver.name
717
- } : null
718
- }, resolver ? `ENS resolver retrieved successfully
656
+ return createSuccessResponse(
657
+ resolver ? `ENS resolver retrieved successfully
719
658
  Address: ${resolver.address}
720
659
  Name: ${resolver.name}
721
660
  ` : "No resolver found for this ENS name");
@@ -724,7 +663,7 @@ export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchem
724
663
  }
725
664
  };
726
665
 
727
- export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema<any>> => {
666
+ export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema> => {
728
667
  try {
729
668
  if (!input.address) {
730
669
  return createErrorResponse("Address is required");
@@ -736,9 +675,8 @@ export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema
736
675
  }
737
676
  const name = await provider.lookupAddress(input.address);
738
677
 
739
- return createSuccessResponse({
740
- name
741
- }, name ? `ENS name retrieved successfully
678
+ return createSuccessResponse(
679
+ name ? `ENS name retrieved successfully
742
680
  Name: ${name}
743
681
  ` : "No ENS name found for this address");
744
682
  } catch (error) {
@@ -746,7 +684,7 @@ export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema
746
684
  }
747
685
  };
748
686
 
749
- export const resolveNameHandler = async (input: any): Promise<ToolResultSchema<any>> => {
687
+ export const resolveNameHandler = async (input: any): Promise<ToolResultSchema> => {
750
688
  try {
751
689
  if (!input.name) {
752
690
  return createErrorResponse("ENS name is required");
@@ -758,9 +696,8 @@ export const resolveNameHandler = async (input: any): Promise<ToolResultSchema<a
758
696
  }
759
697
  const address = await provider.resolveName(input.name);
760
698
 
761
- return createSuccessResponse({
762
- address
763
- }, address ? `ENS name resolved successfully
699
+ return createSuccessResponse(
700
+ address ? `ENS name resolved successfully
764
701
  Name: ${input.name}
765
702
  Address: ${address}
766
703
  ` : "Could not resolve this ENS name");
@@ -771,7 +708,7 @@ export const resolveNameHandler = async (input: any): Promise<ToolResultSchema<a
771
708
 
772
709
  // Network Methods
773
710
 
774
- export const getNetworkHandler = async (input: any): Promise<ToolResultSchema<any>> => {
711
+ export const getNetworkHandler = async (input: any): Promise<ToolResultSchema> => {
775
712
  try {
776
713
  const provider = getProvider();
777
714
  if (!provider) {
@@ -779,13 +716,7 @@ export const getNetworkHandler = async (input: any): Promise<ToolResultSchema<an
779
716
  }
780
717
  const network = await provider.getNetwork();
781
718
 
782
- return createSuccessResponse({
783
- network: {
784
- name: network.name,
785
- chainId: network.chainId,
786
- ensAddress: network.ensAddress
787
- }
788
- }, `Network information retrieved successfully
719
+ return createSuccessResponse(`Network information retrieved successfully
789
720
  Network name: ${network.name}
790
721
  Chain ID: ${network.chainId}
791
722
  ENS address: ${network.ensAddress}
@@ -795,7 +726,7 @@ export const getNetworkHandler = async (input: any): Promise<ToolResultSchema<an
795
726
  }
796
727
  };
797
728
 
798
- export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchema<any>> => {
729
+ export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchema> => {
799
730
  try {
800
731
  const provider = getProvider();
801
732
  if (!provider) {
@@ -803,9 +734,8 @@ export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchem
803
734
  }
804
735
  const blockNumber = await provider.getBlockNumber();
805
736
 
806
- return createSuccessResponse({
807
- blockNumber
808
- }, `Block number retrieved successfully
737
+ return createSuccessResponse(
738
+ `Block number retrieved successfully
809
739
  Block number: ${blockNumber.toString()}
810
740
  `);
811
741
  } catch (error) {
@@ -813,7 +743,7 @@ export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchem
813
743
  }
814
744
  };
815
745
 
816
- export const getFeeDataHandler = async (input: any): Promise<ToolResultSchema<any>> => {
746
+ export const getFeeDataHandler = async (input: any): Promise<ToolResultSchema> => {
817
747
  try {
818
748
  const provider = getProvider();
819
749
  if (!provider) {
@@ -823,13 +753,7 @@ export const getFeeDataHandler = async (input: any): Promise<ToolResultSchema<an
823
753
  // @ts-ignore - getFeeData might not be in the type definitions depending on the version
824
754
  const feeData = await provider.getFeeData();
825
755
 
826
- return createSuccessResponse({
827
- feeData: {
828
- gasPrice: feeData.gasPrice?.toString(),
829
- maxFeePerGas: feeData.maxFeePerGas?.toString(),
830
- maxPriorityFeePerGas: feeData.maxPriorityFeePerGas?.toString()
831
- }
832
- }, `Fee data retrieved successfully
756
+ return createSuccessResponse(`Fee data retrieved successfully
833
757
  Gas price: ${feeData.gasPrice?.toString()}
834
758
  Max fee per gas: ${feeData.maxFeePerGas?.toString()}
835
759
  Max priority fee per gas: ${feeData.maxPriorityFeePerGas?.toString()}
package/src/types.ts CHANGED
@@ -1,7 +1,6 @@
1
- export type ToolResultSchema<T> = {
1
+ export type ToolResultSchema = {
2
2
  content: ToolResultContent[];
3
3
  isError?: boolean;
4
- toolResult?: T;
5
4
  }
6
5
 
7
6
  export type ToolResultContent = {