A Model Context Protocol (MCP) server that provides AI assistants with access to cast tools from the Foundry toolkit.
Cast is a powerful command-line tool for interacting with Ethereum blockchain networks. This MCP server exposes cast's functionality as callable tools that can be used by AI models through the MCP protocol.
chain: Get the symbolic name of the current chainchain_id: Get the chain ID of the current chainclient: Get the current client versionage: Get the timestamp of a block
block: Get detailed information about a blockblock_number: Get the block number of a specific block or the latest blockage: Get the timestamp of a blockgas_price: Get the current gas price
balance: Get the balance of an account in wei or ethernonce: Get the nonce of an accountcode: Get the bytecode of a contract (with optional disassembly)code_size: Get the size of contract bytecode in bytesstorage: Get the storage value at a specific slot
max_int: Get maximum value for signed integer types (int8, int16, int32, int64, int256)min_int: Get minimum value for signed integer types (int8, int16, int32, int64, int256)max_uint: Get maximum value for unsigned integer types (uint8, uint16, uint32, uint64, uint256)address_zero: Get the zero Ethereum address (0x0000000000000000000000000000000000000000)hash_zero: Get the zero hash (0x0000000000000000000000000000000000000000000000000000000000000000)
- Rust 1.91.0 (managed automatically via rust-toolchain.toml)
- AI client that supports MCP protocol (such as Claude Desktop, Cursor, or other MCP-compatible clients)
- Access to an Ethereum RPC endpoint (default: http://localhost:8545)
# Clone the repository
git clone <repository-url>
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-serverThe server supports the following environment variable configurations:
# 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:8545Configure this server in an MCP-enabled AI client:
Add to your Claude desktop configuration file:
{
"mcpServers": {
"cast-mcp-server": {
"command": "/path/to/cast-mcp-server/target/release/cast-mcp-server",
"args": []
}
}
}For other MCP-compatible clients, configure the server with:
- Command: Path to the compiled binary
- Arguments: None required (empty array)
- Working Directory: Project root directory
Here are examples of how to use the available tools:
{
"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"
}
}All tools support the following common parameters:
- rpc: Ethereum RPC endpoint URL (default: http://localhost:8545)
- block: Block identifier (number, hash, or tags like "latest", "finalized", "safe", "earliest", "pending")
# 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 warningsmake 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_testContributions are welcome! Here's how you can help:
- Fork this repository
- Clone your fork:
git clone https://github.com/your-username/cast-mcp-server.git - Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Format your code:
make fmt - Test your changes:
cargo test - Commit your changes:
git commit -am 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style (enforced by rustfmt)
- Add tests for new functionality
- Update documentation as needed
- Ensure all tests pass before submitting PR
Please include:
- Clear description of the issue
- Steps to reproduce
- Expected vs actual behavior
- Environment information (OS, Rust version, etc.)
This project is licensed under the MIT License - see the LICENSE file for details.
- Foundry - Ethereum development toolkit
- MCP Specification - Model Context Protocol
- Rust - Systems programming language