search_blockchain
Search Bitcoin blockchain data by automatically detecting transaction IDs, block hashes, block heights, or addresses to retrieve relevant information.
Instructions
Smart search: auto-detects if query is a txid, block hash, block height, or address and returns the right data.
Args: query: A txid (64 hex), block hash (64 hex starting with 0000), block height (number), or Bitcoin address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/bitcoin_mcp/server.py:764-798 (handler)The tool "search_blockchain" detects if a query is a block height, txid, block hash, or address and performs the appropriate lookup.
def search_blockchain(query: str) -> str: """Smart search: auto-detects if query is a txid, block hash, block height, or address and returns the right data. Args: query: A txid (64 hex), block hash (64 hex starting with 0000), block height (number), or Bitcoin address """ query = query.strip() # Block height (pure digits) if query.isdigit(): try: analysis = _analyze_block(get_rpc(), query) return analysis.model_dump_json() except Exception as e: return json.dumps({"error": f"Block lookup failed: {e}"}) # 64 hex chars — block hash or txid if re.fullmatch(r"[0-9a-fA-F]{64}", query): if query.startswith("0000"): try: analysis = _analyze_block(get_rpc(), query) return analysis.model_dump_json() except Exception: pass # fall through to txid try: analysis = _analyze_transaction(get_rpc(), query) return analysis.model_dump_json() except Exception as e: return json.dumps({"error": f"Transaction lookup failed: {e}"}) # Address validation try: result = get_rpc().validateaddress(query) if result.get("isvalid"): return json.dumps(result) except Exception: pass return json.dumps({"error": f"Could not identify query: {query!r}. Provide a txid, block hash, block height, or address."})