Skip to main content
Glama
AbdelStark
by AbdelStark

decode_tx

Decode Bitcoin transaction hex to reveal details like inputs, outputs, and amounts for blockchain analysis and verification.

Instructions

Decode a Bitcoin transaction

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rawHexYesTransaction hex

Implementation Reference

  • MCP handler function for the decode_tx tool. Validates input schema and delegates to BitcoinService.decodeTx, then formats the response.
    export async function handleDecodeTx(
      bitcoinService: BitcoinService,
      args: unknown
    ) {
      const result = DecodeTxSchema.safeParse(args);
      if (!result.success) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Invalid parameters: ${result.error.message}`
        );
      }
    
      const tx = bitcoinService.decodeTx(result.data.rawHex);
      return {
        content: [
          {
            type: "text",
            text: `Decoded transaction:\nTXID: ${tx.txid}\nVersion: ${tx.version}\nInputs: ${tx.inputs.length}\nOutputs: ${tx.outputs.length}\nLocktime: ${tx.locktime}`,
          },
        ] as TextContent[],
      };
    }
  • Zod schema for validating input to decode_tx tool: requires rawHex string.
    export const DecodeTxSchema = z.object({
      rawHex: z.string().min(1, "Raw transaction hex is required"),
    });
  • Tool registration in listToolsRequestHandler: defines name, description, and inputSchema for decode_tx.
      name: "decode_tx",
      description: "Decode a Bitcoin transaction",
      inputSchema: {
        type: "object",
        properties: {
          rawHex: { type: "string", description: "Transaction hex" },
        },
        required: ["rawHex"],
      },
    } as Tool,
  • Tool call handler registration: switch case dispatches decode_tx calls to handleDecodeTx.
    case "decode_tx": {
      return handleDecodeTx(this.bitcoinService, args);
  • Core implementation of transaction decoding using bitcoinjs-lib Transaction.fromHex, extracts txid, inputs, outputs, etc.
    decodeTx(rawHex: string): DecodedTx {
      try {
        const tx = bitcoin.Transaction.fromHex(rawHex);
    
        return {
          txid: tx.getId(),
          version: tx.version,
          inputs: tx.ins.map((input) => ({
            txid: Buffer.from(input.hash).reverse().toString("hex"),
            vout: input.index,
            sequence: input.sequence,
          })),
          outputs: tx.outs.map((output) => ({
            value: output.value,
            scriptPubKey: output.script.toString("hex"),
            address: this.tryGetAddress(output.script),
          })),
          locktime: tx.locktime,
        };
      } catch (error) {
        logger.error({ error, rawHex }, "Failed to decode transaction");
        throw new BitcoinError(
          "Failed to decode transaction",
          BitcoinErrorCode.DECODE_ERROR
        );
      }
    }
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 offers minimal behavioral insight. It doesn't disclose whether this is a read-only operation, if it requires network access, potential rate limits, error conditions, or what the decoded output looks like. The description is functional but lacks context about how the tool behaves.

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 a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple tool with one parameter.

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?

For a tool with no annotations and no output schema, the description is inadequate. It doesn't explain what 'decode' entails (e.g., parsing inputs/outputs, scripts), the format of the result, or error handling. Given the complexity of Bitcoin transactions and lack of structured context, more completeness 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 schema description coverage is 100%, with the parameter 'rawHex' fully documented in the schema as 'Transaction hex'. The description adds no additional meaning beyond this, so it meets the baseline for high schema coverage without compensating value.

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

Purpose4/5

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

The description clearly states the verb ('decode') and resource ('a Bitcoin transaction'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_transaction' or 'decode_invoice', which prevents a perfect score.

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 about when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing raw hex data), exclusions, or comparisons to sibling tools like 'get_transaction' (which might retrieve transaction details differently).

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

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