@mcp-dockmaster/mcp-cryptowallet-evm 1.0.0
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/.eslintrc/index.js +12 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/build/handlers/utils.d.ts +29 -0
- package/build/handlers/utils.js +86 -0
- package/build/handlers/utils.js.map +1 -0
- package/build/handlers/wallet.d.ts +36 -0
- package/build/handlers/wallet.js +781 -0
- package/build/handlers/wallet.js.map +1 -0
- package/build/handlers/wallet.types.d.ts +14 -0
- package/build/handlers/wallet.types.js +2 -0
- package/build/handlers/wallet.types.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +32 -0
- package/build/index.js.map +1 -0
- package/build/tools.d.ts +1143 -0
- package/build/tools.js +571 -0
- package/build/tools.js.map +1 -0
- package/build/types.d.ts +20 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/jest.config.js +17 -0
- package/package.json +48 -0
- package/required-methods.md +53 -0
- package/src/handlers/utils.ts +97 -0
- package/src/handlers/wallet.ts +901 -0
- package/src/handlers/wallet.types.ts +16 -0
- package/src/index.ts +40 -0
- package/src/tools.ts +621 -0
- package/src/types.ts +21 -0
- package/tests/handlers/network.test.ts +73 -0
- package/tests/handlers/provider.test.ts +197 -0
- package/tests/handlers/wallet.test.ts +289 -0
- package/tsconfig.json +17 -0
package/package.json
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"name": "@mcp-dockmaster/mcp-cryptowallet-evm",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "MCP server for EVM crypto wallet operations using ethers.js v5",
|
5
|
+
"main": "build/index.js",
|
6
|
+
"type": "module",
|
7
|
+
"bin": {
|
8
|
+
"mcp-cryptowallet-evm": "./build/index.js"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"build": "tsc",
|
12
|
+
"start": "node build/index.js",
|
13
|
+
"test": "jest",
|
14
|
+
"lint": "eslint src/**/*.ts"
|
15
|
+
},
|
16
|
+
"repository": {
|
17
|
+
"type": "git",
|
18
|
+
"url": "git+https://github.com/dcSpark/mcp-cryptowallet-evm.git"
|
19
|
+
},
|
20
|
+
"keywords": [
|
21
|
+
"mcp",
|
22
|
+
"ethereum",
|
23
|
+
"evm",
|
24
|
+
"wallet",
|
25
|
+
"ethers"
|
26
|
+
],
|
27
|
+
"author": "dcSpark",
|
28
|
+
"license": "MIT",
|
29
|
+
"bugs": {
|
30
|
+
"url": "https://github.com/dcSpark/mcp-cryptowallet-evm/issues"
|
31
|
+
},
|
32
|
+
"homepage": "https://github.com/dcSpark/mcp-cryptowallet-evm#readme",
|
33
|
+
"dependencies": {
|
34
|
+
"@modelcontextprotocol/sdk": "^1.6.1",
|
35
|
+
"@scure/bip39": "^1.5.4",
|
36
|
+
"ethers": "^5.7.2"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"@types/jest": "^29.5.0",
|
40
|
+
"@types/node": "^18.15.11",
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
42
|
+
"@typescript-eslint/parser": "^5.57.1",
|
43
|
+
"eslint": "^8.38.0",
|
44
|
+
"jest": "^29.5.0",
|
45
|
+
"ts-jest": "^29.1.0",
|
46
|
+
"typescript": "^5.0.4"
|
47
|
+
}
|
48
|
+
}
|
@@ -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.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
import { ToolResultSchema } from "../types.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Creates a success response with the given result
|
6
|
+
* @param result The result to include in the response
|
7
|
+
* @param message Optional message to include in the response
|
8
|
+
* @returns A ToolResultSchema with the result and message
|
9
|
+
*/
|
10
|
+
export const createSuccessResponse = <T>(result: T, message?: string): ToolResultSchema<T> => {
|
11
|
+
return {
|
12
|
+
content: [
|
13
|
+
{
|
14
|
+
type: "text",
|
15
|
+
text: message || "Operation completed successfully"
|
16
|
+
}
|
17
|
+
],
|
18
|
+
isError: false,
|
19
|
+
toolResult: result
|
20
|
+
};
|
21
|
+
};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Creates an error response with the given message
|
25
|
+
* @param message The error message
|
26
|
+
* @returns A ToolResultSchema with the error message
|
27
|
+
*/
|
28
|
+
export const createErrorResponse = (message: string): ToolResultSchema<any> => {
|
29
|
+
return {
|
30
|
+
content: [
|
31
|
+
{
|
32
|
+
type: "text",
|
33
|
+
text: message
|
34
|
+
}
|
35
|
+
],
|
36
|
+
isError: true,
|
37
|
+
toolResult: { error: message }
|
38
|
+
};
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Gets a provider from a provider URL
|
43
|
+
* @param providerUrl The provider URL
|
44
|
+
* @returns An ethers.js provider
|
45
|
+
*/
|
46
|
+
export const getProvider = (providerUrl?: string): ethers.providers.Provider => {
|
47
|
+
if (!providerUrl) {
|
48
|
+
// Default to Ethereum mainnet if no provider URL is specified
|
49
|
+
return ethers.getDefaultProvider();
|
50
|
+
}
|
51
|
+
|
52
|
+
try {
|
53
|
+
return new ethers.providers.JsonRpcProvider(providerUrl);
|
54
|
+
} catch (error) {
|
55
|
+
throw new Error(`Invalid provider URL: ${providerUrl}`);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Gets a wallet from a private key, mnemonic, or JSON wallet
|
61
|
+
* @param walletData The wallet data (private key, mnemonic, or JSON)
|
62
|
+
* @param password Optional password for encrypted JSON wallets
|
63
|
+
* @param provider Optional provider to connect the wallet to
|
64
|
+
* @returns An ethers.js wallet
|
65
|
+
*/
|
66
|
+
export const getWallet = async (
|
67
|
+
walletData: string,
|
68
|
+
password?: string,
|
69
|
+
providerUrl?: string
|
70
|
+
): Promise<ethers.Wallet> => {
|
71
|
+
const provider = providerUrl ? getProvider(providerUrl) : undefined;
|
72
|
+
|
73
|
+
try {
|
74
|
+
// Try to parse as JSON first
|
75
|
+
if (walletData.startsWith("{")) {
|
76
|
+
if (!password) {
|
77
|
+
throw new Error("Password is required for encrypted JSON wallets");
|
78
|
+
}
|
79
|
+
|
80
|
+
const wallet = await ethers.Wallet.fromEncryptedJson(walletData, password);
|
81
|
+
return provider ? wallet.connect(provider) : wallet;
|
82
|
+
}
|
83
|
+
|
84
|
+
// Check if it's a mnemonic (12, 15, 18, 21, or 24 words)
|
85
|
+
const words = walletData.trim().split(/\s+/);
|
86
|
+
if ([12, 15, 18, 21, 24].includes(words.length)) {
|
87
|
+
const wallet = ethers.Wallet.fromMnemonic(walletData);
|
88
|
+
return provider ? wallet.connect(provider) : wallet;
|
89
|
+
}
|
90
|
+
|
91
|
+
// Assume it's a private key
|
92
|
+
const wallet = new ethers.Wallet(walletData);
|
93
|
+
return provider ? wallet.connect(provider) : wallet;
|
94
|
+
} catch (error) {
|
95
|
+
throw new Error(`Invalid wallet data: ${(error as Error).message}`);
|
96
|
+
}
|
97
|
+
};
|