Skip to main content
Glama

sweep_agent

Transfer funds from an agent's Lightning wallet back to the operator's balance using the agent ID and amount in satoshis.

Instructions

Sweep funds from agent back to operator balance. REQUIRES OPERATOR KEY.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesAgent ID to sweep funds from
amount_satsYesAmount in sats (use large number for full balance)

Implementation Reference

  • The handler implementation for the "sweep_agent" tool, which calls the client's sweepAgent method.
    case 'sweep_agent': {
      const parsed = SweepAgentSchema.parse(args);
      const amount = typeof parsed.amount_sats === 'string' ? 999999999 : parsed.amount_sats;
      const result = await session.requireClient().sweepAgent(parsed.agent_id, amount);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              message: `Swept ${result.amountTransferred} sats from agent`,
              amount_transferred: result.amountTransferred,
              new_operator_balance: result.newOperatorBalance,
              new_agent_balance: result.newAgentBalance,
            }, null, 2),
          },
        ],
      };
    }
  • The underlying API client method that performs the sweep operation.
    /**
     * Sweep funds from agent back to operator
     */
    async sweepAgent(agentId: number, amountSats: number): Promise<{
      amountTransferred: number;
      newOperatorBalance: number;
      newAgentBalance: number;
      rawResponse: ApiResponse;
    }> {
      const result = await this.request<ApiResponse & {
        amount_transferred?: number;
        new_operator_balance?: number;
        new_agent_balance?: number;
      }>('withdraw_from_agent', {
        agent_id: agentId,
        amount_sats: amountSats,
        sweep: true,
      });
    
      return {
        amountTransferred: result.amount_transferred || amountSats,
        newOperatorBalance: result.new_operator_balance || 0,
        newAgentBalance: result.new_agent_balance || 0,
        rawResponse: result,
      };
    }
  • The input validation schema for the sweep_agent tool.
    const SweepAgentSchema = z.object({
      agent_id: z.number().int().positive().describe('Agent ID to sweep funds from'),
      amount_sats: z.union([z.number().int().positive(), z.literal('all')]).describe('Amount in sats or "all" for full balance'),
    });

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/lightningfaucet/lightning-wallet-mcp'

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