mohitJukariya/ArbitrumMCPserver
If you are the rightful owner of ArbitrumMCPserver and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Arbitrum MCP Server is a Model Context Protocol server built with NestJS, designed to facilitate interaction with the Arbitrum blockchain via HTTP transport.
getBalance
Get ETH balance for any address
getTransaction
Get transaction details by hash
getTransactionReceipt
Get transaction receipt by hash
getBlock
Get block information by number
getLatestBlock
Get latest block number
getTransactionHistory
Get transaction history for an address
getContractAbi
Get ABI for a contract address
getTokenBalance
Get token balance for an address
getGasPrice
Get current gas price
getEthSupply
Get total ETH supply on Arbitrum
validateAddress
Validate Ethereum address format
Arbitrum MCP Server
A Model Context Protocol (MCP) server built with NestJS that provides tools for interacting with the Arbitrum blockchain via HTTP transport.
Features
This MCP server provides the following tools:
- getBalance - Get ETH balance for any address
- getTransaction - Get transaction details by hash
- getTransactionReceipt - Get transaction receipt by hash
- getBlock - Get block information by number
- getLatestBlock - Get latest block number
- getTransactionHistory - Get transaction history for an address
- getContractAbi - Get ABI for a contract address
- getTokenBalance - Get token balance for an address
- getGasPrice - Get current gas price
- getEthSupply - Get total ETH supply on Arbitrum
- validateAddress - Validate Ethereum address format
Setup
Prerequisites
- Node.js (v18 or higher)
- npm or yarn
- Arbiscan API key (free from https://arbiscan.io/apis)
Installation
- Clone or download the project
cd arbitrumServer
- Install dependencies
npm install
- Create environment file
cp .env.example .env
- Add your Arbiscan API key to
.env
:
ARBISCAN_API_KEY=your_actual_api_key_here
PORT=4000
NODE_ENV=development
Running the Server
# Development mode with hot reload
npm run start:dev
# Production build
npm run build
npm run start:prod
The server will start on http://localhost:4000
API Endpoints
Health Check
GET /api/health
Returns server status and health information.
MCP Endpoint
POST /api/mcp
Main endpoint for all MCP protocol communication.
MCP Protocol Usage
All MCP requests follow the JSON-RPC 2.0 protocol format:
{
"jsonrpc": "2.0",
"id": <unique_id>,
"method": "<method_name>",
"params": <parameters>
}
Initialization
Before using tools, initialize the connection:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}
List Available Tools
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
Tool Usage Examples
1. Get Balance
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "getBalance",
"arguments": {
"address": "0x742d35Cc6634C0532925a3b8D7389F7Aa6b99D2b"
}
}
}
2. Get Latest Block
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "getLatestBlock",
"arguments": {}
}
}
3. Get Transaction History
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "getTransactionHistory",
"arguments": {
"address": "0x742d35Cc6634C0532925a3b8D7389F7Aa6b99D2b",
"page": "1",
"offset": "10"
}
}
}
4. Get Transaction Details
{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "getTransaction",
"arguments": {
"txHash": "0x1234567890abcdef..."
}
}
}
5. Get Gas Price
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "getGasPrice",
"arguments": {}
}
}
6. Validate Address
{
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "validateAddress",
"arguments": {
"address": "0x742d35Cc6634C0532925a3b8D7389F7Aa6b99D2b"
}
}
}
Testing
The project includes a test script to verify all endpoints:
node test-server.js
Or test individual endpoints using curl:
# Health check
curl http://localhost:4000/api/health
# List tools
curl -X POST http://localhost:4000/api/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
# Validate address
curl -X POST http://localhost:4000/api/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"validateAddress","arguments":{"address":"0x742d35Cc6634C0532925a3b8D7389F7Aa6b99D2b"}}}'
Client Integration
To integrate this MCP server with your client application:
- Start the server on your desired port
- Initialize the connection using the
/initialize
method - List available tools using
/tools/list
- Call tools using
/tools/call
with the appropriate arguments - Handle responses in your client application
The server returns all tool results in the standard MCP format:
{
"jsonrpc": "2.0",
"id": <request_id>,
"result": {
"content": [
{
"type": "text",
"text": "<JSON_data_here>"
}
]
}
}
Project Structure
src/
āāā arbitrum/ # Arbitrum blockchain service
ā āāā dto/ # Data transfer objects
ā āāā arbitrum.service.ts
ā āāā arbitrum.module.ts
āāā mcp/ # MCP protocol implementation
ā āāā mcp.controller.ts
ā āāā mcp.service.ts
ā āāā mcp.module.ts
āāā types/ # TypeScript type definitions
āāā app.module.ts # Main application module
āāā app.controller.ts # Health check controller
āāā app.service.ts # Application service
āāā main.ts # Application entry point
Available Scripts
npm run start
- Start the applicationnpm run start:dev
- Start in development mode with hot reloadnpm run start:debug
- Start in debug modenpm run build
- Build the applicationnpm run test
- Run testsnpm run lint
- Lint the codenpm run format
- Format the code
Environment Variables
Variable | Description | Required |
---|---|---|
ARBISCAN_API_KEY | Your Arbiscan API key | Yes |
PORT | Server port (default: 4000) | No |
NODE_ENV | Environment (development/production) | No |
Error Handling
The server returns standard JSON-RPC 2.0 error responses:
{
"jsonrpc": "2.0",
"id": <request_id>,
"error": {
"code": <error_code>,
"message": "<error_message>",
"data": "<additional_error_info>"
}
}
Common error codes:
-32601
: Method not found-32603
: Internal error-32602
: Invalid params
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
This project is licensed under the ISC License.