Provides real-time information about Ethereum addresses across multiple chains using the Model Context Protocol, featuring a Server-Sent Events endpoint for live updates.
This server provides information about Ethereum addresses across multiple chains using the Model Context Protocol (MCP). It includes a Server-Sent Events (SSE) endpoint for real-time updates.
Clone the repository:
git clone cd mcp-0x-address
Install dependencies:
npm install
Create a .env
file with the following variables:
MCP_PORT=3002
Start the HTTP MCP server:
npm run start:http
This will start the server on port 3002 (or the port specified in your .env
file).
The server provides the following endpoints:
GET /health
- Server health checkPOST /mcp
- MCP endpoint for tool callsGET /sse
- Server-Sent Events endpoint for real-time updatesGET /sse/clients
- Get information about connected SSE clientsPOST /sse/subscribe/:clientId
- Subscribe to address updatesPOST /sse/unsubscribe/:clientId
- Unsubscribe from address updatesThe SSE endpoint allows clients to receive real-time updates from the server. Here's how to use it:
curl -N http://localhost:3002/sse
This will establish a connection to the SSE endpoint and start receiving events. The connection will remain open until you manually terminate it.
curl http://localhost:3002/sse/clients
After connecting to the SSE endpoint, you'll receive a client ID. Use that ID to subscribe to address updates:
curl -X POST \ http://localhost:3002/sse/subscribe/YOUR_CLIENT_ID \ -H "Content-Type: application/json" \ -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]}'
Replace YOUR_CLIENT_ID
with the client ID you received when connecting to the SSE endpoint.
curl -X POST \ http://localhost:3002/sse/unsubscribe/YOUR_CLIENT_ID \ -H "Content-Type: application/json" \ -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}'
To trigger an address update (which will be sent to subscribed clients), call the get-address-info
tool:
curl -X POST \ http://localhost:3002/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get-address-info", "arguments": { "address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" } } }'
curl http://localhost:3002/health
curl -X POST \ http://localhost:3002/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "ping", "arguments": {} } }'
Here's a complete workflow for testing the SSE functionality:
Start the server:
npm run start:http
In a new terminal, connect to the SSE endpoint:
curl -N http://localhost:3002/sse
You'll receive a response like:
data: {"type":"connection","clientId":"client-1234567890abcdef","message":"Connected to MCP SSE endpoint","timestamp":"2023-01-01T00:00:00.000Z"}
Note the clientId
from the response.
In another terminal, subscribe to address updates:
curl -X POST \ http://localhost:3002/sse/subscribe/client-1234567890abcdef \ -H "Content-Type: application/json" \ -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}'
Trigger an address update:
curl -X POST \ http://localhost:3002/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get-address-info", "arguments": { "address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" } } }'
In the terminal where you're connected to the SSE endpoint, you'll see updates for the address.
For a more automated test, you can use this bash script:
#!/bin/bash # Start SSE connection in the background and capture the output curl -N http://localhost:3002/sse > sse_output.txt & SSE_PID=$! # Wait a moment for the connection to establish sleep 2 # Extract the client ID from the output CLIENT_ID=$(grep -o '"clientId":"[^"]*"' sse_output.txt | head -1 | cut -d'"' -f4) if [ -z "$CLIENT_ID" ]; then echo "Failed to get client ID" kill $SSE_PID exit 1 fi echo "Connected with client ID: $CLIENT_ID" # Subscribe to an address curl -X POST \ http://localhost:3002/sse/subscribe/$CLIENT_ID \ -H "Content-Type: application/json" \ -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}' echo "Subscribed to address. Waiting for updates..." echo "Press Ctrl+C to stop" # Keep the script running to see updates tail -f sse_output.txt # Clean up on exit trap "kill $SSE_PID; rm sse_output.txt" EXIT
Save this as test_sse.sh
, make it executable with chmod +x test_sse.sh
, and run it with ./test_sse.sh
.
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!