Skip to main content
Glama
JamesANZ

Bitcoin MCP Server

by JamesANZ

get_transaction

Retrieve Bitcoin transaction details by providing a transaction ID to access blockchain data.

Instructions

Get transaction details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
txidYesTransaction ID

Implementation Reference

  • The main execution handler for the 'get-transaction' tool. Fetches raw transaction data via helper and formats a detailed Markdown-like text response including basic info, status, inputs, and outputs.
    async ({ txid }) => {
      try {
        const tx = await getTransaction(txid);
    
        let result = `**Transaction: ${tx.txid}**\n\n`;
        result += `**Basic Info:**\n`;
        result += `- Version: ${tx.version}\n`;
        result += `- Size: ${tx.size} bytes\n`;
        result += `- Weight: ${tx.weight} WU\n`;
        result += `- Fee: ${tx.fee} sats\n`;
        result += `- Locktime: ${tx.locktime}\n\n`;
    
        result += `**Status:**\n`;
        if (tx.status.confirmed) {
          result += `- Confirmed in block ${tx.status.block_height}\n`;
          result += `- Block hash: ${tx.status.block_hash}\n`;
          result += `- Block time: ${new Date(tx.status.block_time! * 1000).toISOString()}\n`;
        } else {
          result += `- Unconfirmed (in mempool)\n`;
        }
        result += "\n";
    
        result += `**Inputs (${tx.vin.length}):**\n`;
        tx.vin.forEach((input, index) => {
          if (input.prevout) {
            result += `${index + 1}. ${input.txid.substring(0, 16)}...:${input.vout} - ${(input.prevout.value / 100000000).toFixed(8)} BTC\n`;
          } else {
            result += `${index + 1}. Coinbase transaction\n`;
          }
        });
        result += "\n";
    
        result += `**Outputs (${tx.vout.length}):**\n`;
        tx.vout.forEach((output, index) => {
          result += `${index + 1}. ${(output.value / 100000000).toFixed(8)} BTC to ${output.scriptpubkey_address || "Unknown address"}\n`;
        });
    
        return {
          content: [
            {
              type: "text",
              text: result,
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching transaction data: ${error.message || "Unknown error"}`,
            },
          ],
        };
      }
    },
  • Zod input schema defining the 'txid' parameter for the tool.
    {
      txid: z.string().describe("Transaction ID (hash) to query"),
    },
  • src/index.ts:262-324 (registration)
    Registration of the 'get-transaction' tool on the MCP server using server.tool() with name, description, schema, and handler.
    server.tool(
      "get-transaction",
      "Get detailed information about a Bitcoin transaction",
      {
        txid: z.string().describe("Transaction ID (hash) to query"),
      },
      async ({ txid }) => {
        try {
          const tx = await getTransaction(txid);
    
          let result = `**Transaction: ${tx.txid}**\n\n`;
          result += `**Basic Info:**\n`;
          result += `- Version: ${tx.version}\n`;
          result += `- Size: ${tx.size} bytes\n`;
          result += `- Weight: ${tx.weight} WU\n`;
          result += `- Fee: ${tx.fee} sats\n`;
          result += `- Locktime: ${tx.locktime}\n\n`;
    
          result += `**Status:**\n`;
          if (tx.status.confirmed) {
            result += `- Confirmed in block ${tx.status.block_height}\n`;
            result += `- Block hash: ${tx.status.block_hash}\n`;
            result += `- Block time: ${new Date(tx.status.block_time! * 1000).toISOString()}\n`;
          } else {
            result += `- Unconfirmed (in mempool)\n`;
          }
          result += "\n";
    
          result += `**Inputs (${tx.vin.length}):**\n`;
          tx.vin.forEach((input, index) => {
            if (input.prevout) {
              result += `${index + 1}. ${input.txid.substring(0, 16)}...:${input.vout} - ${(input.prevout.value / 100000000).toFixed(8)} BTC\n`;
            } else {
              result += `${index + 1}. Coinbase transaction\n`;
            }
          });
          result += "\n";
    
          result += `**Outputs (${tx.vout.length}):**\n`;
          tx.vout.forEach((output, index) => {
            result += `${index + 1}. ${(output.value / 100000000).toFixed(8)} BTC to ${output.scriptpubkey_address || "Unknown address"}\n`;
          });
    
          return {
            content: [
              {
                type: "text",
                text: result,
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching transaction data: ${error.message || "Unknown error"}`,
              },
            ],
          };
        }
      },
    );
  • Helper function that fetches the raw Transaction data from the mempool.space API.
    async function getTransaction(txid: string): Promise<Transaction> {
      const res = await superagent
        .get(`${MEMPOOL_API_BASE}/tx/${txid}`)
        .set("User-Agent", USER_AGENT);
    
      return res.body;
    }
  • TypeScript interface defining the structure of a Transaction object used by the tool.
    type Transaction = {
      txid: string;
      version: number;
      locktime: number;
      vin: any[];
      vout: any[];
      size: number;
      weight: number;
      fee: number;
      status: {
        confirmed: boolean;
        block_height?: number;
        block_hash?: string;
        block_time?: number;
      };
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits such as whether this is a read-only operation, error handling, rate limits, or authentication needs. It mentions 'details' but doesn't specify what those include.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with 'Get transaction details'—a single, front-loaded sentence that efficiently conveys the core purpose without unnecessary words. However, it may be overly terse for a tool with no annotations or output schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what transaction details are returned, error conditions, or how it differs from sibling tools. For a tool with one parameter but no structured context, more information is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting the 'txid' parameter. The description adds no additional meaning beyond the schema, so it meets the baseline of 3 for adequate but not enhanced parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get transaction details' states the basic action (get) and resource (transaction details), but it's vague about what specific details are retrieved and doesn't differentiate from sibling tools like 'decode_tx' or 'get_latest_block'. It provides minimal but adequate purpose information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'decode_tx' (which might decode transaction data) or 'get_latest_block' (which retrieves block information). The description lacks context about prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.