FM

foshougua/mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

0 stars 0 forks 质量 38 趋势 0

A Model Context Protocol (MCP) server implementation in Rust that enables AI agents to query Ethereum balances and simulate token swaps on Uniswap.

概览

A Model Context Protocol (MCP) server implementation in Rust that enables AI agents to query Ethereum balances and simulate token swaps on Uniswap. - - Query ETH and ERC20 token balances for any Ethereum address - - Get current token prices in USD or ETH from CoinGecko - - Simulate Uniswap V2/V3 token swaps without executing on-chain - Rust 1.70+ (with cargo) - Access to an Ethereum RPC endpoint (public endpoints or Infura/Alchemy) The .env file contains: - ETH_RPC_URL: Ethereum RPC endpoint (default: https://eth.llamarpc.com) - PORT: HTTP server port (default: 3000) - PRIVATE_KEY: Optional private key for wallet functionality (default: not set) : The .env file is already in .gitignore and will not be committed to version control. Never commit your private keys! The server starts an HTTP server on port 3000 (default). You can change the port by setting the PORT environment variable: The server provides an HTTP API that accepts JSON-RPC 2.0 requests.

README

以下为原文 README 节选,完整内容请查看原文。

Ethereum Trading MCP Server

A Model Context Protocol (MCP) server implementation in Rust that enables AI agents to query Ethereum balances and simulate token swaps on Uniswap.

Features

  • get_balance - Query ETH and ERC20 token balances for any Ethereum address
  • get_token_price - Get current token prices in USD or ETH from CoinGecko
  • swap_tokens - Simulate Uniswap V2/V3 token swaps without executing on-chain

Requirements

  • Rust 1.70+ (with cargo)
  • Access to an Ethereum RPC endpoint (public endpoints or Infura/Alchemy)

Setup

  1. Clone the repository:

    git clone 
    cd mpc
    
  2. Install dependencies:

    cargo build
    
  3. Set up environment variables:

    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env file if needed
    # The default ETH_RPC_URL is already set to https://eth.llamarpc.com
    # Optionally uncomment and set PRIVATE_KEY for wallet functionality
    

    The .env file contains:

    • ETH_RPC_URL: Ethereum RPC endpoint (default: https://eth.llamarpc.com)
    • PORT: HTTP server port (default: 3000)
    • PRIVATE_KEY: Optional private key for wallet functionality (default: not set)

    Note: The .env file is already in .gitignore and will not be committed to version control. Never commit your private keys!

  4. Build the project:

    cargo build --release
    
  5. Run the server:

    cargo run --release
    

    The server starts an HTTP server on port 3000 (default). You can change the port by setting the PORT environment variable:

    PORT=8080 cargo run --release
    

Usage

The server provides an HTTP API that accepts JSON-RPC 2.0 requests. By default, it runs on http://localhost:3000.

Start the Server

# Start server (default port 3000)
cargo run --release

# Or specify a custom port
PORT=8080 cargo run --release

The server will display:

MCP Server starting on http://0.0.0.0:3000
Health check available at http://0.0.0.0:3000/health

Quick Start - Command Line Testing

Method 1: Using curl

# Health check
curl http://localhost:3000/health

# Test get_balance
curl -X POST http://localhost:3000 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_balance","arguments":{"address":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"}}}'

Method 2: Using provided test scripts

# Run all example tests
./test_examples.sh

# Test a specific tool
./test_single.sh get_balance '{"address":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"}'
./test_single.sh get_token_price '{"token_symbol":"USDC"}'
./test_single.sh swap_tokens '{"from_token":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","to_token":"0xdAC17F958D2ee523a2206206994597C13D831ec7","amount":"100.0"}'

# Specify custom server URL
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →