get_latest_block
Retrieve the most recent Bitcoin blockchain data to monitor network activity and verify transaction confirmations.
Instructions
Get the latest block
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_latest_block"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server/tools.ts:142-152 (handler)The handler function that executes the get_latest_block tool logic. It calls bitcoinService.getLatestBlock() and formats the response as MCP text content.
export async function handleGetLatestBlock(bitcoinService: BitcoinService) { const block = await bitcoinService.getLatestBlock(); return { content: [ { type: "text", text: `Latest block:\nHash: ${block.hash}\nHeight: ${block.height}\nTimestamp: ${block.timestamp}\nTransactions: ${block.txCount}`, }, ] as TextContent[], }; } - src/server/base.ts:146-150 (registration)Registration of the get_latest_block tool in the listTools handler, including name, description, and empty input schema.
{ name: "get_latest_block", description: "Get the latest block", inputSchema: { type: "object", properties: {} }, } as Tool, - src/server/base.ts:209-211 (registration)Dispatcher case in CallToolRequestHandler that routes get_latest_block calls to the handler function.
case "get_latest_block": { return handleGetLatestBlock(this.bitcoinService); } - src/services/bitcoin.ts:173-202 (helper)Supporting utility in BitcoinService that fetches the latest block information from Blockstream API.
async getLatestBlock(): Promise<BlockInfo> { try { const hashRes = await fetch(`${this.apiBase}/blocks/tip/hash`); if (!hashRes.ok) { throw new Error("Failed to fetch latest block hash"); } const hash = await hashRes.text(); const blockRes = await fetch(`${this.apiBase}/block/${hash}`); if (!blockRes.ok) { throw new Error("Failed to fetch block data"); } const block = (await blockRes.json()) as BlockstreamBlock; return { hash: block.id, height: block.height, timestamp: block.timestamp, txCount: block.tx_count, size: block.size, weight: block.weight, }; } catch (error) { logger.error({ error }, "Failed to fetch latest block"); throw new BitcoinError( "Failed to fetch latest block", BitcoinErrorCode.BLOCKCHAIN_ERROR ); } }