Skip to main content
Glama

swap_build

Build a signable/sendable plan for a swap. This is the tool that does the work — an agent that only knows this tool can execute a swap end to end. Quotes and builds the best route in one call when quoteId is omitted (recommended): a route with GAIN first, re-quoting up to 3 rounds total before accepting one without gain, the same rule as Invoice; pass quoteId from a prior swap_quote to build exactly that route instead. No API key required: pass the wallet that will sign. A machine credential is optional and only raises your limit from the per-IP cap to the credential budget. Four things to hold onto: 1. steps[] are ORDERED and REQUIRED. Skipping an approve step guarantees a revert. 2. If simulation.status is "approval_required", sign/send only the approve step(s), do not report them as the swap execution, then call swap_build again with quoteId set to the quote.id of that build (the approved route; without it a fresh quote may pick another provider whose spender you never approved). If it is "incomplete", do not sign anything: the transaction was never independently verified. 3. If a step has type "signature", there is no transaction and never will be one for that step — what exists afterward is the uid from report_execution, not a hash. 4. If the provider is cowswap and the token sold is the chain's native asset, the transaction only REGISTERS the order — a successful receipt is not a successful swap. Use swap_status, not the receipt, to know what actually happened. 5. routeSwitch, when present, means the route you asked for refused to build (it hit its request limit) and the plan was built with another provider instead: {from, to, reason}. The quote in the plan is the route that will actually be signed. If the user picked that route themselves, say which provider replaced it before they sign.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "chainId": "<chainId>",
      "wallet": "<wallet>"
    },
    "name": "swap_build"
  }
}

Input Schema

NameRequiredDescriptionDefault
amountNoHuman decimal amount, e.g. "100". Use this OR amountRaw, not both.
loteIdNoPaying a batch charge with another token: the loteId from payout_batch, with tokenOut = charge.token and receiver = charge.feeWallet. The guaranteed minimum must stay between the charge and 10% above it.
walletYesWallet that will sign. Required for builds and EVM execution/history calls. On an anonymous EVM quote, pass it to make the returned quoteId executable; without it the quote is indicative.
chainIdYesEVM: integer from GET /v1/chains (1, 10, 56, 100, 137, 8453, 42161, 43114, 130). Solana: string from GET /v1/svm/chains ("solana-mainnet").
quoteIdNoOptional: build exactly this route from a prior swap_quote, instead of quoting fresh.
tokenInNoContract address (Solana: mint), or symbol (case-insensitive). A symbol matching more than one token on this chain fails with ambiguous_token and every candidate — pick the address you meant and retry. On Solana only VERIFIED tokens resolve by symbol, because there anyone can mint a token using another one's symbol; an unverified token has to be named by its mint.
receiverNoOptional: deliver the output to this address instead of the signing wallet. Only providers with supportsReceiver true on the resulting quote honor it — others are left out of quotes[] entirely rather than risk sending to the wrong address. supportsReceiver is present on Solana quotes too, so read it instead of assuming. On Solana, selling into native SOL with a separate destination is refused on every provider (receiver_native_sol_unsupported): closing the wrapped-SOL account sends balance and rent to whoever signs. Ask for wSOL instead. Building with a receiver needs the paying wallet's signed authorization first (destination_challenge, then destination_authorize), or the build fails with destination_not_authorized.
tokenOutNoContract address, or symbol.
amountRawNoRaw integer string in tokenIn's smallest unit.
invoiceIdNoPaying an analysis charge with another token: the invoice id, with receiver = the fee wallet of that charge. Same rule for the minimum.
slippageBpsNoOptional, a sane per-pair default applies when omitted.
maxSlippageBpsNoOptional ceiling, 0-10000, enforced on every future refresh of this build — once set it never loosens.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • addedInput schema / properties / invoiceId
      Added value: +{
      +  "description": "Paying an analysis charge with another token: the invoice id, with receiver = the fee wallet of that charge. Same rule for the minimum.",
      +  "type": "string"
      +}
    • addedInput schema / properties / loteId
      Added value: +{
      +  "description": "Paying a batch charge with another token: the loteId from payout_batch, with tokenOut = charge.token and receiver = charge.feeWallet. The guaranteed minimum must stay between the charge and 10% above it.",
      +  "type": "string"
      +}
  2. Changed1 schema field changed
    • changedInput schema / properties / receiver / description
      Previous value: -"Optional: deliver the output to this address instead of the signing wallet. Only providers with supportsReceiver true on the resulting quote honor it — others are left out of quotes[] entirely rather than risk sending to the wrong address. supportsReceiver is present on Solana quotes too, so read it instead of assuming. On Solana, selling into native SOL with a separate destination is refused on every provider (receiver_native_sol_unsupported): closing the wrapped-SOL account sends balance and rent to whoever signs. Ask for wSOL instead."New value: +"Optional: deliver the output to this address instead of the signing wallet. Only providers with supportsReceiver true on the resulting quote honor it — others are left out of quotes[] entirely rather than risk sending to the wrong address. supportsReceiver is present on Solana quotes too, so read it instead of assuming. On Solana, selling into native SOL with a separate destination is refused on every provider (receiver_native_sol_unsupported): closing the wrapped-SOL account sends balance and rent to whoever signs. Ask for wSOL instead. Building with a receiver needs the paying wallet's signed authorization first (destination_challenge, then destination_authorize), or the build fails with destination_not_authorized."
  3. First observed

TDQS

A4.3/5.0
Behavior4/5

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

With annotations already declaring non-read-only, non-idempotent and open-world behavior, the description still adds substantial context: ordered steps and the revert from skipping an approve step, the signature-step case yielding a uid rather than a hash, the cowswap native-asset registration caveat, and routeSwitch provider substitution. It stops short of describing the overall response shape or rate-limit/credential specifics, which keeps it below a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It is front-loaded with the core purpose and the recommended call shape before the numbered caveats, and nearly every sentence carries actionable content. It is long and dense for a description, and the "Four things to hold onto" header introduces five numbered items, a small structural slip that costs a point.

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?

For a 12-parameter, non-idempotent build tool with no output schema, the description covers the failure modes an agent would otherwise get wrong: step ordering, approval re-entry, signature steps, and route substitution. What it does not cover is the top-level shape of the returned plan beyond steps[], simulation.status and routeSwitch, so an agent still has to infer some of the response surface.

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 the schema carries the per-parameter semantics; the description's notes on quoteId, wallet and the no-API-key requirement largely restate what the schema already documents. It adds modest value by framing quoteId as the mechanism for re-calling after approval, but the 12 parameters' meanings are not extended meaningfully beyond the schema. Baseline 3 applies.

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?

"Build a signable/sendable plan for a swap" states a specific verb and resource, and the text immediately distinguishes it from swap_quote (by explaining the quoteId handoff) and points to swap_status for execution outcome. An agent can tell exactly what this tool produces versus its siblings.

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?

It explicitly recommends omitting quoteId for the one-call quote-and-build path, names the alternative (passing quoteId from swap_quote) and the condition that selects it, and gives a decision procedure for the approval_required and incomplete simulation states. That is as close to when/when-not/alternatives as a description gets.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources