get-block-info
Retrieve detailed block information from MantraChain blockchain by specifying block height and network name using the Model Context Protocol (MCP).
Instructions
Get block information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| height | No | Optional block height to query, defaults to latest block | |
| networkName | Yes | Name of the network to use - must first check what networks are available through the mantrachain-mcp server by accessing the networks resource `networks://all` before you pass this arguments |
Implementation Reference
- src/tools/network.ts:27-43 (registration)MCP server.tool registration for 'get-block-info', including description, input schema, and inline handler function.server.tool( "get-block-info", "Get block information from cometbft rpc", { networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), height: z.number().optional().describe("Optional block height to query, defaults to latest block"), }, async ({ networkName, height }) => { await mantraClient.initialize(networkName); const currentBlockInfo = await mantraClient.getBlockInfo(height); return { content: [{type: "text", text: JSON.stringify(currentBlockInfo)}], }; } );
- src/tools/network.ts:30-35 (schema)Input validation schema using Zod for networkName (validated against available networks) and optional height.{ networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), height: z.number().optional().describe("Optional block height to query, defaults to latest block"), },
- src/tools/network.ts:36-42 (handler)Tool execution handler: initializes MantraClient for the specified network and retrieves block information, returning it as JSON text in MCP response format.async ({ networkName, height }) => { await mantraClient.initialize(networkName); const currentBlockInfo = await mantraClient.getBlockInfo(height); return { content: [{type: "text", text: JSON.stringify(currentBlockInfo)}], }; }
- Supporting utility function in NetworkService that fetches block data via Comet38Client, processes and returns key block metadata (height, time, chainId, tx count, proposer, appHash). Called by MantraClient.getBlockInfo.async getBlockInfo(height?: number) { try { const blockData = height ? await this.cometClient.block(height) : await this.cometClient.block(); // Extract the most useful information return { height: blockData.block.header.height, time: blockData.block.header.time.toISOString(), chainId: blockData.block.header.chainId, numTxs: blockData.block.txs?.length || 0, proposer: Buffer.from(blockData.block.header.proposerAddress).toString('hex').toUpperCase(), appHash: Buffer.from(blockData.block.header.appHash).toString('hex').toUpperCase(), }; } catch (error) { throw new Error(`Failed to get current block info: ${error instanceof Error ? error.message : String(error)}`); } }