Skip to main content
Glama

get_latest_block

Retrieve the most recent Bitcoin blockchain data to monitor network activity and verify transaction confirmations.

Instructions

Get the latest block

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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[],
      };
    }
  • 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,
  • Dispatcher case in CallToolRequestHandler that routes get_latest_block calls to the handler function.
    case "get_latest_block": {
      return handleGetLatestBlock(this.bitcoinService);
    }
  • 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
        );
      }
    }

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