cymqqqq/eth_mcp_server
If you are the rightful owner of eth_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Rust-based Model Context Protocol (MCP) server that lets AI agents query balances, token prices, and simulate token swaps on Ethereum.
Ethereum Trading MCP Server
A Rust-based Model Context Protocol (MCP) server that lets AI agents query balances, token prices, and simulate token swaps on Ethereum.
Overview
This project builds an MCP-compatible JSON-RPC server in Rust that exposes three main tools:
| Method | Description | Example |
|---|---|---|
get_balance | Query ETH or ERC20 token balance | {"wallet": "0x..."} |
get_token_price | Get token price in USD | {"symbol": "ETH"} |
swap_tokens | Simulate token swap on Uniswap V2 | {"from_token": "...", "to_token": "...", "amount": 1.0} |
Architecture
- MCP Server: Exposes JSON-RPC 2.0 endpoints.
- Ethereum RPC: Fetches on-chain data via
ethers-rs. - Uniswap Simulation: Uses
eth_callto simulate swaps.
Requirements
- Rust 1.75+
- Infura or Alchemy API key
- macOS
⚙️ Setup
Clone the repo
git clone https://github.com/cymqqqq/eth_mcp_server.git
cd eth_mcp_server
Get ETH Balance
curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"get_balance","params":{"wallet":"0x742d35Cc6634C0532925a3b844Bc454e4438f44e"},"id":1}'
Get ERC20 Balance
curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"get_balance","params":{"wallet":"0x742d35Cc6634C0532925a3b844Bc454e4438f44e","token":"0xdAC17F958D2ee523a2206206994597C13D831ec7"},"id":2}'
Simulate Uniswap Swap
curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"swap_tokens","params":{"from_token":"0xC02aaA39b223FE8D0A0E5C4F27eAD9083C756Cc2","to_token":"0xdAC17F958D2ee523a2206206994597C13D831ec7","amount":0.1,"slippage":0.5},"id":3}'
Test
cargo test
Design Decisions
Rust + ethers-rs for async Ethereum access.
JSON-RPC 2.0 for easy AI agent integration.
Uniswap Router V2 used for swap simulation.
eth_call simulation ensures zero gas cost and safety.
Structured logging via tracing.
Fold Structure
src/
├─ main.rs # Entry point
├─ rpc.rs # JSON-RPC handler
├─ eth_client.rs # Ethereum balance & price queries
├─ uniswap.rs # Swap simulation
└─ abi/ # ERC20 & Router ABIs
tests/
└─ integration.rs # Full end-to-end tests
Known Limitations
get_token_price uses static data (mocked).
Swap simulation uses Uniswap V2 only.
No persistent wallet or private key storage (only env variable).
Future Improvements
Integrate Uniswap V3 Router.
Add Chainlink Oracle for real-time USD prices.
Add structured error handling & logging with anyhow.
Register as a true MCP tool for AI frameworks.
Compile ethers-contracts waste too much time.
Now I'm testing it.