Skip to main content
Glama

write.account.withdraw

Idempotent

Build an unsigned transaction to withdraw assets from an Arcadia Finance account to the owner's wallet, ensuring the account remains properly collateralized.

Instructions

Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256 — pass exact amounts from read.account.info. Account version is auto-detected on-chain (override with account_version if needed).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_addressYesArcadia account address
asset_addressesYesToken contract addresses to withdraw
asset_amountsYesAmounts in raw units/wei, one per asset
asset_idsNoToken IDs: 0 for ERC20, NFT token ID for ERC721
asset_typesNoV4 only. Asset types per asset: 1=ERC20, 2=ERC721, 3=ERC1155. If omitted, inferred from asset_ids (non-zero → ERC721).
account_versionNoOverride account version (3 or 4). Auto-detected on-chain if omitted.
chain_idNoChain ID: 8453 (Base) or 130 (Unichain)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
transactionYes
predicted_account_addressNo

Implementation Reference

  • Registration of the "write.account.withdraw" tool.
    export function registerWithdrawTool(server: McpServer, chains: Record<ChainId, ChainConfig>) {
      server.registerTool(
        "write.account.withdraw",
        {
          annotations: {
            title: "Build Withdraw Transaction",
            readOnlyHint: false,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: false,
          },
          outputSchema: SimpleTransactionOutput,
          description:
            "Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256 — pass exact amounts from read.account.info. Account version is auto-detected on-chain (override with account_version if needed).",
          inputSchema: {
            account_address: z.string().describe("Arcadia account address"),
            asset_addresses: z.array(z.string()).describe("Token contract addresses to withdraw"),
            asset_amounts: z.array(z.string()).describe("Amounts in raw units/wei, one per asset"),
            asset_ids: z
              .array(z.number())
              .optional()
              .describe("Token IDs: 0 for ERC20, NFT token ID for ERC721"),
            asset_types: z
              .array(z.number())
              .optional()
              .describe(
                "V4 only. Asset types per asset: 1=ERC20, 2=ERC721, 3=ERC1155. If omitted, inferred from asset_ids (non-zero → ERC721).",
              ),
            account_version: z
              .number()
              .optional()
              .describe("Override account version (3 or 4). Auto-detected on-chain if omitted."),
            chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
          },
        },
        async (params) => {
          try {
            if (params.asset_amounts.some((a) => a === "max_uint256")) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: 'Error: write.account.withdraw does not support "max_uint256". Pass exact amounts from read.account.info.',
                  },
                ],
                isError: true,
              };
            }
            if (params.asset_addresses.length !== params.asset_amounts.length) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: "Error: asset_addresses and asset_amounts must have the same length.",
                  },
                ],
                isError: true,
              };
            }
    
            const validChainId = validateChainId(params.chain_id);
            const validAccount = validateAddress(params.account_address, "account_address");
    
            let version = params.account_version ?? 0;
            if (!version) {
              const client = getPublicClient(validChainId, chains);
              version = Number(
                await client.readContract({
                  address: validAccount,
                  abi: accountAbi,
                  functionName: "ACCOUNT_VERSION",
                }),
              );
            }
    
            const ids = (params.asset_ids ?? params.asset_addresses.map(() => 0)).map((n) => BigInt(n));
            const amounts = params.asset_amounts.map((a) => BigInt(a));
            const abi = getAccountAbi(version);
    
            const args: unknown[] = [params.asset_addresses as `0x${string}`[], ids, amounts];
            if (version >= 4) {
              const assetTypes = params.asset_types
                ? params.asset_types.map((t) => BigInt(t))
                : ids.map((id) => (id > 0n ? 2n : 1n)); // 0 → ERC20 (1), non-zero → ERC721 (2)
              args.push(assetTypes);
            }
    
            const data = appendDataSuffix(
              encodeFunctionData({
                abi,
                functionName: "withdraw",
                args,
              }),
            );
    
            const result = {
              description: `Withdraw assets from Arcadia account (V${version})`,
              transaction: {
                to: validAccount,
                data,
                value: "0",
                chainId: validChainId,
              },
            };
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(result, null, 2),
                },
              ],
              structuredContent: result,
            };
          } catch (err) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error: ${err instanceof Error ? err.message : String(err)}`,
                },
              ],
              isError: true,
            };
          }
        },
      );
    }
  • Handler function for the "write.account.withdraw" tool.
    async (params) => {
      try {
        if (params.asset_amounts.some((a) => a === "max_uint256")) {
          return {
            content: [
              {
                type: "text" as const,
                text: 'Error: write.account.withdraw does not support "max_uint256". Pass exact amounts from read.account.info.',
              },
            ],
            isError: true,
          };
        }
        if (params.asset_addresses.length !== params.asset_amounts.length) {
          return {
            content: [
              {
                type: "text" as const,
                text: "Error: asset_addresses and asset_amounts must have the same length.",
              },
            ],
            isError: true,
          };
        }
    
        const validChainId = validateChainId(params.chain_id);
        const validAccount = validateAddress(params.account_address, "account_address");
    
        let version = params.account_version ?? 0;
        if (!version) {
          const client = getPublicClient(validChainId, chains);
          version = Number(
            await client.readContract({
              address: validAccount,
              abi: accountAbi,
              functionName: "ACCOUNT_VERSION",
            }),
          );
        }
    
        const ids = (params.asset_ids ?? params.asset_addresses.map(() => 0)).map((n) => BigInt(n));
        const amounts = params.asset_amounts.map((a) => BigInt(a));
        const abi = getAccountAbi(version);
    
        const args: unknown[] = [params.asset_addresses as `0x${string}`[], ids, amounts];
        if (version >= 4) {
          const assetTypes = params.asset_types
            ? params.asset_types.map((t) => BigInt(t))
            : ids.map((id) => (id > 0n ? 2n : 1n)); // 0 → ERC20 (1), non-zero → ERC721 (2)
          args.push(assetTypes);
        }
    
        const data = appendDataSuffix(
          encodeFunctionData({
            abi,
            functionName: "withdraw",
            args,
          }),
        );
    
        const result = {
          description: `Withdraw assets from Arcadia account (V${version})`,
          transaction: {
            to: validAccount,
            data,
            value: "0",
            chainId: validChainId,
          },
        };
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(result, null, 2),
            },
          ],
          structuredContent: result,
        };
      } catch (err) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: ${err instanceof Error ? err.message : String(err)}`,
            },
          ],
          isError: true,
        };
      }
    },
Behavior5/5

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

Annotations indicate idempotentHint=true and destructiveHint=false, but description adds crucial context: this builds an unsigned transaction (not execution), auto-detection behavior for account versions, revert conditions for undercollateralized accounts, and the max_uint256 constraint. No contradictions with annotations.

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?

Four sentences total, front-loaded with core purpose. Each subsequent sentence adds distinct value: authorization constraint, failure mode + input constraint, and parameter override behavior. No redundant or filler text.

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

Completeness5/5

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

Comprehensive for a complex DeFi operation involving multiple asset standards (ERC20/721/1155) and account versions. Covers auth, failure modes, data sourcing, and version handling. Output schema exists per context signals, so return value documentation is not required in description.

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?

With 100% schema coverage, baseline is 3. Description adds specific semantic guidance for asset_amounts (source from read.account.info, no max_uint256) and account_version (auto-detected with optional override). Does not fully explain the parallel array relationships (addresses[i] to amounts[i]), but adds significant value for key parameters.

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?

Description opens with specific verb phrase 'Build an unsigned transaction to withdraw assets' and clearly identifies the resource (Arcadia account) and destination (owner's wallet). Distinct from siblings like deposit, borrow, or swap through explicit 'withdraw' terminology and unsigned transaction builder pattern.

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?

Explicitly states prerequisites ('Only the account owner can withdraw'), failure conditions ('Will revert if...undercollateralized'), and references sibling tool read.account.info for parameter values ('pass exact amounts from read.account.info'). Also clarifies the max_uint256 limitation.

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/arcadia-finance/arcadia-finance-mcp-server'

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