get_mempool_ancestors
Retrieve all unconfirmed ancestor transactions for a given mempool transaction to analyze CPFP (Child Pays For Parent) scenarios and understand transaction dependencies.
Instructions
Get all unconfirmed ancestor transactions of a mempool transaction. Useful for CPFP analysis.
Args: txid: Transaction hash (64 hex characters)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| txid | Yes |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/bitcoin_mcp/server.py:325-348 (handler)The `get_mempool_ancestors` tool is implemented in `src/bitcoin_mcp/server.py` as a function decorated with `@mcp.tool()`. It uses the `get_rpc()` helper to call `getmempoolancestors` on the Bitcoin RPC interface and formats the results for MCP.
def get_mempool_ancestors(txid: str) -> str: """Get all unconfirmed ancestor transactions of a mempool transaction. Useful for CPFP analysis. Args: txid: Transaction hash (64 hex characters) """ try: ancestors = get_rpc().getmempoolancestors(txid, True) except Exception as e: return json.dumps({"error": str(e)}) summary = [] for anc_txid, info in ancestors.items(): summary.append({ "txid": anc_txid, "fee_sats": info.get("fees", {}).get("base", 0) * 1e8, "vsize": info.get("vsize"), "fee_rate_sat_vb": round(info.get("fees", {}).get("base", 0) * 1e8 / info.get("vsize", 1), 2) if info.get("vsize") else None, "depends": info.get("depends", []), }) return json.dumps({ "txid": txid, "ancestor_count": len(ancestors), "ancestors": summary, })