Skip to main content
Glama

build_swap

Create unsigned swap transactions for token exchanges on the Casper Network. Specify input/output tokens, amounts, and slippage to generate deploy JSON for external signing.

Instructions

Build an unsigned swap transaction. Returns the deploy JSON for external signing, plus a human-readable summary.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token_inYesInput token: symbol (e.g., "CSPR"), name, or contract hash
token_outYesOutput token: symbol (e.g., "USDT"), name, or contract hash
amountYesHuman-readable amount (e.g., "100")
typeYes"exact_in" or "exact_out"
slippage_bpsNoSlippage tolerance in basis points (default 300 = 3%)
deadline_minutesNoTransaction deadline in minutes (default 20)
sender_public_keyYesSender hex public key (e.g., "01abc...")
token_in_balanceNoRaw input token balance for one-time approval (e.g., from wallet). If omitted, approves exact swap amount only.

Implementation Reference

  • The tool `build_swap` is registered here, defining its input schema (zod) and the handler function that calls `client.buildSwap`.
    server.tool(
      'build_swap',
      'Build an unsigned swap transaction. Returns the deploy JSON for external signing, plus a human-readable summary.',
      {
        token_in: z.string().describe('Input token: symbol (e.g., "CSPR"), name, or contract hash'),
        token_out: z.string().describe('Output token: symbol (e.g., "USDT"), name, or contract hash'),
        amount: z.string().describe('Human-readable amount (e.g., "100")'),
        type: z.enum(['exact_in', 'exact_out']).describe('"exact_in" or "exact_out"'),
        slippage_bps: z.number().optional().describe('Slippage tolerance in basis points (default 300 = 3%)'),
        deadline_minutes: z.number().optional().describe('Transaction deadline in minutes (default 20)'),
        sender_public_key: z.string().describe('Sender hex public key (e.g., "01abc...")'),
        token_in_balance: z.string().optional().describe('Raw input token balance for one-time approval (e.g., from wallet). If omitted, approves exact swap amount only.'),
      },
      async (args) => {
        const bundle = await client.buildSwap({
          tokenIn: args.token_in,
          tokenOut: args.token_out,
          amount: args.amount,
          type: args.type,
          slippageBps: args.slippage_bps,
          deadlineMinutes: args.deadline_minutes,
          senderPublicKey: args.sender_public_key,
          tokenInBalance: args.token_in_balance,
        });
    
        const parts = [bundle.summary];
        if (bundle.warnings.length > 0) {
          parts.push('\nWARNINGS:\n' + bundle.warnings.join('\n'));
        }
    
        // Write approval transactions first, then the main swap
        if (bundle.approvalsRequired?.length) {
          parts.push('\n--- APPROVAL REQUIRED ---');
          for (let i = 0; i < bundle.approvalsRequired.length; i++) {
            const approval = bundle.approvalsRequired[i];
            const approvalPath = await writeDeployFile(approval.transactionJson);
            parts.push(`\nStep ${i + 1}: ${approval.summary}`);
            parts.push(`Approval transaction saved to: ${approvalPath}`);
            parts.push(`Gas: ${approval.estimatedGasCost}`);
          }
          parts.push('\n--- SWAP TRANSACTION ---');
        }
    
        const deployPath = await writeDeployFile(bundle.transactionJson);
        parts.push(`\nSwap transaction saved to: ${deployPath}`);
    
        if (bundle.approvalsRequired?.length) {
          parts.push('\nWorkflow: Sign and submit each approval with submit_transaction, then sign and submit the swap with submit_transaction.');
        } else {
          parts.push('Pass this path to sign_deploy, then use submit_transaction.');
        }
    
        return { content: [{ type: 'text' as const, text: parts.join('\n') }] };
      },
    );
Behavior3/5

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

With no annotations, description carries full burden. It discloses 'unsigned' nature (no state change yet), output format ('deploy JSON'), and bonus output ('human-readable summary'). However, misses critical behavioral context: that this doesn't submit to blockchain, approval mechanics via token_in_balance, error conditions (slippage), or that returned JSON requires subsequent signing.

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?

Two sentences, zero waste. First sentence states core purpose immediately. Second sentence describes outputs. Every word earns its place; properly front-loaded with no redundant filler.

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

Completeness3/5

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

Given 100% schema coverage, the description adequately covers the return values (compensating for no output schema). However, for a complex DeFi tool with 8 parameters involving slippage, deadlines, and approvals, the description lacks workflow context (e.g., that approval may be needed first, or that this is step 1 of 2 in swap execution).

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

Parameters3/5

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

Schema coverage is 100%, so baseline score applies. Description provides high-level context ('swap transaction') that helps interpret parameter relationships, but doesn't add syntax, format details, or parameter-specific guidance beyond what the schema already documents.

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?

Clear specific verb ('Build') + resource ('unsigned swap transaction') + scope. Distinguishes from siblings: vs 'get_quote' (this builds executable tx), vs 'submit_transaction' (this returns unsigned for external signing), vs 'build_add_liquidity' (different operation).

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

Usage Guidelines3/5

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

Implies usage context via 'for external signing', suggesting use when handling signing outside the tool. However, lacks explicit 'when to use vs alternatives' (e.g., 'use submit_transaction instead to auto-submit') or workflow prerequisites (e.g., 'call get_quote first').

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/make-software/cspr-trade-mcp'

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