search_blocks
Retrieve Bitcoin block statistics for a specific height range, allowing analysis of up to 10 consecutive blocks at once.
Instructions
Get block statistics for a range of heights. Max 10 blocks.
Args: start_height: Starting block height (inclusive) end_height: Ending block height (inclusive)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_height | Yes | ||
| end_height | Yes |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/bitcoin_mcp/server.py:260-284 (handler)The implementation of the `search_blocks` tool, which queries statistics for a block range via the RPC `getblockstats` method.
def search_blocks(start_height: int, end_height: int) -> str: """Get block statistics for a range of heights. Max 10 blocks. Args: start_height: Starting block height (inclusive) end_height: Ending block height (inclusive) """ if end_height - start_height + 1 > 10: return json.dumps({"error": "Maximum range is 10 blocks. Narrow your search."}) if start_height > end_height: return json.dumps({"error": "start_height must be <= end_height"}) results = [] for h in range(start_height, end_height + 1): stats = get_rpc().getblockstats(h) results.append({ "height": h, "time": stats.get("time"), "txs": stats.get("txs"), "total_fee": stats.get("totalfee"), "avg_fee_rate": stats.get("avgfeerate"), "median_fee_rate": stats.get("feerate_percentiles", [None, None, None])[2] if "feerate_percentiles" in stats else stats.get("medianfee"), "total_weight": stats.get("total_weight"), "total_size": stats.get("total_size"), }) return json.dumps(results)