web3-tools-mcp 1.0.0 → 1.1.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/README.md +92 -259
- package/dist/client.d.ts +1653 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +142 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -28274
- package/dist/index.js.map +1 -0
- package/dist/package.json +60 -0
- package/dist/src/client.d.ts +1653 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +142 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +88 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/tools/advanced.d.ts +75 -0
- package/dist/src/tools/advanced.d.ts.map +1 -0
- package/dist/src/tools/advanced.js +234 -0
- package/dist/src/tools/advanced.js.map +1 -0
- package/dist/src/tools/balance.d.ts +55 -0
- package/dist/src/tools/balance.d.ts.map +1 -0
- package/dist/src/tools/balance.js +146 -0
- package/dist/src/tools/balance.js.map +1 -0
- package/dist/src/tools/contract-info.d.ts +79 -0
- package/dist/src/tools/contract-info.d.ts.map +1 -0
- package/dist/src/tools/contract-info.js +450 -0
- package/dist/src/tools/contract-info.js.map +1 -0
- package/dist/src/tools/contract.d.ts +79 -0
- package/dist/src/tools/contract.d.ts.map +1 -0
- package/dist/src/tools/contract.js +140 -0
- package/dist/src/tools/contract.js.map +1 -0
- package/dist/src/tools/index.d.ts +3 -0
- package/dist/src/tools/index.d.ts.map +1 -0
- package/dist/src/tools/index.js +27 -0
- package/dist/src/tools/index.js.map +1 -0
- package/dist/src/tools/logs.d.ts +39 -0
- package/dist/src/tools/logs.d.ts.map +1 -0
- package/dist/src/tools/logs.js +231 -0
- package/dist/src/tools/logs.js.map +1 -0
- package/dist/src/tools/signatures.d.ts +83 -0
- package/dist/src/tools/signatures.d.ts.map +1 -0
- package/dist/src/tools/signatures.js +93 -0
- package/dist/src/tools/signatures.js.map +1 -0
- package/dist/src/types.d.ts +22 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +22 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +183 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/mcp-client.test.d.ts +2 -0
- package/dist/test/mcp-client.test.d.ts.map +1 -0
- package/dist/test/mcp-client.test.js +376 -0
- package/dist/test/mcp-client.test.js.map +1 -0
- package/dist/test/tools/advanced.test.d.ts +2 -0
- package/dist/test/tools/advanced.test.d.ts.map +1 -0
- package/dist/test/tools/advanced.test.js +235 -0
- package/dist/test/tools/advanced.test.js.map +1 -0
- package/dist/test/tools/balance.test.d.ts +2 -0
- package/dist/test/tools/balance.test.d.ts.map +1 -0
- package/dist/test/tools/balance.test.js +167 -0
- package/dist/test/tools/balance.test.js.map +1 -0
- package/dist/test/tools/contract-info.test.d.ts +2 -0
- package/dist/test/tools/contract-info.test.d.ts.map +1 -0
- package/dist/test/tools/contract-info.test.js +286 -0
- package/dist/test/tools/contract-info.test.js.map +1 -0
- package/dist/test/tools/contract.test.d.ts +2 -0
- package/dist/test/tools/contract.test.d.ts.map +1 -0
- package/dist/test/tools/contract.test.js +234 -0
- package/dist/test/tools/contract.test.js.map +1 -0
- package/dist/test/tools/logs.test.d.ts +2 -0
- package/dist/test/tools/logs.test.d.ts.map +1 -0
- package/dist/test/tools/logs.test.js +196 -0
- package/dist/test/tools/logs.test.js.map +1 -0
- package/dist/test/tools/signatures.test.d.ts +2 -0
- package/dist/test/tools/signatures.test.d.ts.map +1 -0
- package/dist/test/tools/signatures.test.js +112 -0
- package/dist/test/tools/signatures.test.js.map +1 -0
- package/dist/tools/advanced.d.ts +75 -0
- package/dist/tools/advanced.d.ts.map +1 -0
- package/dist/tools/advanced.js +234 -0
- package/dist/tools/advanced.js.map +1 -0
- package/dist/tools/balance.d.ts +55 -0
- package/dist/tools/balance.d.ts.map +1 -0
- package/dist/tools/balance.js +146 -0
- package/dist/tools/balance.js.map +1 -0
- package/dist/tools/batch.d.ts +122 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +243 -0
- package/dist/tools/batch.js.map +1 -0
- package/dist/tools/contract-info.d.ts +79 -0
- package/dist/tools/contract-info.d.ts.map +1 -0
- package/dist/tools/contract-info.js +450 -0
- package/dist/tools/contract-info.js.map +1 -0
- package/dist/tools/contract.d.ts +79 -0
- package/dist/tools/contract.d.ts.map +1 -0
- package/dist/tools/contract.js +140 -0
- package/dist/tools/contract.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +27 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/logs.d.ts +39 -0
- package/dist/tools/logs.d.ts.map +1 -0
- package/dist/tools/logs.js +231 -0
- package/dist/tools/logs.js.map +1 -0
- package/dist/tools/signatures.d.ts +83 -0
- package/dist/tools/signatures.d.ts.map +1 -0
- package/dist/tools/signatures.js +93 -0
- package/dist/tools/signatures.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +183 -0
- package/dist/utils.js.map +1 -0
- package/package.json +35 -23
- package/src/client.ts +160 -0
- package/src/index.ts +96 -0
- package/src/tools/advanced.ts +262 -0
- package/src/tools/balance.ts +176 -0
- package/src/tools/contract-info.ts +582 -0
- package/src/tools/contract.ts +180 -0
- package/src/tools/index.ts +35 -0
- package/src/tools/logs.ts +291 -0
- package/src/tools/signatures.ts +126 -0
- package/src/types.ts +29 -0
- package/src/utils.ts +222 -0
- package/dist/hypersync-client.darwin-arm64-7fegfwn5.node +0 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { AbiParameter } from 'viem'
|
|
2
|
+
import type { ToolResult } from './types.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
// Create tool helper
|
|
6
|
+
export function createTool<T extends z.ZodType>(
|
|
7
|
+
title: string,
|
|
8
|
+
description: string,
|
|
9
|
+
schema: T,
|
|
10
|
+
handler: (args: z.infer<T>) => Promise<ToolResult>
|
|
11
|
+
) {
|
|
12
|
+
return {
|
|
13
|
+
title,
|
|
14
|
+
description,
|
|
15
|
+
schema,
|
|
16
|
+
handler
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Convert BigInt values to strings for JSON serialization
|
|
21
|
+
export function convertBigIntToString(obj: unknown): unknown {
|
|
22
|
+
if (typeof obj === 'bigint') {
|
|
23
|
+
return obj.toString()
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(obj)) {
|
|
26
|
+
return obj.map(item => convertBigIntToString(item))
|
|
27
|
+
}
|
|
28
|
+
if (obj && typeof obj === 'object') {
|
|
29
|
+
const converted: Record<string, unknown> = {}
|
|
30
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
31
|
+
converted[key] = convertBigIntToString(value)
|
|
32
|
+
}
|
|
33
|
+
return converted
|
|
34
|
+
}
|
|
35
|
+
return obj
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Convert arguments to appropriate types based on ABI
|
|
39
|
+
export function convertArgumentsToTypes(
|
|
40
|
+
args: (string | number | boolean | null)[],
|
|
41
|
+
abiInputs: readonly AbiParameter[]
|
|
42
|
+
): unknown[] {
|
|
43
|
+
return args.map((arg, index) => {
|
|
44
|
+
if (index >= abiInputs.length) {
|
|
45
|
+
throw new Error(`Too many arguments provided. Expected ${abiInputs.length}, got ${args.length}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const param = abiInputs[index]
|
|
49
|
+
if (!param?.type) {
|
|
50
|
+
throw new Error(`Missing type information for parameter at index ${index}`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const paramType = param.type
|
|
54
|
+
|
|
55
|
+
// Handle null values
|
|
56
|
+
if (arg === null) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Handle different parameter types
|
|
61
|
+
if (paramType === 'address') {
|
|
62
|
+
return String(arg)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (paramType === 'bool') {
|
|
66
|
+
if (typeof arg === 'boolean') return arg
|
|
67
|
+
if (typeof arg === 'string') return arg.toLowerCase() === 'true'
|
|
68
|
+
return Boolean(arg)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (paramType.startsWith('uint') || paramType.startsWith('int')) {
|
|
72
|
+
if (typeof arg === 'number') return BigInt(arg)
|
|
73
|
+
if (typeof arg === 'string') return BigInt(arg)
|
|
74
|
+
throw new Error(`Invalid type for ${paramType}: ${typeof arg}`)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (paramType === 'string') {
|
|
78
|
+
return String(arg)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (paramType === 'bytes' || paramType.startsWith('bytes')) {
|
|
82
|
+
return String(arg)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// For other types, try to convert appropriately
|
|
86
|
+
if (typeof arg === 'string' && arg.startsWith('0x')) {
|
|
87
|
+
return arg // Assume it's already properly formatted
|
|
88
|
+
}
|
|
89
|
+
return arg
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Convert event arguments to appropriate types
|
|
94
|
+
export function convertEventArgsToTypes(
|
|
95
|
+
eventArgs: Record<string, unknown>,
|
|
96
|
+
abiInputs: readonly AbiParameter[]
|
|
97
|
+
): Record<string, unknown> {
|
|
98
|
+
const converted: Record<string, unknown> = {}
|
|
99
|
+
|
|
100
|
+
for (const [argName, argValue] of Object.entries(eventArgs)) {
|
|
101
|
+
// Find the parameter definition for this argument name
|
|
102
|
+
const param = abiInputs.find(input => input.name === argName)
|
|
103
|
+
|
|
104
|
+
if (!param) {
|
|
105
|
+
throw new Error(`Parameter '${argName}' not found in event ABI`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!param.type) {
|
|
109
|
+
throw new Error(`Missing type information for parameter '${argName}'`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const paramType = param.type
|
|
113
|
+
|
|
114
|
+
// Handle null/undefined values
|
|
115
|
+
if (argValue === null || argValue === undefined) {
|
|
116
|
+
converted[argName] = null
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Handle different parameter types
|
|
121
|
+
if (paramType === 'address') {
|
|
122
|
+
converted[argName] = String(argValue)
|
|
123
|
+
} else if (paramType === 'bool') {
|
|
124
|
+
if (typeof argValue === 'boolean') {
|
|
125
|
+
converted[argName] = argValue
|
|
126
|
+
} else if (typeof argValue === 'string') {
|
|
127
|
+
converted[argName] = argValue.toLowerCase() === 'true'
|
|
128
|
+
} else {
|
|
129
|
+
converted[argName] = Boolean(argValue)
|
|
130
|
+
}
|
|
131
|
+
} else if (paramType.startsWith('uint') || paramType.startsWith('int')) {
|
|
132
|
+
if (typeof argValue === 'number') {
|
|
133
|
+
converted[argName] = BigInt(argValue)
|
|
134
|
+
} else if (typeof argValue === 'string') {
|
|
135
|
+
converted[argName] = BigInt(argValue)
|
|
136
|
+
} else {
|
|
137
|
+
throw new Error(`Invalid type for ${paramType}: ${typeof argValue}`)
|
|
138
|
+
}
|
|
139
|
+
} else if (paramType === 'string') {
|
|
140
|
+
converted[argName] = String(argValue)
|
|
141
|
+
} else if (paramType === 'bytes' || paramType.startsWith('bytes')) {
|
|
142
|
+
converted[argName] = String(argValue)
|
|
143
|
+
} else {
|
|
144
|
+
// For other types, handle arrays and try to convert appropriately
|
|
145
|
+
if (Array.isArray(argValue)) {
|
|
146
|
+
converted[argName] = argValue
|
|
147
|
+
} else if (typeof argValue === 'string' && argValue.startsWith('0x')) {
|
|
148
|
+
converted[argName] = argValue // Assume it's already properly formatted
|
|
149
|
+
} else {
|
|
150
|
+
converted[argName] = argValue
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return converted
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Format response as tool result
|
|
159
|
+
export function formatResponse(data: unknown): ToolResult {
|
|
160
|
+
const serializable = convertBigIntToString(data)
|
|
161
|
+
return {
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: 'text',
|
|
165
|
+
text: JSON.stringify(serializable, null, 2)
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Parse command line arguments
|
|
172
|
+
export function parseCommandLineArgs(): {
|
|
173
|
+
etherscanApiKey?: string
|
|
174
|
+
alchemyApiKey?: string
|
|
175
|
+
infuraApiKey?: string
|
|
176
|
+
customRpcUrls?: Record<string, string>
|
|
177
|
+
hypersyncApiKey?: string
|
|
178
|
+
showHelp?: boolean
|
|
179
|
+
} {
|
|
180
|
+
const config: {
|
|
181
|
+
etherscanApiKey?: string
|
|
182
|
+
alchemyApiKey?: string
|
|
183
|
+
infuraApiKey?: string
|
|
184
|
+
customRpcUrls?: Record<string, string>
|
|
185
|
+
hypersyncApiKey?: string
|
|
186
|
+
showHelp?: boolean
|
|
187
|
+
} = {}
|
|
188
|
+
|
|
189
|
+
function getArgValue(argName: string): string | undefined {
|
|
190
|
+
const args = process.argv
|
|
191
|
+
const index = args.findIndex(arg => arg === argName)
|
|
192
|
+
return index !== -1 && index + 1 < args.length ? args[index + 1] : undefined
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function hasArg(argName: string): boolean {
|
|
196
|
+
return process.argv.includes(argName)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Check for help flag
|
|
200
|
+
if (hasArg('--help') || hasArg('-h')) {
|
|
201
|
+
config.showHelp = true
|
|
202
|
+
return config
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Parse environment variables and command line arguments
|
|
206
|
+
config.etherscanApiKey = process.env.ETHERSCAN_API_KEY || getArgValue('--etherscan-api-key')
|
|
207
|
+
config.alchemyApiKey = process.env.ALCHEMY_API_KEY || getArgValue('--alchemy-api-key')
|
|
208
|
+
config.infuraApiKey = process.env.INFURA_API_KEY || getArgValue('--infura-api-key')
|
|
209
|
+
config.hypersyncApiKey = process.env.HYPERSYNC_API_KEY || getArgValue('--hypersync-api-key')
|
|
210
|
+
|
|
211
|
+
// Parse custom RPC URLs
|
|
212
|
+
const customRpcs = getArgValue('--custom-rpc')
|
|
213
|
+
if (customRpcs) {
|
|
214
|
+
try {
|
|
215
|
+
config.customRpcUrls = JSON.parse(customRpcs)
|
|
216
|
+
} catch {
|
|
217
|
+
console.error('Invalid JSON for --custom-rpc:', customRpcs)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return config
|
|
222
|
+
}
|
|
Binary file
|