Skip to main content
Glama

swap_status

Check the status of an open swap by providing the swap handle. Returns the current best sealed bid and number of bids, enabling you to decide when to execute or resume after losing context.

Instructions

Re-poll an open swap by its swap_handle — returns the current best sealed bid + how many bids are in. Read-only, stateless: the primary way to resume a swap after losing context (only the swap_handle is needed).

USE WHEN: letting maker competition build before executing, or rebuilding an in-flight swap after a context reset. DO NOT USE WHEN: you need settlement-leg detail (use get_htlc) or your trade history (use list_my_trades).

PARAM NOTES: returns best_bid (or null), bids_seen, still_open and rfq_status. When best_bid is present, swap_execute with the same limit_price (or best_bid.quote_id) to take it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
swap_handleYesThe swap_handle returned by swap_quote (the RFQ id).
max_wait_secondsNoBounded wait for new bids this call. Default 15, capped 25.

Implementation Reference

  • Core handler function for swap_status. Takes a SwapClient, SwapStatusArgs (swap_handle, optional max_wait_seconds), and a Sleep function. Calls client.getRFQ to fetch the RFQ, handles forbidden/not-found via uniform error contract, then polls for bids (pollForQuotes) if the RFQ is open, or fetches quotes directly if closed. Selects the best bid and returns outcome with swap_handle, status, best_bid, bids_seen, still_open, and next guidance.
    export async function runSwapStatus(
      client: SwapClient, args: SwapStatusArgs, sleep: Sleep,
    ): Promise<ToolContent> {
      let rfq: SwapRfq | null;
      try {
        rfq = await client.getRFQ(args.swap_handle);
      } catch (err) {
        // Uniform not-found contract (same as runSwapExecute): a forbidden/unauthorized
        // RFQ (exists but caller is not a participant) must NOT be distinguishable from
        // a non-existent one, or swap_handle becomes an existence/participant oracle.
        const msg = err instanceof Error ? err.message : String(err);
        if (/forbidden|not a participant|unauthor|\b401\b|\b403\b/i.test(msg)) {
          return okContent({ outcome: 'SWAP_NOT_FOUND', swap_handle: args.swap_handle,
            next: 'Verify the swap_handle, or open a fresh swap with swap_quote.' });
        }
        throw err;
      }
      if (!rfq) {
        return okContent({ outcome: 'SWAP_NOT_FOUND', swap_handle: args.swap_handle,
          next: 'Verify the swap_handle, or open a fresh swap with swap_quote.' });
      }
      const open = RFQ_OPEN_STATES.has(rfq.status);
      const quotes = open
        ? await pollForQuotes(client, rfq.id, rfq.side, rfq.amount, args.max_wait_seconds ?? 15, sleep)
        : await client.getQuotes(rfq.id);
      const best = selectBestBid(quotes, rfq.side, rfq.amount);
      return okContent({
        swap_handle: rfq.id,
        status: best ? 'QUOTED' : 'OPEN',
        rfq_status: rfq.status,
        best_bid: bidView(best),
        bids_seen: quotes.length,
        still_open: open,
        next: best
          ? 'swap_execute with this swap_handle + your limit_price (or best_bid.quote_id).'
          : open ? 'Still waiting on bids. Call swap_status again, or swap_cancel.'
                 : 'This swap is closed. Open a fresh one with swap_quote.',
      });
    }
  • TypeScript interface defining the input arguments for swap_status: swap_handle (string, required) and max_wait_seconds (number, optional).
    export interface SwapStatusArgs { swap_handle: string; max_wait_seconds?: number; }
  • src/index.ts:356-371 (registration)
    MCP server tool registration for 'swap_status'. Registers the tool with a description, Zod schema for swap_handle (string) and max_wait_seconds (optional number), and wraps the handler calling runSwapStatus(swapClient, a, realSleep).
    // ─── swap_status ─────────────────────────────────────────────
    server.tool(
      'swap_status',
      [
        'Re-poll an open swap by its swap_handle — returns the current best sealed bid + how many bids are in. Read-only, stateless: the primary way to resume a swap after losing context (only the swap_handle is needed).',
        '',
        'USE WHEN: letting maker competition build before executing, or rebuilding an in-flight swap after a context reset. DO NOT USE WHEN: you need settlement-leg detail (use get_htlc) or your trade history (use list_my_trades).',
        '',
        'PARAM NOTES: returns best_bid (or null), bids_seen, still_open and rfq_status. When best_bid is present, swap_execute with the same limit_price (or best_bid.quote_id) to take it.',
      ].join('\n'),
      {
        swap_handle: z.string().describe('The swap_handle returned by swap_quote (the RFQ id).'),
        max_wait_seconds: z.number().optional().describe('Bounded wait for new bids this call. Default 15, capped 25.'),
      },
      wrapTool(async (a) => runSwapStatus(swapClient, a, realSleep)),
    );
  • pollForQuotes helper used by runSwapStatus. Polls client.getQuotes at 2.5s intervals (capped at 25s max) until an eligible bid is found or the wait window elapses. Returns all quotes.
    export async function pollForQuotes(
      client: SwapClient, rfqId: string, side: Side, requestedAmount: string,
      maxWaitSeconds: number, sleep: Sleep,
    ): Promise<SwapQuote[]> {
      const capped = Math.max(0, Math.min(MAX_WAIT_CAP_S, Math.floor(maxWaitSeconds || 0)));
      const iterations = Math.max(1, Math.ceil((capped * 1000) / POLL_INTERVAL_MS) + 1);
      let quotes: SwapQuote[] = [];
      for (let i = 0; i < iterations; i++) {
        quotes = await client.getQuotes(rfqId);
        if (selectBestBid(quotes, side, requestedAmount)) return quotes;
        if (i < iterations - 1) await sleep(POLL_INTERVAL_MS);
      }
      return quotes;
    }
Behavior5/5

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

Despite no annotations, the description explicitly states read-only and stateless, describes output fields (best_bid, bids_seen, still_open, rfq_status), and explains the follow-up action with swap_execute, providing comprehensive behavioral context.

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?

Well-organized with distinct sections; each sentence adds necessary information without redundancy. The description is compact and front-loaded.

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, the description covers purpose, usage, parameters, output, and follow-up actions adequately. It could mention error handling but is complete for its complexity.

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% with descriptions for both parameters. The description adds value by explaining response fields and how to use them with swap_execute, enhancing semantics beyond the schema.

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 re-polls an open swap using swap_handle, returning the current best sealed bid and bid count. It distinguishes from siblings by referencing get_htlc and list_my_trades for different needs, making the purpose unambiguous.

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 provide specific scenarios and alternative tool names (get_htlc, list_my_trades), offering clear decision guidance.

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