Skip to main content
Glama
cuongpo

Rootstock MCP Server

by cuongpo

get_block

Retrieve block details from the Rootstock blockchain using either block number or hash for informed blockchain analysis and operations.

Instructions

Get block information by number or hash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockHashNoBlock hash (alternative to blockNumber)
blockNumberNoBlock number (alternative to blockHash)

Implementation Reference

  • The handler function that executes the 'get_block' tool logic. It calls RootstockClient.getBlock and formats the response as MCP content.
    private async handleGetBlock(params: GetBlockParams) { try { const block = await this.rootstockClient.getBlock(params.blockNumber, params.blockHash); return { content: [ { type: 'text', text: `Block Information:\n\nNumber: ${block.number}\nHash: ${block.hash}\nTimestamp: ${new Date(block.timestamp * 1000).toISOString()}\nTransactions: ${block.transactionCount}\nGas Used: ${block.gasUsed}\nGas Limit: ${block.gasLimit}\nMiner: ${block.miner}`, }, ], }; } catch (error) { throw new Error(`Failed to get block: ${error}`); } }
  • src/index.ts:269-285 (registration)
    Registration of the 'get_block' tool in the MCP server's listAvailableTools method, defining name, description, and input schema.
    { name: 'get_block', description: 'Get block information by number or hash', inputSchema: { type: 'object', properties: { blockNumber: { type: 'number', description: 'Block number (alternative to blockHash)', }, blockHash: { type: 'string', description: 'Block hash (alternative to blockNumber)', }, }, }, },
  • TypeScript interface defining the input parameters for the get_block tool.
    export interface GetBlockParams { blockNumber?: number; blockHash?: string; }
  • Supporting method in RootstockClient that performs the actual blockchain RPC call to retrieve block data using ethers.js.
    async getBlock(blockNumber?: number, blockHash?: string): Promise<BlockInfo> { try { let block; if (blockHash) { block = await this.getProvider().getBlock(blockHash); } else if (blockNumber !== undefined) { block = await this.getProvider().getBlock(blockNumber); } else { block = await this.getProvider().getBlock('latest'); } if (!block) { throw new Error('Block not found'); } return { number: block.number, hash: block.hash || '', parentHash: block.parentHash, timestamp: block.timestamp, gasLimit: block.gasLimit.toString(), gasUsed: block.gasUsed.toString(), miner: block.miner, difficulty: block.difficulty?.toString(), size: block.length || 0, transactionCount: block.transactions.length, }; } catch (error) { throw new Error(`Failed to get block: ${error}`); } }

Latest Blog Posts

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