@mcp-dockmaster/mcp-cryptowallet-evm 1.0.0 → 1.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/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ # Optional private key for wallet operations
2
+ PRIVATE_KEY=your_private_key_here
package/README.md CHANGED
@@ -91,6 +91,12 @@ This will download and execute the server directly from npm.
91
91
 
92
92
  ## Configuration
93
93
 
94
+ ### Environment Variables
95
+
96
+ The MCP server supports the following environment variables:
97
+
98
+ - `PRIVATE_KEY`: Optional private key to use for wallet operations when no wallet is explicitly provided
99
+
94
100
  ### Configure Claude Desktop
95
101
 
96
102
  To configure Claude Desktop to use this MCP server:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-dockmaster/mcp-cryptowallet-evm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "MCP server for EVM crypto wallet operations using ethers.js v5",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -64,12 +64,23 @@ export const getProvider = (providerUrl?: string): ethers.providers.Provider =>
64
64
  * @returns An ethers.js wallet
65
65
  */
66
66
  export const getWallet = async (
67
- walletData: string,
67
+ walletData?: string,
68
68
  password?: string,
69
69
  providerUrl?: string
70
70
  ): Promise<ethers.Wallet> => {
71
71
  const provider = providerUrl ? getProvider(providerUrl) : undefined;
72
72
 
73
+ // If walletData is not provided, check for PRIVATE_KEY environment variable
74
+ if (!walletData && process.env.PRIVATE_KEY) {
75
+ const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
76
+ return provider ? wallet.connect(provider) : wallet;
77
+ }
78
+
79
+ // If no walletData and no environment variable, throw an error
80
+ if (!walletData) {
81
+ throw new Error("Wallet data is required or set PRIVATE_KEY environment variable");
82
+ }
83
+
73
84
  try {
74
85
  // Try to parse as JSON first
75
86
  if (walletData.startsWith("{")) {
@@ -170,10 +170,6 @@ export const encryptWalletHandler = async (input: any): Promise<ToolResultSchema
170
170
 
171
171
  export const getAddressHandler = async (input: any): Promise<ToolResultSchema<any>> => {
172
172
  try {
173
- if (!input.wallet) {
174
- return createErrorResponse("Wallet is required");
175
- }
176
-
177
173
  const wallet = await getWallet(input.wallet);
178
174
 
179
175
  return createSuccessResponse({
@@ -186,10 +182,6 @@ export const getAddressHandler = async (input: any): Promise<ToolResultSchema<an
186
182
 
187
183
  export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema<any>> => {
188
184
  try {
189
- if (!input.wallet) {
190
- return createErrorResponse("Wallet is required");
191
- }
192
-
193
185
  const wallet = await getWallet(input.wallet);
194
186
 
195
187
  return createSuccessResponse({
@@ -202,10 +194,6 @@ export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema<
202
194
 
203
195
  export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema<any>> => {
204
196
  try {
205
- if (!input.wallet) {
206
- return createErrorResponse("Wallet is required");
207
- }
208
-
209
197
  const wallet = await getWallet(input.wallet, input.password);
210
198
 
211
199
  return createSuccessResponse({
@@ -219,9 +207,6 @@ export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema
219
207
 
220
208
  export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
221
209
  try {
222
- if (!input.wallet) {
223
- return createErrorResponse("Wallet is required");
224
- }
225
210
  if (!input.provider) {
226
211
  return createErrorResponse("Provider URL is required to get balance");
227
212
  }
@@ -244,10 +229,6 @@ export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<an
244
229
 
245
230
  export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<any>> => {
246
231
  try {
247
- if (!input.wallet) {
248
- return createErrorResponse("Wallet is required");
249
- }
250
-
251
232
  const wallet = await getWallet(input.wallet, input.password, input.provider);
252
233
 
253
234
  if (!wallet.provider) {
@@ -268,10 +249,6 @@ export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<an
268
249
 
269
250
  export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
270
251
  try {
271
- if (!input.wallet) {
272
- return createErrorResponse("Wallet is required");
273
- }
274
-
275
252
  const wallet = await getWallet(input.wallet, input.password, input.provider);
276
253
 
277
254
  if (!wallet.provider) {
@@ -294,10 +271,6 @@ export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<a
294
271
 
295
272
  export const getTransactionCountHandler = async (input: any): Promise<ToolResultSchema<any>> => {
296
273
  try {
297
- if (!input.wallet) {
298
- return createErrorResponse("Wallet is required");
299
- }
300
-
301
274
  const wallet = await getWallet(input.wallet, input.password, input.provider);
302
275
 
303
276
  if (!wallet.provider) {
@@ -318,10 +291,6 @@ export const getTransactionCountHandler = async (input: any): Promise<ToolResult
318
291
 
319
292
  export const callHandler = async (input: any): Promise<ToolResultSchema<any>> => {
320
293
  try {
321
- if (!input.wallet) {
322
- return createErrorResponse("Wallet is required");
323
- }
324
-
325
294
  if (!input.transaction) {
326
295
  return createErrorResponse("Transaction is required");
327
296
  }
@@ -348,10 +317,6 @@ export const callHandler = async (input: any): Promise<ToolResultSchema<any>> =>
348
317
 
349
318
  export const sendTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
350
319
  try {
351
- if (!input.wallet) {
352
- return createErrorResponse("Wallet is required");
353
- }
354
-
355
320
  if (!input.transaction) {
356
321
  return createErrorResponse("Transaction is required");
357
322
  }
@@ -389,10 +354,6 @@ export const sendTransactionHandler = async (input: any): Promise<ToolResultSche
389
354
 
390
355
  export const signTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
391
356
  try {
392
- if (!input.wallet) {
393
- return createErrorResponse("Wallet is required");
394
- }
395
-
396
357
  if (!input.transaction) {
397
358
  return createErrorResponse("Transaction is required");
398
359
  }
@@ -415,10 +376,6 @@ export const signTransactionHandler = async (input: any): Promise<ToolResultSche
415
376
 
416
377
  export const populateTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
417
378
  try {
418
- if (!input.wallet) {
419
- return createErrorResponse("Wallet is required");
420
- }
421
-
422
379
  if (!input.transaction) {
423
380
  return createErrorResponse("Transaction is required");
424
381
  }
@@ -461,10 +418,6 @@ export const populateTransactionHandler = async (input: any): Promise<ToolResult
461
418
 
462
419
  export const signMessageHandler = async (input: any): Promise<ToolResultSchema<any>> => {
463
420
  try {
464
- if (!input.wallet) {
465
- return createErrorResponse("Wallet is required");
466
- }
467
-
468
421
  if (!input.message) {
469
422
  return createErrorResponse("Message is required");
470
423
  }
package/src/tools.ts CHANGED
@@ -135,9 +135,9 @@ export const tools = [
135
135
  inputSchema: {
136
136
  type: "object",
137
137
  properties: {
138
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" }
138
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." }
139
139
  },
140
- required: ["wallet"]
140
+ required: []
141
141
  }
142
142
  },
143
143
  {
@@ -146,9 +146,9 @@ export const tools = [
146
146
  inputSchema: {
147
147
  type: "object",
148
148
  properties: {
149
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" }
149
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." }
150
150
  },
151
- required: ["wallet"]
151
+ required: []
152
152
  }
153
153
  },
154
154
  {
@@ -157,10 +157,10 @@ export const tools = [
157
157
  inputSchema: {
158
158
  type: "object",
159
159
  properties: {
160
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
160
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
161
161
  password: { type: "string", description: "The password to decrypt the wallet if it's encrypted" }
162
162
  },
163
- required: ["wallet"]
163
+ required: []
164
164
  }
165
165
  },
166
166
  // Blockchain Methods
@@ -170,11 +170,11 @@ export const tools = [
170
170
  inputSchema: {
171
171
  type: "object",
172
172
  properties: {
173
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
173
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
174
174
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
175
175
  blockTag: { type: "string", description: "Optional block tag (latest, pending, etc.)" }
176
176
  },
177
- required: ["wallet", "provider"]
177
+ required: ["provider"]
178
178
  }
179
179
  },
180
180
  {
@@ -183,10 +183,10 @@ export const tools = [
183
183
  inputSchema: {
184
184
  type: "object",
185
185
  properties: {
186
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
186
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
187
187
  provider: { type: "string", description: "Optional JSON RPC provider URL" }
188
188
  },
189
- required: ["wallet"]
189
+ required: []
190
190
  }
191
191
  },
192
192
  {
@@ -195,10 +195,10 @@ export const tools = [
195
195
  inputSchema: {
196
196
  type: "object",
197
197
  properties: {
198
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
198
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
199
199
  provider: { type: "string", description: "Optional JSON RPC provider URL" }
200
200
  },
201
- required: ["wallet"]
201
+ required: []
202
202
  }
203
203
  },
204
204
  {
@@ -207,11 +207,11 @@ export const tools = [
207
207
  inputSchema: {
208
208
  type: "object",
209
209
  properties: {
210
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
210
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
211
211
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
212
212
  blockTag: { type: "string", description: "Optional block tag (latest, pending, etc.)" }
213
213
  },
214
- required: ["wallet"]
214
+ required: []
215
215
  }
216
216
  },
217
217
  {
@@ -220,7 +220,7 @@ export const tools = [
220
220
  inputSchema: {
221
221
  type: "object",
222
222
  properties: {
223
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
223
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
224
224
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
225
225
  transaction: {
226
226
  type: "object",
@@ -237,7 +237,7 @@ export const tools = [
237
237
  },
238
238
  blockTag: { type: "string", description: "Optional block tag (latest, pending, etc.)" }
239
239
  },
240
- required: ["wallet", "transaction"]
240
+ required: ["transaction"]
241
241
  }
242
242
  },
243
243
 
@@ -248,7 +248,7 @@ export const tools = [
248
248
  inputSchema: {
249
249
  type: "object",
250
250
  properties: {
251
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
251
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
252
252
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
253
253
  transaction: {
254
254
  type: "object",
@@ -268,7 +268,7 @@ export const tools = [
268
268
  required: ["to"]
269
269
  }
270
270
  },
271
- required: ["wallet", "transaction"]
271
+ required: ["transaction"]
272
272
  }
273
273
  },
274
274
  {
@@ -277,7 +277,7 @@ export const tools = [
277
277
  inputSchema: {
278
278
  type: "object",
279
279
  properties: {
280
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
280
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
281
281
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
282
282
  transaction: {
283
283
  type: "object",
@@ -297,7 +297,7 @@ export const tools = [
297
297
  required: ["to"]
298
298
  }
299
299
  },
300
- required: ["wallet", "transaction"]
300
+ required: ["transaction"]
301
301
  }
302
302
  },
303
303
  {
@@ -306,7 +306,7 @@ export const tools = [
306
306
  inputSchema: {
307
307
  type: "object",
308
308
  properties: {
309
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
309
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
310
310
  provider: { type: "string", description: "Optional JSON RPC provider URL" },
311
311
  transaction: {
312
312
  type: "object",
@@ -326,7 +326,7 @@ export const tools = [
326
326
  required: ["to"]
327
327
  }
328
328
  },
329
- required: ["wallet", "transaction"]
329
+ required: ["transaction"]
330
330
  }
331
331
  },
332
332
 
@@ -337,10 +337,10 @@ export const tools = [
337
337
  inputSchema: {
338
338
  type: "object",
339
339
  properties: {
340
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
340
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
341
341
  message: { type: "string", description: "The message to sign" }
342
342
  },
343
- required: ["wallet", "message"]
343
+ required: ["message"]
344
344
  }
345
345
  },
346
346
  {
@@ -349,12 +349,12 @@ export const tools = [
349
349
  inputSchema: {
350
350
  type: "object",
351
351
  properties: {
352
- wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON)" },
352
+ wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
353
353
  domain: { type: "object", description: "The domain data" },
354
354
  types: { type: "object", description: "The type definitions" },
355
355
  value: { type: "object", description: "The value to sign" }
356
356
  },
357
- required: ["wallet", "domain", "types", "value"]
357
+ required: ["domain", "types", "value"]
358
358
  }
359
359
  },
360
360
  {