Skip to main content
Glama

get_latest_block

Retrieve the most recent Bitcoin block data using the Bitcoin MCP Server, enabling efficient access to blockchain information for analysis or integration.

Instructions

Get the latest block

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "type": "object" }

Implementation Reference

  • The handler function that executes the get_latest_block tool. It fetches the latest block via BitcoinService and returns formatted 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[], }; }
  • Tool registration in the listToolsRequestSchema handler, defining the tool name, description, and empty input schema (no parameters required).
    name: "get_latest_block", description: "Get the latest block", inputSchema: { type: "object", properties: {} }, } as Tool,
  • Tool handling registration in the CallToolRequestSchema switch statement, dispatching to the handleGetLatestBlock function.
    case "get_latest_block": { return handleGetLatestBlock(this.bitcoinService); }
  • Supporting helper method in BitcoinService that fetches the latest block hash and details from Blockstream API and returns BlockInfo.
    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 ); } }

Other Tools

Related Tools

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/AbdelStark/bitcoin-mcp'

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