web3-tools-mcp 1.3.0 → 1.3.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/README.md +46 -2
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/gas.d.ts +99 -0
- package/dist/tools/gas.d.ts.map +1 -0
- package/dist/tools/gas.js +229 -0
- package/dist/tools/gas.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/signatures.d.ts +18 -0
- package/dist/tools/signatures.d.ts.map +1 -1
- package/dist/tools/signatures.js +26 -1
- package/dist/tools/signatures.js.map +1 -1
- package/dist/tools/transactions.d.ts +111 -0
- package/dist/tools/transactions.d.ts.map +1 -0
- package/dist/tools/transactions.js +198 -0
- package/dist/tools/transactions.js.map +1 -0
- package/dist/wallet-server.d.ts +34 -0
- package/dist/wallet-server.d.ts.map +1 -0
- package/dist/wallet-server.js +195 -0
- package/dist/wallet-server.js.map +1 -0
- package/package.json +8 -1
- package/public/wallet-app.js +677 -0
- package/public/wallet.html +723 -0
- package/src/index.ts +8 -0
- package/src/tools/gas.ts +267 -0
- package/src/tools/index.ts +5 -1
- package/src/tools/signatures.ts +34 -1
- package/src/tools/transactions.ts +246 -0
- package/src/wallet-server.ts +236 -0
package/README.md
CHANGED
|
@@ -5,9 +5,12 @@ A Model Context Protocol (MCP) server for blockchain interactions using [viem](h
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Multi-chain support (Ethereum, Arbitrum, Avalanche, Base, BNB Chain, Gnosis, Sonic, Optimism, Polygon, zkSync Era, Linea, Unichain)
|
|
8
|
-
-
|
|
8
|
+
- **🔐 Transaction Signing via Browser Wallet** (MetaMask, Rabby, Coinbase Wallet)
|
|
9
|
+
- Smart contract interactions (read & write functions, ABI retrieval, source code)
|
|
10
|
+
- Contract simulation & gas estimation (simulate transactions, estimate costs)
|
|
11
|
+
- Real-time gas price tracking (legacy & EIP-1559)
|
|
9
12
|
- ENS resolution (names ↔ addresses, text records, avatars)
|
|
10
|
-
- Token balances (native & ERC20, batch queries)
|
|
13
|
+
- Token balances & transfers (native & ERC20, batch queries)
|
|
11
14
|
- Event log queries with Hypersync acceleration
|
|
12
15
|
- Transaction tracing and analysis
|
|
13
16
|
- Storage slot reading with type decoding
|
|
@@ -78,6 +81,35 @@ npx web3-tools-mcp
|
|
|
78
81
|
| Unichain | 130 | ✅ |
|
|
79
82
|
| Localhost | 31337 | ❌ |
|
|
80
83
|
|
|
84
|
+
## 🔐 Browser Wallet Integration
|
|
85
|
+
|
|
86
|
+
The server includes a built-in wallet interface for secure transaction signing without exposing private keys.
|
|
87
|
+
|
|
88
|
+
### How It Works
|
|
89
|
+
|
|
90
|
+
1. When you use a transaction tool (e.g., `send_native_token`), the server automatically:
|
|
91
|
+
- Starts a local web server on `http://localhost:3456`
|
|
92
|
+
- Opens your browser to connect your wallet (MetaMask, Rabby, Coinbase Wallet, etc.)
|
|
93
|
+
2. You connect your wallet once in the browser
|
|
94
|
+
3. Transaction requests appear in the browser for approval
|
|
95
|
+
4. Sign or reject transactions directly in your wallet
|
|
96
|
+
|
|
97
|
+
### Supported Wallets
|
|
98
|
+
|
|
99
|
+
- MetaMask
|
|
100
|
+
- Rabby
|
|
101
|
+
- Coinbase Wallet
|
|
102
|
+
- Any browser wallet supporting EIP-1193
|
|
103
|
+
|
|
104
|
+
### Manual Access
|
|
105
|
+
|
|
106
|
+
Visit `http://localhost:3456` anytime to:
|
|
107
|
+
- Check wallet connection status
|
|
108
|
+
- See pending transactions
|
|
109
|
+
- View transaction history
|
|
110
|
+
|
|
111
|
+
**Note:** The wallet server runs automatically when the MCP server starts. No additional setup required!
|
|
112
|
+
|
|
81
113
|
## Available Tools
|
|
82
114
|
|
|
83
115
|
### Signatures
|
|
@@ -93,6 +125,18 @@ npx web3-tools-mcp
|
|
|
93
125
|
|
|
94
126
|
### Contract Interaction
|
|
95
127
|
- `call_contract_function` - Call view/pure functions (supports batch)
|
|
128
|
+
- `call_contract_write` - Execute state-changing contract functions via browser wallet
|
|
129
|
+
- `simulate_contract` - Simulate contract calls without broadcasting (includes gas estimate)
|
|
130
|
+
|
|
131
|
+
### Transactions (Browser Wallet Required)
|
|
132
|
+
- `send_native_token` - Send ETH/native tokens to an address
|
|
133
|
+
- `send_erc20_token` - Send ERC20 tokens to an address
|
|
134
|
+
- `sign_message` - Sign messages with your wallet
|
|
135
|
+
- `wallet_status` - Check wallet connection status
|
|
136
|
+
|
|
137
|
+
### Gas & Simulation
|
|
138
|
+
- `estimate_gas` - Estimate gas cost for any transaction
|
|
139
|
+
- `get_gas_price` - Get current gas prices (legacy & EIP-1559)
|
|
96
140
|
|
|
97
141
|
### ENS
|
|
98
142
|
- `resolve_ens_name` - ENS name → address
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
5
5
|
import { initializeClientManager } from "./client.js";
|
|
6
6
|
import { registerAllTools } from "./tools/index.js";
|
|
7
7
|
import { parseCommandLineArgs } from "./utils.js";
|
|
8
|
+
import { startWalletServer } from "./wallet-server.js";
|
|
8
9
|
// Parse configuration
|
|
9
10
|
const config = parseCommandLineArgs();
|
|
10
11
|
// Show help if requested
|
|
@@ -75,11 +76,17 @@ const server = new McpServer({
|
|
|
75
76
|
});
|
|
76
77
|
// Register all tools
|
|
77
78
|
registerAllTools(server);
|
|
79
|
+
// Start wallet server in background
|
|
80
|
+
startWalletServer().catch((error) => {
|
|
81
|
+
console.error("[MCP] Wallet server failed to start:", error.message);
|
|
82
|
+
console.error("[MCP] Transaction signing features will not be available");
|
|
83
|
+
});
|
|
78
84
|
// Start server
|
|
79
85
|
async function main() {
|
|
80
86
|
const transport = new StdioServerTransport();
|
|
81
87
|
await server.connect(transport);
|
|
82
88
|
console.error("Web3 Tools MCP Server running on stdio");
|
|
89
|
+
console.error("Wallet interface available at http://localhost:3456");
|
|
83
90
|
}
|
|
84
91
|
main().catch((error) => {
|
|
85
92
|
console.error("Fatal error:", error);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,sBAAsB;AACtB,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;AAEtC,yBAAyB;AACzB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC;yBACW,WAAW,CAAC,OAAO;EAC1C,WAAW,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAmCb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B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACxD,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
simulate_contract: {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: z.ZodObject<{
|
|
7
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
8
|
+
contractAddress: z.ZodString;
|
|
9
|
+
functionAbi: z.ZodString;
|
|
10
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>;
|
|
11
|
+
from: z.ZodOptional<z.ZodString>;
|
|
12
|
+
value: z.ZodOptional<z.ZodString>;
|
|
13
|
+
blockNumber: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
functionAbi: string;
|
|
18
|
+
blockNumber?: string | undefined;
|
|
19
|
+
from?: string | undefined;
|
|
20
|
+
value?: string | undefined;
|
|
21
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
24
|
+
contractAddress: string;
|
|
25
|
+
functionAbi: string;
|
|
26
|
+
blockNumber?: string | undefined;
|
|
27
|
+
from?: string | undefined;
|
|
28
|
+
value?: string | undefined;
|
|
29
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
handler: (args: {
|
|
32
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
33
|
+
contractAddress: string;
|
|
34
|
+
functionAbi: string;
|
|
35
|
+
blockNumber?: string | undefined;
|
|
36
|
+
from?: string | undefined;
|
|
37
|
+
value?: string | undefined;
|
|
38
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
39
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
40
|
+
};
|
|
41
|
+
estimate_gas: {
|
|
42
|
+
title: string;
|
|
43
|
+
description: string;
|
|
44
|
+
schema: z.ZodObject<{
|
|
45
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
46
|
+
to: z.ZodOptional<z.ZodString>;
|
|
47
|
+
from: z.ZodOptional<z.ZodString>;
|
|
48
|
+
value: z.ZodOptional<z.ZodString>;
|
|
49
|
+
data: z.ZodOptional<z.ZodString>;
|
|
50
|
+
functionAbi: z.ZodOptional<z.ZodString>;
|
|
51
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
54
|
+
from?: string | undefined;
|
|
55
|
+
to?: string | undefined;
|
|
56
|
+
value?: string | undefined;
|
|
57
|
+
data?: string | undefined;
|
|
58
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
59
|
+
functionAbi?: string | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
62
|
+
from?: string | undefined;
|
|
63
|
+
to?: string | undefined;
|
|
64
|
+
value?: string | undefined;
|
|
65
|
+
data?: string | undefined;
|
|
66
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
67
|
+
functionAbi?: string | undefined;
|
|
68
|
+
}>;
|
|
69
|
+
handler: (args: {
|
|
70
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
71
|
+
from?: string | undefined;
|
|
72
|
+
to?: string | undefined;
|
|
73
|
+
value?: string | undefined;
|
|
74
|
+
data?: string | undefined;
|
|
75
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
76
|
+
functionAbi?: string | undefined;
|
|
77
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
78
|
+
};
|
|
79
|
+
get_gas_price: {
|
|
80
|
+
title: string;
|
|
81
|
+
description: string;
|
|
82
|
+
schema: z.ZodObject<{
|
|
83
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
84
|
+
formatted: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
87
|
+
formatted: boolean;
|
|
88
|
+
}, {
|
|
89
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
90
|
+
formatted?: boolean | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
handler: (args: {
|
|
93
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
94
|
+
formatted: boolean;
|
|
95
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export default _default;
|
|
99
|
+
//# sourceMappingURL=gas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../src/tools/gas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKxB,wBAoQE"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { isAddress, parseAbiItem, encodeFunctionData, decodeFunctionResult } from "viem";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getClientManager, SUPPORTED_CHAINS } from "../client.js";
|
|
4
|
+
import { convertArgumentsToTypes, createTool, formatResponse } from "../utils.js";
|
|
5
|
+
export default {
|
|
6
|
+
simulate_contract: createTool("Simulate Contract Call", "Simulate a contract call (including state-changing functions) without broadcasting. Returns simulation result and estimated gas.", z.object({
|
|
7
|
+
chain: z
|
|
8
|
+
.enum(SUPPORTED_CHAINS)
|
|
9
|
+
.describe("Blockchain network to simulate on"),
|
|
10
|
+
contractAddress: z
|
|
11
|
+
.string()
|
|
12
|
+
.describe("Contract address to call"),
|
|
13
|
+
functionAbi: z
|
|
14
|
+
.string()
|
|
15
|
+
.describe('Function ABI signature (e.g., "function transfer(address to, uint256 amount)"). Can be any function type.'),
|
|
16
|
+
args: z
|
|
17
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Function arguments in order matching the ABI signature"),
|
|
20
|
+
from: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("Sender address (defaults to zero address)"),
|
|
24
|
+
value: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("ETH value to send with the transaction (in wei as string)"),
|
|
28
|
+
blockNumber: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Block number for simulation (defaults to latest)"),
|
|
32
|
+
}), async (args) => {
|
|
33
|
+
if (!isAddress(args.contractAddress)) {
|
|
34
|
+
throw new Error(`Invalid contract address: ${args.contractAddress}`);
|
|
35
|
+
}
|
|
36
|
+
if (args.from && !isAddress(args.from)) {
|
|
37
|
+
throw new Error(`Invalid from address: ${args.from}`);
|
|
38
|
+
}
|
|
39
|
+
const clientManager = getClientManager();
|
|
40
|
+
const client = clientManager.getClient(args.chain);
|
|
41
|
+
try {
|
|
42
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
43
|
+
const convertedArgs = convertArgumentsToTypes(args.args || [], abiItem.inputs);
|
|
44
|
+
const blockTag = args.blockNumber ? BigInt(args.blockNumber) : undefined;
|
|
45
|
+
// Simulate the call
|
|
46
|
+
const result = await client.call({
|
|
47
|
+
to: args.contractAddress,
|
|
48
|
+
data: encodeFunctionData({
|
|
49
|
+
abi: [abiItem],
|
|
50
|
+
functionName: abiItem.name,
|
|
51
|
+
args: convertedArgs,
|
|
52
|
+
}),
|
|
53
|
+
account: args.from ? args.from : undefined,
|
|
54
|
+
value: args.value ? BigInt(args.value) : undefined,
|
|
55
|
+
blockNumber: blockTag,
|
|
56
|
+
});
|
|
57
|
+
// Also estimate gas
|
|
58
|
+
const gasEstimate = await client.estimateGas({
|
|
59
|
+
to: args.contractAddress,
|
|
60
|
+
data: encodeFunctionData({
|
|
61
|
+
abi: [abiItem],
|
|
62
|
+
functionName: abiItem.name,
|
|
63
|
+
args: convertedArgs,
|
|
64
|
+
}),
|
|
65
|
+
account: args.from ? args.from : undefined,
|
|
66
|
+
value: args.value ? BigInt(args.value) : undefined,
|
|
67
|
+
blockNumber: blockTag,
|
|
68
|
+
});
|
|
69
|
+
// Decode the result if the function has outputs
|
|
70
|
+
let decodedResult = result.data;
|
|
71
|
+
if (abiItem.outputs && abiItem.outputs.length > 0 && result.data) {
|
|
72
|
+
decodedResult = decodeFunctionResult({
|
|
73
|
+
abi: [abiItem],
|
|
74
|
+
functionName: abiItem.name,
|
|
75
|
+
data: result.data,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return formatResponse({
|
|
79
|
+
success: true,
|
|
80
|
+
chain: args.chain,
|
|
81
|
+
contractAddress: args.contractAddress,
|
|
82
|
+
functionName: abiItem.name,
|
|
83
|
+
result: decodedResult,
|
|
84
|
+
rawData: result.data,
|
|
85
|
+
gasEstimate: gasEstimate.toString(),
|
|
86
|
+
blockNumber: args.blockNumber || "latest",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// Check if it's a revert error
|
|
91
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
92
|
+
return formatResponse({
|
|
93
|
+
success: false,
|
|
94
|
+
chain: args.chain,
|
|
95
|
+
contractAddress: args.contractAddress,
|
|
96
|
+
error: errorMessage,
|
|
97
|
+
reverted: errorMessage.includes("revert") || errorMessage.includes("execution reverted"),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
estimate_gas: createTool("Estimate Gas", "Estimate gas required for a transaction. Supports contract calls, transfers, and deployments.", z.object({
|
|
102
|
+
chain: z
|
|
103
|
+
.enum(SUPPORTED_CHAINS)
|
|
104
|
+
.describe("Blockchain network"),
|
|
105
|
+
to: z
|
|
106
|
+
.string()
|
|
107
|
+
.optional()
|
|
108
|
+
.describe("Recipient address (omit for contract deployment)"),
|
|
109
|
+
from: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe("Sender address (optional)"),
|
|
113
|
+
value: z
|
|
114
|
+
.string()
|
|
115
|
+
.optional()
|
|
116
|
+
.describe("ETH value to send (in wei as string)"),
|
|
117
|
+
data: z
|
|
118
|
+
.string()
|
|
119
|
+
.optional()
|
|
120
|
+
.describe("Transaction data (hex string for contract calls or deployment bytecode)"),
|
|
121
|
+
functionAbi: z
|
|
122
|
+
.string()
|
|
123
|
+
.optional()
|
|
124
|
+
.describe("Optional: Function ABI signature to encode call data automatically"),
|
|
125
|
+
args: z
|
|
126
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
127
|
+
.optional()
|
|
128
|
+
.describe("Optional: Function arguments (only used with functionAbi)"),
|
|
129
|
+
}), async (args) => {
|
|
130
|
+
if (args.to && !isAddress(args.to)) {
|
|
131
|
+
throw new Error(`Invalid to address: ${args.to}`);
|
|
132
|
+
}
|
|
133
|
+
if (args.from && !isAddress(args.from)) {
|
|
134
|
+
throw new Error(`Invalid from address: ${args.from}`);
|
|
135
|
+
}
|
|
136
|
+
const clientManager = getClientManager();
|
|
137
|
+
const client = clientManager.getClient(args.chain);
|
|
138
|
+
try {
|
|
139
|
+
let callData = args.data;
|
|
140
|
+
// If functionAbi is provided, encode the call data
|
|
141
|
+
if (args.functionAbi) {
|
|
142
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
143
|
+
const convertedArgs = convertArgumentsToTypes(args.args || [], abiItem.inputs);
|
|
144
|
+
callData = encodeFunctionData({
|
|
145
|
+
abi: [abiItem],
|
|
146
|
+
functionName: abiItem.name,
|
|
147
|
+
args: convertedArgs,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const gasEstimate = await client.estimateGas({
|
|
151
|
+
to: args.to ? args.to : undefined,
|
|
152
|
+
account: args.from ? args.from : undefined,
|
|
153
|
+
value: args.value ? BigInt(args.value) : undefined,
|
|
154
|
+
data: callData,
|
|
155
|
+
});
|
|
156
|
+
return formatResponse({
|
|
157
|
+
success: true,
|
|
158
|
+
chain: args.chain,
|
|
159
|
+
gasEstimate: gasEstimate.toString(),
|
|
160
|
+
to: args.to,
|
|
161
|
+
from: args.from,
|
|
162
|
+
value: args.value,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
throw new Error(`Gas estimation failed: ${error}`);
|
|
167
|
+
}
|
|
168
|
+
}),
|
|
169
|
+
get_gas_price: createTool("Get Gas Price", "Get current gas prices for a chain. Returns both legacy gasPrice and EIP-1559 fees (maxFeePerGas, maxPriorityFeePerGas).", z.object({
|
|
170
|
+
chain: z
|
|
171
|
+
.enum(SUPPORTED_CHAINS)
|
|
172
|
+
.describe("Blockchain network"),
|
|
173
|
+
formatted: z
|
|
174
|
+
.boolean()
|
|
175
|
+
.optional()
|
|
176
|
+
.default(true)
|
|
177
|
+
.describe("Return prices in Gwei (default: true). If false, returns wei."),
|
|
178
|
+
}), async (args) => {
|
|
179
|
+
const clientManager = getClientManager();
|
|
180
|
+
const client = clientManager.getClient(args.chain);
|
|
181
|
+
try {
|
|
182
|
+
// Get both legacy and EIP-1559 gas prices
|
|
183
|
+
const [gasPrice, feeData] = await Promise.all([
|
|
184
|
+
client.getGasPrice(),
|
|
185
|
+
client.estimateFeesPerGas().catch(() => null), // Some chains don't support EIP-1559
|
|
186
|
+
]);
|
|
187
|
+
const formatPrice = (wei) => {
|
|
188
|
+
if (args.formatted) {
|
|
189
|
+
// Convert to Gwei (1 Gwei = 1e9 wei)
|
|
190
|
+
const gwei = Number(wei) / 1e9;
|
|
191
|
+
return `${gwei.toFixed(2)} Gwei`;
|
|
192
|
+
}
|
|
193
|
+
return wei.toString();
|
|
194
|
+
};
|
|
195
|
+
const response = {
|
|
196
|
+
chain: args.chain,
|
|
197
|
+
timestamp: new Date().toISOString(),
|
|
198
|
+
legacy: {
|
|
199
|
+
gasPrice: args.formatted ? formatPrice(gasPrice) : gasPrice.toString(),
|
|
200
|
+
gasPriceWei: gasPrice.toString(),
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
// Add EIP-1559 data if available
|
|
204
|
+
if (feeData) {
|
|
205
|
+
response.eip1559 = {
|
|
206
|
+
maxFeePerGas: args.formatted
|
|
207
|
+
? formatPrice(feeData.maxFeePerGas)
|
|
208
|
+
: feeData.maxFeePerGas.toString(),
|
|
209
|
+
maxPriorityFeePerGas: args.formatted
|
|
210
|
+
? formatPrice(feeData.maxPriorityFeePerGas)
|
|
211
|
+
: feeData.maxPriorityFeePerGas.toString(),
|
|
212
|
+
maxFeePerGasWei: feeData.maxFeePerGas.toString(),
|
|
213
|
+
maxPriorityFeePerGasWei: feeData.maxPriorityFeePerGas.toString(),
|
|
214
|
+
};
|
|
215
|
+
// Calculate estimated total cost for a standard 21000 gas transaction
|
|
216
|
+
const standardGasLimit = 21000n;
|
|
217
|
+
const estimatedCost = feeData.maxFeePerGas * standardGasLimit;
|
|
218
|
+
response.eip1559.estimatedCostFor21kGas = args.formatted
|
|
219
|
+
? `${(Number(estimatedCost) / 1e18).toFixed(6)} ETH`
|
|
220
|
+
: estimatedCost.toString();
|
|
221
|
+
}
|
|
222
|
+
return formatResponse(response);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
throw new Error(`Failed to get gas price: ${error}`);
|
|
226
|
+
}
|
|
227
|
+
}),
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=gas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/tools/gas.ts"],"names":[],"mappings":"AAAA,OAAO,E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BAChD,uBAAuB,EAAE,OAAO,CAAC,oBAAoB,CAAC,QAAQ,EAAE;iBACjE,CAAC;gBAEF,sEAAsE;gBACtE,MAAM,gBAAgB,GAAG,MAAM,CAAC;gBAChC,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC;gBAC9D,QAAQ,CAAC,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,SAAS;oBACtD,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;oBACpD,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC/B,CAAC;YAED,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC,CACF;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AA0BnE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,QAcjD"}
|
package/dist/tools/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import balanceTools from './balance.js';
|
|
|
3
3
|
import contractTools from './contract.js';
|
|
4
4
|
import contractInfoTools from './contract-info.js';
|
|
5
5
|
import ensTools from './ens.js';
|
|
6
|
+
import gasTools from './gas.js';
|
|
6
7
|
import logTools from './logs.js';
|
|
7
8
|
import signatureTools from './signatures.js';
|
|
9
|
+
import transactionTools from './transactions.js';
|
|
8
10
|
const allToolDefinitions = {
|
|
9
11
|
...signatureTools,
|
|
10
12
|
...contractTools,
|
|
@@ -12,7 +14,9 @@ const allToolDefinitions = {
|
|
|
12
14
|
...balanceTools,
|
|
13
15
|
...logTools,
|
|
14
16
|
...advancedTools,
|
|
15
|
-
...ensTools
|
|
17
|
+
...ensTools,
|
|
18
|
+
...gasTools,
|
|
19
|
+
...transactionTools
|
|
16
20
|
};
|
|
17
21
|
// Register all tools with the MCP server
|
|
18
22
|
export function registerAllTools(server) {
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,eAAe,CAAA;AACzC,OAAO,YAAY,MAAM,cAAc,CAAA;AACvC,OAAO,aAAa,MAAM,eAAe,CAAA;AACzC,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,cAAc,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,eAAe,CAAA;AACzC,OAAO,YAAY,MAAM,cAAc,CAAA;AACvC,OAAO,aAAa,MAAM,eAAe,CAAA;AACzC,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,cAAc,MAAM,iBAAiB,CAAA;AAC5C,OAAO,gBAAgB,MAAM,mBAAmB,CAAA;AAEhD,MAAM,kBAAkB,GAAG;IACzB,GAAG,cAAc;IACjB,GAAG,aAAa;IAChB,GAAG,iBAAiB;IACpB,GAAG,YAAY;IACf,GAAG,QAAQ;IACX,GAAG,aAAa;IAChB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,gBAAgB;CACX,CAAA;AAEV,yCAAyC;AACzC,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QAC1D,MAAM,CAAC,YAAY,CACjB,IAAI,EACJ;YACE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;SAC/B,EACD,KAAK,EAAE,IAAS,EAAE,MAA8D,EAAE,EAAE;YAClF,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjC,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -78,6 +78,24 @@ declare const _default: {
|
|
|
78
78
|
}[];
|
|
79
79
|
}) => Promise<import("../types.js").ToolResult>;
|
|
80
80
|
};
|
|
81
|
+
encode_function_data: {
|
|
82
|
+
title: string;
|
|
83
|
+
description: string;
|
|
84
|
+
schema: z.ZodObject<{
|
|
85
|
+
functionAbi: z.ZodString;
|
|
86
|
+
args: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
args: (string | number | boolean)[];
|
|
89
|
+
functionAbi: string;
|
|
90
|
+
}, {
|
|
91
|
+
args: (string | number | boolean)[];
|
|
92
|
+
functionAbi: string;
|
|
93
|
+
}>;
|
|
94
|
+
handler: (args: {
|
|
95
|
+
args: (string | number | boolean)[];
|
|
96
|
+
functionAbi: string;
|
|
97
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
98
|
+
};
|
|
81
99
|
};
|
|
82
100
|
export default _default;
|
|
83
101
|
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBvB,wBA+HC"}
|
package/dist/tools/signatures.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keccak256, parseAbiItem, toBytes, toEventSignature, toFunctionSignature } from 'viem';
|
|
1
|
+
import { keccak256, parseAbiItem, toBytes, toEventSignature, toFunctionSignature, encodeFunctionData } from 'viem';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { createTool, formatResponse } from '../utils.js';
|
|
4
4
|
const FunctionAbiSchema = z.object({
|
|
@@ -88,6 +88,31 @@ export default {
|
|
|
88
88
|
catch (error) {
|
|
89
89
|
throw new Error(`Failed to parse error ABI: ${error}`);
|
|
90
90
|
}
|
|
91
|
+
}),
|
|
92
|
+
encode_function_data: createTool('Encode Function Call Data', 'Encode a function call with parameters into transaction data. Use this before calling call_contract_write.', z.object({
|
|
93
|
+
functionAbi: z.string().describe('Function ABI definition (e.g., "function transfer(address to, uint256 amount)")'),
|
|
94
|
+
args: z.array(z.union([z.string(), z.number(), z.boolean()])).describe('Function arguments in order matching the ABI signature. Automatically type-converted.')
|
|
95
|
+
}), async (args) => {
|
|
96
|
+
try {
|
|
97
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
98
|
+
// Encode the function data
|
|
99
|
+
const data = encodeFunctionData({
|
|
100
|
+
abi: [abiItem],
|
|
101
|
+
functionName: abiItem.name,
|
|
102
|
+
args: args.args
|
|
103
|
+
});
|
|
104
|
+
return formatResponse({
|
|
105
|
+
data,
|
|
106
|
+
functionName: abiItem.name,
|
|
107
|
+
functionSignature: toFunctionSignature(abiItem),
|
|
108
|
+
selector: data.slice(0, 10),
|
|
109
|
+
encodedArgs: data.slice(10),
|
|
110
|
+
message: 'Function data encoded successfully. Use this data with call_contract_write tool.'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw new Error(`Failed to encode function data: ${error}`);
|
|
115
|
+
}
|
|
91
116
|
})
|
|
92
117
|
};
|
|
93
118
|
//# sourceMappingURL=signatures.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iFAAiF,CAAC;CACpH,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,QAAQ,CAAC,wGAAwG,CAAC;CACtH,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,CAAC;SACR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