Skip to main content
Glama
JamesANZ

Bitcoin MCP Server

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;
      };
    };
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Get transaction details' implies a read-only operation, but it doesn't specify if this requires authentication, has rate limits, returns specific data formats, or handles errors. For a tool with zero annotation coverage, this is a significant gap in describing how it behaves beyond basic functionality.

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

Conciseness5/5

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

The description is extremely concise with just three words, front-loading the core purpose without any wasted text. It's appropriately sized for a simple tool, making it easy to parse quickly, though this conciseness comes at the cost of missing contextual details.

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' include, how results are structured, or any behavioral aspects like error handling. For a tool that likely returns complex data (transaction details), this leaves significant gaps in understanding its full context and usage.

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, with the 'txid' parameter clearly documented as 'Transaction ID'. The description adds no additional meaning beyond this, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate, as the schema handles parameter documentation adequately.

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' clearly states the verb ('Get') and resource ('transaction details'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'decode_tx' or 'get_latest_block', leaving ambiguity about when to use this specific tool versus others that might also retrieve transaction-related 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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a transaction ID), exclusions, or comparisons to siblings like 'decode_tx' or 'decode_invoice', which could be relevant for transaction-related tasks. This leaves the agent with no context for tool selection.

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

Install Server

Other Tools

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/JamesANZ/bitcoin-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server