Skip to main content
Glama

refund_htlc

Recover locked funds after HTLC timelock expires when the swap fails to complete. Only the original sender can refund with no counterparty risk.

Instructions

Trustless unwind — recover locked funds after the HTLC timelock expires. Non-custodial refund guarantee: if the swap does not complete, the original sender reclaims their asset with zero counterparty risk.

USE WHEN: the timelock deadline has passed AND the counterparty never locked their side (or the swap otherwise failed to complete). DO NOT USE WHEN: counterparty HAS locked and the swap can still complete — use withdraw_htlc instead. Only the original lock sender can call refund, and only after the deadline.

PARAM NOTES: txHash is the on-chain refund tx hash (0x-prefixed). No preimage needed — expiry alone unlocks the refund path. Set chainType to "bitcoin" or "sui" for non-EVM legs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tradeIdYesTrade ID
txHashYesOn-chain refund transaction hash (0x-prefixed)
chainTypeNoChain type: evm, bitcoin, or sui
client_request_idNoIdempotency key. Retrying the SAME write with the SAME id within this MCP session returns the first result instead of triggering a second on-chain/backend side effect. Best-effort: not durable across MCP restarts.

Implementation Reference

  • src/index.ts:99-121 (registration)
    MCP tool registration for 'refund_htlc'. Defines the tool name, description (trustless unwind after HTLC timelock expiry), input schema (tradeId, txHash, chainType, client_request_id), and handler via wrapTool.
    server.tool(
      'refund_htlc',
      [
        'Trustless unwind — recover locked funds after the HTLC timelock expires. Non-custodial refund guarantee: if the swap does not complete, the original sender reclaims their asset with zero counterparty risk.',
        '',
        'USE WHEN: the timelock deadline has passed AND the counterparty never locked their side (or the swap otherwise failed to complete).',
        'DO NOT USE WHEN: counterparty HAS locked and the swap can still complete — use withdraw_htlc instead. Only the original lock sender can call refund, and only after the deadline.',
        '',
        'PARAM NOTES: `txHash` is the on-chain refund tx hash (0x-prefixed). No preimage needed — expiry alone unlocks the refund path. Set `chainType` to "bitcoin" or "sui" for non-EVM legs.',
      ].join('\n'),
      {
        tradeId: z.string().describe('Trade ID'),
        txHash: z.string().describe('On-chain refund transaction hash (0x-prefixed)'),
        chainType: z.string().optional().describe('Chain type: evm, bitcoin, or sui'),
        client_request_id: z.string().optional().describe('Idempotency key. Retrying the SAME write with the SAME id within this MCP session returns the first result instead of triggering a second on-chain/backend side effect. Best-effort: not durable across MCP restarts.'),
      },
      wrapTool(async ({ tradeId, txHash, chainType, client_request_id }) => {
        const input = { tradeId, txHash, chainType };
        const result = await idempotency.remember(idempotencyKey('refund_htlc', client_request_id, input), () =>
          hl.refundHTLC(input));
        return okContent(result);
      }),
    );
  • The actual handler function for refund_htlc. Constructs input (tradeId, txHash, chainType), uses idempotency guard with key 'refund_htlc', and delegates to hl.refundHTLC(input) from the @hashlock-tech/sdk.
    wrapTool(async ({ tradeId, txHash, chainType, client_request_id }) => {
      const input = { tradeId, txHash, chainType };
      const result = await idempotency.remember(idempotencyKey('refund_htlc', client_request_id, input), () =>
        hl.refundHTLC(input));
      return okContent(result);
    }),
  • Zod input schema for refund_htlc: tradeId (string), txHash (string), chainType (optional string: evm/bitcoin/sui), client_request_id (optional string for idempotency).
    {
      tradeId: z.string().describe('Trade ID'),
      txHash: z.string().describe('On-chain refund transaction hash (0x-prefixed)'),
      chainType: z.string().optional().describe('Chain type: evm, bitcoin, or sui'),
      client_request_id: z.string().optional().describe('Idempotency key. Retrying the SAME write with the SAME id within this MCP session returns the first result instead of triggering a second on-chain/backend side effect. Best-effort: not durable across MCP restarts.'),
    },
  • Helper function idempotencyKey used to generate a dedup key scoped by operation name ('refund_htlc'), client_request_id, and payload JSON.
    /** Compose a cache key scoped by operation + exact payload so the same
     *  client_request_id reused for a different tool or a different payload
     *  does NOT replay an unrelated result. Returns undefined when no id
     *  (=> no dedup, always run). */
    export function idempotencyKey(scope: string, clientRequestId: string | undefined, payload: unknown): string | undefined {
      if (!clientRequestId) return undefined;
      return `${scope}:${clientRequestId}:${JSON.stringify(payload)}`;
    }
Behavior4/5

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

Without annotations, the description carries full behavioral burden. It explains the refund mechanism (non-custodial, trustless, no preimage needed) and conditions. However, it omits details on idempotency or success/failure behavior beyond the parameter note for client_request_id.

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?

Description is well-structured into a title, usage conditions, parameter notes. Every sentence adds value, no redundancy. Appropriate length for the tool's complexity.

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

Completeness4/5

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

Given no output schema and moderate parameter count, the description covers usage context, parameter semantics, and behavioral intent. It lacks error scenarios or return value details, but is sufficient for an agent to invoke correctly in the stated conditions.

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

Parameters4/5

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

Schema coverage is 100% (baseline 3). Description adds value by clarifying that 'txHash' is on-chain 0x-prefixed and that 'chainType' should be 'bitcoin' or 'sui' for non-EVM legs, which is not obvious from the schema alone. Also explains 'client_request_id' as an idempotency key.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Trustless unwind — recover locked funds after the HTLC timelock expires.' It distinguishes from sibling 'withdraw_htlc' by specifying when NOT to use it, providing a specific verb-resource pair and scope.

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

Usage Guidelines5/5

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

Explicit 'USE WHEN' and 'DO NOT USE WHEN' sections with concrete conditions (timelock deadline passed, counterparty didn't lock) and an alternative tool named (withdraw_htlc). Also notes that only the original lock sender can call refund, and only after deadline.

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/Hashlock-Tech/hashlock-mcp'

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