Geth MCP服务器
用于与Geth区块链节点交互的模型上下文协议(MCP)服务器。这是一个纯MCP服务器,通过stdio传输进行通信,不需要任何端口侦听器。
特性
- 10个MCP工具:全面的区块链交互工具
- 纯MCP服务器:通过stdio传输运行(无HTTP服务器或端口)
- Web3集成:直接连接到本地Geth节点
http://localhost:8545 - BigInt支持:正确处理具有BigInt值的区块链数据
- 全面的错误处理:对所有区块链操作进行稳健的错误处理
可用的MCP工具
- get_block_info:通过数字或哈希获取特定块的详细信息
- get_count_balance:检查以太坊账户的余额
- get_transaction_info:获取全面的交易详细信息
- get_latest_block:获取有关最新块的信息
- get_network_info:获取网络状态和节点信息
- get_gas_price:查看当前的天然气价格
- get_storage_at:从智能合约中的特定位置获取存储值
- get_logs:根据筛选条件获取事件日志
- get_code:获取特定地址的合约字节码
- 估计气体:通过成本计算估算交易所需的天然气
安装
选项1:从npm安装(推荐)
# Install globally
npm install -g geth-mcp-server
# Or install locally in your project
npm install geth-mcp-server选项2:从源代码构建
git clone https://github.com/your-username/geth-mcp-server.git
cd geth-mcp-server
npm install
npm run build用法
使用npm包
通过npm安装后,可以直接使用服务器:
# If installed globally
geth-mcp-server
# If installed locally
npx geth-mcp-server从源头使用
# Development mode
npm run dev
# Production mode
npm run build
npm startMCP配置
用于npm安装
在MCP客户端(如Claude Desktop)中使用此配置:
{
"mcpServers": {
"geth-mcp-server": {
"command": "npx",
"args": ["geth-mcp-server"],
"env": {
"GETH_URL": "http://localhost:8545"
}
}
}
}用于全局npm安装
{
"mcpServers": {
"geth-mcp-server": {
"command": "geth-mcp-server",
"args": [],
"env": {
"GETH_URL": "http://localhost:8545"
}
}
}
}用于源安装
{
"mcpServers": {
"geth-mcp-server": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/path/to/geth-mcp-server",
"env": {
"GETH_URL": "http://localhost:8545"
}
}
}
}配置
- 获取URL:
http://localhost:8545(通过配置GETH_URL环境变量) - 运输:仅限stdio(无HTTP服务器或端口)
MCP工具示例
获取最新区块
{
"tool": "get_latest_block",
"arguments": {}
}检查账户余额
{
"tool": "get_account_balance",
"arguments": {
"address": "0x742d35cc6Cc6ab4b3569bB50915BF3a3bF6dEc76"
}
}获取区块信息
{
"tool": "get_block_info",
"arguments": {
"blockIdentifier": "latest"
}
}获取合同存储
{
"tool": "get_storage_at",
"arguments": {
"address": "0x742d35cc6Cc6ab4b3569bB50915BF3a3bF6dEc76",
"position": "0x0"
}
}获取事件日志
{
"tool": "get_logs",
"arguments": {
"fromBlock": "latest",
"toBlock": "latest",
"address": "0x742d35cc6Cc6ab4b3569bB50915BF3a3bF6dEc76"
}
}估算天然气
{
"tool": "estimate_gas",
"arguments": {
"from": "0x742d35cc6Cc6ab4b3569bB50915BF3a3bF6dEc76",
"to": "0x742d35cc6Cc6ab4b3569bB50915BF3a3bF6dEc76",
"value": "1000000000000000000"
}
}工具详细信息
合同检验工具
- get_code:返回合约字节码,并指示地址是否为合约
- get_storage_at:读取智能合约中的特定存储插槽
- get_logs:使用灵活的条件筛选和检索事件日志
交易分析工具
- 估计气体:提供Wei、Gwei和ETH的天然气估算和成本计算
- get_transaction_info:包括收据信息在内的综合交易数据
区块链数据工具
- get_latest_block:当前块信息
- get_block_info:按数字或哈希的历史块数据
- get_count_balance:多个单位的账户余额
- get_network_info:网络状态和节点信息
- get_gas_price:当前天然气定价数据
错误处理
该服务器包括全面的错误处理功能,用于:
- 网络连接问题
- 区块链数据请求无效
- 刀具参数格式错误
- Web3提供程序错误
- BigInt序列化问题
快速入门指南
- 安装软件包:
npm install -g geth-mcp-server- 确保Geth正在运行:
# Start your local Geth node
geth --http --http.addr localhost --http.port 8545 --http.corsdomain "*" --http.api eth,net,web3- 配置您的MCP客户端 如上所示的配置
- 开始使用工具 通过您的MCP客户端
NPM包
- 包名:
geth-mcp-server - 版本: 1.0.0
- 注册表: https://www.npmjs.com/package/geth-mcp-server
- 尺寸:压缩7.7 kB,解压缩40.2 kB
需求
- Node.js 18+
- 访问正在运行的Geth节点(默认值:http://localhost:8545)
- 用于交互的MCP兼容客户端
许可证
麻省理工学院
