A Model Context Protocol (MCP) server that provides comprehensive access to the Etherscan API V2. This server exposes 65+ tools covering all major Etherscan API endpoints including accounts, blocks, contracts, gas tracking, tokens, logs, statistics, and Ethereum JSON-RPC proxy methods.
- Complete API Coverage: Access to all Etherscan V2 API endpoints
- Multi-Chain Support: Works with 60+ EVM-compatible chains via chain ID parameter
- HTTP Transport: RESTful HTTP API with Server-Sent Events (SSE) for MCP protocol
- CORS Enabled: Cross-origin requests supported out of the box
- MCP Protocol: Standard MCP server implementation for seamless integration
- TypeScript: Fully typed for better development experience
- Error Handling: Comprehensive error handling with descriptive messages
- Organized Structure: Clean separation of tools, handlers, and utilities
- Native token balances (single and multi-address)
- Historical balance queries
- Transaction lists (normal, internal, token transfers)
- ERC-20, ERC-721, ERC-1155 token transfers
- Mined blocks
- Beacon chain withdrawals
- Address funding source
- Block and uncle rewards
- Block countdown estimates
- Block number by timestamp
- Daily block statistics (size, count, rewards, time)
- Contract ABI retrieval
- Source code access
- Contract creator information
- Gas price oracle (safe, propose, fast)
- Confirmation time estimates
- Daily gas statistics (limit, usage, price)
- Token supply and balances
- Historical token data
- Token holder lists and rankings
- Token metadata and info
- NFT inventory tracking
- Event log filtering by address, topics, and block range
- ETH supply and price
- Network statistics
- Daily metrics (transactions, fees, addresses)
- Hash rate and difficulty
- Node counts and blockchain size
- Complete Ethereum JSON-RPC support
- Block and transaction queries
- Contract calls and code retrieval
- Gas estimation
- Raw transaction broadcasting
-
Clone or download this repository
-
Install dependencies:
npm install- Create a
.envfile based on.env.example:
cp .env.example .env- Add your Etherscan API key to
.env:
ETHERSCAN_API_KEY=your_api_key_here
Get your API key from: https://etherscan.io/myapikey
npm run buildnpm run devnpm startThe server will start on http://localhost:3000 by default.
Once running, the server exposes these endpoints:
GET /health- Health check endpoint, returns server status and tool countPOST /mcp- Initialize MCP session and send JSON-RPC requestsGET /mcp- Establish SSE stream for an existing sessionDELETE /mcp- Terminate an MCP session
curl http://localhost:3000/health
# Response: {"status":"ok","tools":65,"transport":"streamable-http","protocol":"MCP","sessions":0}- Initialize Session - POST to
/mcpwithout session ID - Get Session ID - Receive
mcp-session-idheader in response - Send Requests - POST to
/mcpwith session ID header - Stream Events - GET
/mcpwith session ID for SSE notifications - Terminate - DELETE
/mcpwith session ID when done
Edit .env to configure the server:
ETHERSCAN_API_KEY: Your Etherscan API key (required)DEFAULT_CHAIN_ID: Default chain ID (default: 1 for Ethereum mainnet)PORT: Server port (default: 3000)HOST: Server host (default: localhost)
CORS is enabled by default with origin: '*' for development. For production:
- Edit
src/server.ts - Change the CORS configuration:
app.use(cors({
origin: 'https://your-domain.com', // Specific origin
methods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Accept', 'mcp-session-id'],
exposedHeaders: ['mcp-session-id'],
credentials: true // If using cookies/auth
}));The server supports 60+ chains. Common chain IDs:
1: Ethereum Mainnet5: Goerli Testnet11155111: Sepolia Testnet56: BNB Smart Chain137: Polygon42161: Arbitrum One10: Optimism8453: Base43114: Avalanche C-Chain
This server implements the Model Context Protocol over HTTP using the modern StreamableHTTP transport (current MCP protocol). It provides session-based communication with SSE streaming support.
MCP clients should follow this flow:
# 1. Initialize session
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{...}}'
# 2. Extract mcp-session-id from response headers
# 3. Send requests with session ID
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "mcp-session-id: YOUR_SESSION_ID" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'All tools follow the naming pattern etherscan_<category>_<action>.
{
"name": "etherscan_account_balance",
"arguments": {
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"chainid": "1"
}
}{
"name": "etherscan_gas_oracle",
"arguments": {
"chainid": "1"
}
}{
"name": "etherscan_contract_abi",
"arguments": {
"address": "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
"chainid": "1"
}
}{
"name": "etherscan_proxy_get_transaction_receipt",
"arguments": {
"txhash": "0x...",
"chainid": "1"
}
}etherscan_mcp/
├── src/
│ ├── index.ts # Entry point
│ ├── server.ts # MCP server implementation
│ ├── config.ts # Configuration management
│ ├── types/ # TypeScript type definitions
│ │ ├── index.ts
│ │ └── etherscan.ts
│ ├── tools/ # MCP tool definitions
│ │ ├── account.ts
│ │ ├── block.ts
│ │ ├── contract.ts
│ │ ├── gas.ts
│ │ ├── token.ts
│ │ ├── logs.ts
│ │ ├── stats.ts
│ │ └── proxy.ts
│ ├── handlers/ # Tool execution handlers
│ │ ├── account.ts
│ │ ├── block.ts
│ │ ├── contract.ts
│ │ ├── gas.ts
│ │ ├── token.ts
│ │ ├── logs.ts
│ │ ├── stats.ts
│ │ └── proxy.ts
│ └── utils/
│ ├── api.ts # Etherscan API client
│ └── schemas.ts # Zod validation schemas
├── package.json
├── tsconfig.json
├── .env.example
└── README.md
Etherscan API has rate limits based on your plan:
- Free: 5 calls/second
- Standard: 10 calls/second
- Advanced: 15 calls/second
- Professional: 20 calls/second
The server does not implement rate limiting - ensure your client respects these limits.
The server provides detailed error messages:
- Missing API key
- Invalid parameters
- Etherscan API errors
- Network errors
Errors are returned in MCP error format with appropriate error codes.
- Define the tool in the appropriate
src/tools/*.tsfile - Add the handler logic in the corresponding
src/handlers/*.tsfile - Create Zod schemas in
src/utils/schemas.tsif needed - The server will automatically register and route the new tool
MIT
Contributions are welcome! Please ensure:
- TypeScript types are properly defined
- Error handling is comprehensive
- Tool names follow the
etherscan_<category>_<action>pattern - Documentation is updated for new features