Skip to main content
Glama

get_swap_quote

Obtain token swap quotes across blockchain networks, including estimated output amounts, fees, and transaction time estimates for cross-chain or same-chain token exchanges.

Instructions

Get a quote for swapping between different tokens, optionally across chains (e.g. ETH on Ethereum → USDC on Base, or USDC → WETH on the same chain). Returns estimated output amount, fees, and time estimate.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originChainIdYesSource chain ID (e.g. 1 for Ethereum).
destinationChainIdYesDestination chain ID. Can be the same as originChainId for same-chain swaps.
originCurrencyYesToken address to swap from. Use "0x0000000000000000000000000000000000000000" for native ETH.
destinationCurrencyYesToken address to swap to. Use "0x0000000000000000000000000000000000000000" for native ETH.
amountYesAmount to swap in the origin token's smallest unit (wei for ETH).
senderYesSender wallet address.
recipientNoRecipient wallet address. Defaults to sender.

Implementation Reference

  • Main implementation of the get_swap_quote tool. Contains the handler function that fetches quotes, processes the response, formats output, and returns structured content with summary, JSON details, and deeplink resources.
    export function register(server: McpServer) {
      server.tool(
        "get_swap_quote",
        "Get a quote for swapping between different tokens, optionally across chains (e.g. ETH on Ethereum → USDC on Base, or USDC → WETH on the same chain). Returns estimated output amount, fees, and time estimate.",
        {
          originChainId: z
            .number()
            .describe("Source chain ID (e.g. 1 for Ethereum)."),
          destinationChainId: z
            .number()
            .describe(
              "Destination chain ID. Can be the same as originChainId for same-chain swaps."
            ),
          originCurrency: z
            .string()
            .describe(
              'Token address to swap from. Use "0x0000000000000000000000000000000000000000" for native ETH.'
            ),
          destinationCurrency: z
            .string()
            .describe(
              'Token address to swap to. Use "0x0000000000000000000000000000000000000000" for native ETH.'
            ),
          amount: z
            .string()
            .describe(
              "Amount to swap in the origin token's smallest unit (wei for ETH)."
            ),
          sender: z.string().describe("Sender wallet address."),
          recipient: z
            .string()
            .optional()
            .describe("Recipient wallet address. Defaults to sender."),
        },
        async ({
          originChainId,
          destinationChainId,
          originCurrency,
          destinationCurrency,
          amount,
          sender,
          recipient,
        }) => {
          const quote = await getQuote({
            user: sender,
            originChainId,
            destinationChainId,
            originCurrency,
            destinationCurrency,
            amount,
            recipient,
          });
    
          const { details, fees } = quote;
          const isCrossChain = originChainId !== destinationChainId;
          const action = isCrossChain ? "Cross-chain swap" : "Swap";
          const summary = `${action}: ${details.currencyIn.amountFormatted} ${details.currencyIn.currency.symbol} (chain ${originChainId}) → ${details.currencyOut.amountFormatted} ${details.currencyOut.currency.symbol} (chain ${destinationChainId}). Total fees: $${fees.relayer.amountUsd}. ETA: ~${details.timeEstimate}s.`;
    
          const deeplinkUrl = await buildRelayAppUrl({
            destinationChainId,
            fromChainId: originChainId,
            fromCurrency: originCurrency,
            toCurrency: destinationCurrency,
            amount: details.currencyIn.amountFormatted,
            toAddress: recipient || sender,
          });
    
          const content: Array<Record<string, unknown>> = [
            { type: "text", text: summary },
            {
              type: "text",
              text: JSON.stringify(
                {
                  amountIn: details.currencyIn.amountFormatted,
                  amountOut: details.currencyOut.amountFormatted,
                  amountInUsd: details.currencyIn.amountUsd,
                  amountOutUsd: details.currencyOut.amountUsd,
                  fees: {
                    gas: { formatted: fees.gas.amountFormatted, usd: fees.gas.amountUsd },
                    relayer: { formatted: fees.relayer.amountFormatted, usd: fees.relayer.amountUsd },
                  },
                  totalImpact: details.totalImpact,
                  timeEstimateSeconds: details.timeEstimate,
                  rate: details.rate,
                  relayAppUrl: deeplinkUrl ?? undefined,
                },
                null,
                2
              ),
            },
          ];
    
          if (deeplinkUrl) {
            content.push({
              type: "resource_link",
              uri: deeplinkUrl,
              name: "Execute swap on Relay",
              description: "Open the Relay app to sign and execute this swap",
              mimeType: "text/html",
            });
            content.push({
              type: "text",
              text: `To execute this swap, open the Relay app: ${deeplinkUrl}`,
            });
          }
    
          return { content };
        }
      );
    }
  • Input schema validation using Zod. Defines required parameters: originChainId, destinationChainId, originCurrency, destinationCurrency, amount, sender, and optional recipient.
    {
      originChainId: z
        .number()
        .describe("Source chain ID (e.g. 1 for Ethereum)."),
      destinationChainId: z
        .number()
        .describe(
          "Destination chain ID. Can be the same as originChainId for same-chain swaps."
        ),
      originCurrency: z
        .string()
        .describe(
          'Token address to swap from. Use "0x0000000000000000000000000000000000000000" for native ETH.'
        ),
      destinationCurrency: z
        .string()
        .describe(
          'Token address to swap to. Use "0x0000000000000000000000000000000000000000" for native ETH.'
        ),
      amount: z
        .string()
        .describe(
          "Amount to swap in the origin token's smallest unit (wei for ETH)."
        ),
      sender: z.string().describe("Sender wallet address."),
      recipient: z
        .string()
        .optional()
        .describe("Recipient wallet address. Defaults to sender."),
    },
  • src/index.ts:7-7 (registration)
    Import statement for the get_swap_quote tool registration function.
    import { register as registerGetSwapQuote } from "./tools/get-swap-quote.js";
  • src/index.ts:23-23 (registration)
    Registration call that registers the get_swap_quote tool with the MCP server instance.
    registerGetSwapQuote(server);
  • Helper function getQuote that makes a POST request to the Relay API /quote/v2 endpoint to fetch swap quotes with all necessary parameters.
    export async function getQuote(params: QuoteRequest): Promise<QuoteResponse> {
      return relayApi<QuoteResponse>("/quote/v2", {
        method: "POST",
        body: {
          ...params,
          tradeType: params.tradeType || "EXACT_INPUT",
        },
      });
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it's a read-only operation (returns a quote, not executes), outputs estimated amounts/fees/time, and supports cross-chain swaps. However, it lacks details on rate limits, error conditions, or authentication needs, which are important for a financial tool.

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?

The description is efficiently structured in two sentences: the first states the purpose and scope with helpful examples, and the second specifies the return values. Every sentence adds critical information with zero waste, making it easy to parse.

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 the complexity (cross-chain swaps, 7 parameters) and no annotations/output schema, the description is reasonably complete: it covers purpose, scope, and return values. However, it could improve by mentioning prerequisites (e.g., wallet connectivity) or error handling, which would be valuable for an agent.

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 description coverage is 100%, so the schema fully documents all 7 parameters. The description adds minimal value beyond the schema—it mentions 'optionally across chains' which aligns with destinationChainId, but doesn't explain parameter interactions or provide additional semantics. Baseline 3 is appropriate when schema does the heavy lifting.

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 specific action ('Get a quote for swapping'), identifies the resources involved ('different tokens'), and distinguishes it from siblings like 'execute_bridge' (which performs the actual swap) and 'get_bridge_quote' (which is for bridging, not swapping). The examples ('ETH on Ethereum → USDC on Base') provide concrete differentiation.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('for swapping between different tokens, optionally across chains') and implies alternatives through sibling tool names like 'execute_bridge' (for execution) and 'get_bridge_quote' (for bridging quotes). However, it does not explicitly state when NOT to use it or directly compare to these alternatives.

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/relayprotocol/relay-mcp'

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