Skip to main content
Glama

Rootstock MCP Server

by cuongpo
MIT License
rootstock-testnet-demo.js9.27 kB
#!/usr/bin/env node /** * Live demo of get_balance on Rootstock Testnet * This demonstrates the actual MCP server working with Rootstock blockchain */ import { spawn } from 'child_process'; async function testGetBalanceOnRootstock() { console.log('🚀 Rootstock Testnet - Live get_balance Demo'); console.log('===========================================\n'); console.log('🌐 Network Details:'); console.log('• Network: Rootstock Testnet'); console.log('• Chain ID: 31'); console.log('• RPC: https://public-node.testnet.rsk.co'); console.log('• Currency: tRBTC'); console.log('• Explorer: https://explorer.testnet.rootstock.io\n'); console.log('🚀 Starting Rootstock MCP Server...'); const serverProcess = spawn('node', ['build/index.js'], { stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, ROOTSTOCK_RPC_URL: 'https://public-node.testnet.rsk.co', ROOTSTOCK_CHAIN_ID: '31', ROOTSTOCK_NETWORK_NAME: 'Rootstock Testnet', ROOTSTOCK_CURRENCY_SYMBOL: 'tRBTC', ROOTSTOCK_EXPLORER_URL: 'https://explorer.testnet.rootstock.io' } }); // Wait for server to start await new Promise(resolve => setTimeout(resolve, 3000)); console.log('✅ MCP Server started\n'); // Test 1: Get network info console.log('📡 Test 1: Getting Network Information'); console.log('─'.repeat(40)); const networkRequest = { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'get_network_info', arguments: {} } }; console.log('📤 Request:', JSON.stringify(networkRequest, null, 2)); return new Promise((resolve) => { let responseBuffer = ''; let testCount = 0; const timeout = setTimeout(() => { console.log('⏰ Demo completed (timeout reached)'); serverProcess.kill(); resolve(true); }, 15000); serverProcess.stdout.on('data', (data) => { const output = data.toString(); responseBuffer += output; // Look for JSON responses const lines = responseBuffer.split('\n').filter(line => line.trim()); for (const line of lines) { try { const response = JSON.parse(line); if (response.result && response.result.content) { testCount++; console.log('✅ Response received:'); console.log(response.result.content[0].text); console.log(); if (testCount === 1) { // Send balance request after network info setTimeout(() => { console.log('💰 Test 2: Getting Balance (Sample Address)'); console.log('─'.repeat(40)); const balanceRequest = { jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'get_balance', arguments: { address: '0x7F873eD3ecef67074E2594038AB3D8dd508cF9F4' // Generated wallet address } } }; console.log('📤 Request:', JSON.stringify(balanceRequest, null, 2)); serverProcess.stdin.write(JSON.stringify(balanceRequest) + '\n'); }, 1000); } if (testCount >= 2) { clearTimeout(timeout); serverProcess.kill(); resolve(true); } } } catch (e) { // Continue collecting data } } }); serverProcess.stderr.on('data', (data) => { console.log('🔍 Server info:', data.toString().trim()); }); // Send first request serverProcess.stdin.write(JSON.stringify(networkRequest) + '\n'); }); } function showRootstockIntegrationGuide() { console.log('📚 Rootstock Testnet Integration Guide'); console.log('====================================\n'); console.log('🔧 1. Environment Setup:'); console.log('Create .env file with:'); console.log(`ROOTSTOCK_RPC_URL=https://public-node.testnet.rsk.co ROOTSTOCK_CHAIN_ID=31 ROOTSTOCK_NETWORK_NAME=Rootstock Testnet ROOTSTOCK_CURRENCY_SYMBOL=tRBTC ROOTSTOCK_EXPLORER_URL=https://explorer.testnet.rootstock.io\n`); console.log('🤖 2. Claude Desktop Integration:'); console.log('Add to claude_desktop_config.json:'); console.log(`{ "mcpServers": { "rootstock-mcp": { "command": "node", "args": ["/path/to/rootstock-mcp-server/build/index.js"], "env": { "ROOTSTOCK_RPC_URL": "https://public-node.testnet.rsk.co", "ROOTSTOCK_CHAIN_ID": "31", "ROOTSTOCK_NETWORK_NAME": "Rootstock Testnet", "ROOTSTOCK_CURRENCY_SYMBOL": "tRBTC" } } } }\n`); console.log('💬 3. Example Claude Conversations:'); console.log('User: "What is the tRBTC balance of 0x7F873eD3ecef67074E2594038AB3D8dd508cF9F4?"'); console.log('Claude: *Uses get_balance tool automatically*'); console.log('Response: "The address has 0 tRBTC on Rootstock Testnet"\n'); console.log('User: "What is the current Rootstock testnet block number?"'); console.log('Claude: *Uses get_network_info tool*'); console.log('Response: "The latest block on Rootstock Testnet is #1946318"\n'); console.log('🛠️ 4. Available MCP Tools for Rootstock:'); const tools = [ 'create_wallet - Generate new Rootstock-compatible wallet', 'get_balance - Check tRBTC balance on Rootstock testnet', 'send_transaction - Send tRBTC to other addresses', 'get_network_info - Get Rootstock network status', 'estimate_gas - Calculate transaction costs in tRBTC', 'get_transaction - Query transaction details', 'get_block - Get block information', 'call_contract - Interact with smart contracts', 'send_contract_transaction - Execute contract functions' ]; tools.forEach((tool, index) => { console.log(` ${index + 1}. ${tool}`); }); console.log('\n🎯 5. Real-World Use Cases:'); console.log('• DeFi protocol testing on Rootstock'); console.log('• Smart contract development and testing'); console.log('• Portfolio tracking for Rootstock assets'); console.log('• Automated trading bot development'); console.log('• Multi-chain wallet management'); console.log('• Transaction monitoring and alerts\n'); console.log('🔗 6. Useful Links:'); console.log('• Testnet Explorer: https://explorer.testnet.rootstock.io'); console.log('• RPC Endpoint: https://public-node.testnet.rsk.co'); console.log('• Chain ID: 31'); console.log('• Currency: tRBTC\n'); } function showMockBalanceExample() { console.log('🎭 Mock get_balance Example for Rootstock Testnet'); console.log('===============================================\n'); console.log('📤 MCP Request:'); console.log(`{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_balance", "arguments": { "address": "0x7F873eD3ecef67074E2594038AB3D8dd508cF9F4" } } }\n`); console.log('📥 MCP Response:'); console.log(`{ "jsonrpc": "2.0", "id": 1, "result": { "content": [ { "type": "text", "text": "Native Balance:\\n\\nAddress: 0x7F873eD3ecef67074E2594038AB3D8dd508cF9F4\\nBalance: 0 tRBTC" } ] } }\n`); console.log('✨ What happens:'); console.log('1. MCP server receives get_balance request'); console.log('2. Connects to Rootstock testnet RPC'); console.log('3. Calls eth_getBalance with the address'); console.log('4. Converts Wei to tRBTC (human-readable)'); console.log('5. Returns formatted response with tRBTC symbol\n'); console.log('🎯 Key Features:'); console.log('• Native Rootstock testnet support'); console.log('• Automatic tRBTC currency formatting'); console.log('• Real-time balance queries'); console.log('• Error handling for invalid addresses'); console.log('• Integration with block explorer links\n'); } async function main() { const args = process.argv.slice(2); if (args.includes('--live') || args.includes('-l')) { await testGetBalanceOnRootstock(); console.log('\n🎉 Live demo completed!'); console.log('The get_balance tool successfully connected to Rootstock testnet'); console.log('and retrieved network information and balance data.\n'); } else if (args.includes('--guide') || args.includes('-g')) { showRootstockIntegrationGuide(); } else if (args.includes('--mock') || args.includes('-m')) { showMockBalanceExample(); } else { console.log('🎯 Rootstock Testnet MCP Demo Options'); console.log('===================================\n'); console.log('Available demos:'); console.log('🔴 --live (-l) Run live demo with Rootstock testnet'); console.log('📚 --guide (-g) Show integration guide'); console.log('🎭 --mock (-m) Show mock example\n'); console.log('Examples:'); console.log(' node rootstock-testnet-demo.js --live'); console.log(' node rootstock-testnet-demo.js --guide'); console.log(' node rootstock-testnet-demo.js --mock\n'); // Show mock by default showMockBalanceExample(); } } main().catch(console.error);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cuongpo/rootstock-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server