Skip to main content
Glama

get_transaction

Retrieve detailed information about a Bitcoin transaction by providing its unique transaction ID using the Bitcoin MCP Server tool.

Instructions

Get transaction details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
txidYesTransaction ID

Implementation Reference

  • The MCP tool handler for 'get_transaction' that validates input schema, fetches transaction via BitcoinService, and returns formatted text response.
    export async function handleGetTransaction( bitcoinService: BitcoinService, args: unknown ) { const result = GetTransactionSchema.safeParse(args); if (!result.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${result.error.message}` ); } const tx = await bitcoinService.getTransaction(result.data.txid); return { content: [ { type: "text", text: `Transaction details:\nTXID: ${tx.txid}\nStatus: ${ tx.status.confirmed ? "Confirmed" : "Unconfirmed" }\nBlock Height: ${tx.status.blockHeight || "Pending"}\nFee: ${ tx.fee } sats`, }, ] as TextContent[], }; }
  • Zod input validation schema for get_transaction tool requiring a 64-char txid.
    export const GetTransactionSchema = z.object({ txid: z.string().length(64, "Invalid transaction ID"), });
  • Tool registration in listTools handler defining name, description, and input schema for get_transaction.
    name: "get_transaction", description: "Get transaction details", inputSchema: { type: "object", properties: { txid: { type: "string", description: "Transaction ID" }, }, required: ["txid"], }, } as Tool,
  • Dispatch case in callToolRequest handler that routes get_transaction calls to the specific handler function.
    case "get_transaction": { return handleGetTransaction(this.bitcoinService, args); }
  • Core service method that queries Blockstream API for transaction details and maps to structured TransactionInfo.
    async getTransaction(txid: string): Promise<TransactionInfo> { try { const response = await fetch(`${this.apiBase}/tx/${txid}`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const tx = (await response.json()) as any; return { txid: tx.txid, version: tx.version, locktime: tx.locktime, size: tx.size, weight: tx.weight, fee: tx.fee, status: { confirmed: tx.status.confirmed, blockHeight: tx.status.block_height, blockHash: tx.status.block_hash, blockTime: tx.status.block_time, }, inputs: tx.vin.map((input: any) => ({ txid: input.txid, vout: input.vout, sequence: input.sequence, prevout: input.prevout ? { value: input.prevout.value, scriptPubKey: input.prevout.scriptpubkey, address: input.prevout.scriptpubkey_address, } : undefined, })), outputs: tx.vout.map((output: any) => ({ value: output.value, scriptPubKey: output.scriptpubkey, address: output.scriptpubkey_address, })), }; } catch (error) { logger.error({ error, txid }, "Failed to get transaction"); throw new BitcoinError( "Failed to get transaction", BitcoinErrorCode.BLOCKCHAIN_ERROR ); } }

Other Tools

Related 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