强制MCP服务器
一种模型上下文协议(MCP)服务器,为AI助手提供访问 投射 Foundry工具包中的工具。
Cast是一个强大的命令行工具,用于与以太坊区块链网络进行交互。此MCP服务器将cast的功能作为可调用工具公开,AI模型可以通过MCP协议使用这些工具。
特性
链条工具
chain:获取当前链的符号名称chain_id:获取当前链的链IDclient:获取当前客户端版本age:获取块的时间戳
块工具
block:获取有关块的详细信息block_number:获取特定区块或最新区块的区块编号age:获取块的时间戳gas_price:获取当前的天然气价格
帐户工具
balance:在wei或ether中获取账户余额nonce:获取帐户的noncecode:获取合约的字节码(可选反汇编)code_size:获取合约字节码的大小(以字节为单位)storage:获取特定插槽的存储值
实用工具
max_int:获取有符号整数类型(int8、int16、int32、int64、int256)的最大值min_int:获取有符号整数类型(int8、int16、int32、int64、int256)的最小值max_uint:获取无符号整数类型(uint8、uint16、uint32、uint64、uint256)的最大值address_zero:获取零以太坊地址(0x0000000000000000000000000000000000)hash_zero:获取零哈希值(0x0000000000000000000000000000000000000000000000000000000000)
快速开始
先决条件
- Rust 1.91.0(通过Rust-toolchain.toml自动管理)
- 支持MCP协议的AI客户端(如Claude Desktop、Cursor或其他兼容MCP的客户端)
- 访问以太坊RPC端点(默认:http://localhost:8545)
安装
# Clone the repository
git clone
cd cast-mcp-server
# Build the project
make build
# Or use cargo directly
cargo build --release
# The executable will be located at:
# ./target/release/cast-mcp-server跑步
# Run in development mode
cargo run
# Run in production mode
./target/release/cast-mcp-server配置
环境变量
服务器支持以下环境变量配置:
# Set log level (options: trace, debug, info, warn, error)
# Default: debug
RUST_LOG=info
# Note: RPC endpoints are configured per-tool via parameters
# Default RPC endpoint: http://localhost:8545用法示例
在启用MCP的AI客户端中配置此服务器:
Claude桌面配置
添加到您的Claude桌面配置文件中:
{
"mcpServers": {
"cast-mcp-server": {
"command": "/path/to/cast-mcp-server/target/release/cast-mcp-server",
"args": []
}
}
}通用MCP客户端配置
对于其他MCP兼容客户端,请使用以下配置服务器:
- 命令:编译二进制文件的路径
- 参数:无需(空数组)
- 工作目录:项目根目录
工具使用示例
以下是如何使用可用工具的示例:
块工具
{
"name": "block",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"block": "latest",
"full": true,
"fields": ["number", "timestamp", "gasUsed"]
}
}{
"name": "block_number",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"block": "latest"
}
}{
"name": "age",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"block": "1000000"
}
}{
"name": "gas_price",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID"
}
}帐户工具
{
"name": "balance",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"who": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"ether": true
}
}{
"name": "nonce",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"who": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"block": "latest"
}
}{
"name": "code_size",
"arguments": {
"rpc": "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"block": "latest"
}
}所有工具都支持以下常见参数:
- rpc:以太坊RPC端点URL(默认值:http://localhost:8545)
- 块:块标识符(数字、哈希或“最新”、“已完成”、“安全”、“最早”、“待定”等标签)
发展
代码格式化
# Format code (requires nightly toolchain)
make fmt
# Or
cargo +nightly fmt掉毛
# Run clippy linter
cargo clippy
# Run clippy with all features and stricter warnings
cargo clippy --all-targets --all-features -- -D warnings清洁建筑
make clean
# Or
cargo clean测试
# Run all tests
cargo test
# Run tests with verbose output
cargo test -- --nocapture
# Run specific test modules
cargo test common::account_tools
cargo test common::block_tools
cargo test common::chain_tools
cargo test common::utility_tools
# Run integration tests (if available)
cargo test --test integration_test贡献
欢迎投稿!以下是您可以提供帮助的方式:
开发设置
- 分叉此存储库
- 克隆你的叉子:
git clone https://github.com/your-username/cast-mcp-server.git - 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改
- 设置代码格式:
make fmt - 测试您的更改:
cargo test - 提交您的更改:
git commit -am 'Add amazing feature' - 推到分支:
git push origin feature/amazing-feature - 打开拉取请求
代码规范
- 遵循现有的代码风格(由rustfmt强制执行)
- 添加新功能的测试
- 根据需要更新文档
- 在提交PR之前,确保所有测试都通过
报告问题
请包括:
- 对问题的清晰描述
- 重现步骤
- 预期行为与实际行为
- 环境信息(操作系统、Rust版本等)
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
