Skip to main content
Glama

estimate_fees

Calculate bridge and swap fees before execution to compare routes and understand total costs, including gas and relayer fees.

Instructions

Estimate the fees for a bridge or swap without committing to execution. Returns a breakdown of gas fees, relayer fees, and total cost impact. Useful for comparing routes or showing users expected costs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originChainIdYesSource chain ID.
destinationChainIdYesDestination chain ID.
originCurrencyYesOrigin token address. "0x0000000000000000000000000000000000000000" for native.
destinationCurrencyYesDestination token address. "0x0000000000000000000000000000000000000000" for native.
amountYesAmount in the origin token's smallest unit.
senderYesSender wallet address.

Implementation Reference

  • Main handler function that executes the estimate_fees tool. It calls getQuote API, extracts fee details, and returns a formatted response with gas fees, relayer fees, and total cost impact.
    async ({
      originChainId,
      destinationChainId,
      originCurrency,
      destinationCurrency,
      amount,
      sender,
    }) => {
      const quote = await getQuote({
        user: sender,
        originChainId,
        destinationChainId,
        originCurrency,
        destinationCurrency,
        amount,
      });
    
      const { fees, details } = quote;
    
      const summary = `Fee estimate for ${details.currencyIn.amountFormatted} ${details.currencyIn.currency.symbol} → ${details.currencyOut.currency.symbol}: Gas $${fees.gas.amountUsd}, Relayer $${fees.relayer.amountUsd}. Total impact: ${details.totalImpact.percent}% ($${details.totalImpact.usd}).`;
    
      return {
        content: [
          { type: "text", text: summary },
          {
            type: "text",
            text: JSON.stringify(
              {
                gas: {
                  amount: fees.gas.amountFormatted,
                  symbol: fees.gas.currency.symbol,
                  usd: fees.gas.amountUsd,
                },
                relayer: {
                  amount: fees.relayer.amountFormatted,
                  symbol: fees.relayer.currency.symbol,
                  usd: fees.relayer.amountUsd,
                },
                relayerGas: {
                  amount: fees.relayerGas.amountFormatted,
                  usd: fees.relayerGas.amountUsd,
                },
                relayerService: {
                  amount: fees.relayerService.amountFormatted,
                  usd: fees.relayerService.amountUsd,
                },
                totalImpact: details.totalImpact,
                timeEstimateSeconds: details.timeEstimate,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Zod input schema definition for the estimate_fees tool. Validates originChainId, destinationChainId, originCurrency, destinationCurrency, amount, and sender parameters.
    {
      originChainId: z.number().describe("Source chain ID."),
      destinationChainId: z.number().describe("Destination chain ID."),
      originCurrency: z
        .string()
        .describe('Origin token address. "0x0000000000000000000000000000000000000000" for native.'),
      destinationCurrency: z
        .string()
        .describe('Destination token address. "0x0000000000000000000000000000000000000000" for native.'),
      amount: z
        .string()
        .describe("Amount in the origin token's smallest unit."),
      sender: z.string().describe("Sender wallet address."),
    },
  • Tool registration function that registers 'estimate_fees' with the MCP server, including the tool name, description, schema, and handler.
    export function register(server: McpServer) {
      server.tool(
        "estimate_fees",
        "Estimate the fees for a bridge or swap without committing to execution. Returns a breakdown of gas fees, relayer fees, and total cost impact. Useful for comparing routes or showing users expected costs.",
        {
          originChainId: z.number().describe("Source chain ID."),
          destinationChainId: z.number().describe("Destination chain ID."),
          originCurrency: z
            .string()
            .describe('Origin token address. "0x0000000000000000000000000000000000000000" for native.'),
          destinationCurrency: z
            .string()
            .describe('Destination token address. "0x0000000000000000000000000000000000000000" for native.'),
          amount: z
            .string()
            .describe("Amount in the origin token's smallest unit."),
          sender: z.string().describe("Sender wallet address."),
        },
        async ({
          originChainId,
          destinationChainId,
          originCurrency,
          destinationCurrency,
          amount,
          sender,
        }) => {
          const quote = await getQuote({
            user: sender,
            originChainId,
            destinationChainId,
            originCurrency,
            destinationCurrency,
            amount,
          });
    
          const { fees, details } = quote;
    
          const summary = `Fee estimate for ${details.currencyIn.amountFormatted} ${details.currencyIn.currency.symbol} → ${details.currencyOut.currency.symbol}: Gas $${fees.gas.amountUsd}, Relayer $${fees.relayer.amountUsd}. Total impact: ${details.totalImpact.percent}% ($${details.totalImpact.usd}).`;
    
          return {
            content: [
              { type: "text", text: summary },
              {
                type: "text",
                text: JSON.stringify(
                  {
                    gas: {
                      amount: fees.gas.amountFormatted,
                      symbol: fees.gas.currency.symbol,
                      usd: fees.gas.amountUsd,
                    },
                    relayer: {
                      amount: fees.relayer.amountFormatted,
                      symbol: fees.relayer.currency.symbol,
                      usd: fees.relayer.amountUsd,
                    },
                    relayerGas: {
                      amount: fees.relayerGas.amountFormatted,
                      usd: fees.relayerGas.amountUsd,
                    },
                    relayerService: {
                      amount: fees.relayerService.amountFormatted,
                      usd: fees.relayerService.amountUsd,
                    },
                    totalImpact: details.totalImpact,
                    timeEstimateSeconds: details.timeEstimate,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
      );
  • src/index.ts:8-24 (registration)
    Imports the estimate_fees registration and calls it with the MCP server instance to activate the tool.
    import { register as registerEstimateFees } from "./tools/estimate-fees.js";
    import { register as registerExecuteBridge } from "./tools/execute-bridge.js";
    import { register as registerGetTransactionStatus } from "./tools/get-transaction-status.js";
    import { register as registerGetTransactionHistory } from "./tools/get-transaction-history.js";
    import { register as registerGetRelayAppUrl } from "./tools/get-relay-app-url.js";
    import { register as registerWallet } from "./tools/wallet.js";
    
    const server = new McpServer({
      name: "relay-mcp",
      version: "0.1.0",
    });
    
    registerGetSupportedChains(server);
    registerGetSupportedTokens(server);
    registerGetBridgeQuote(server);
    registerGetSwapQuote(server);
    registerEstimateFees(server);
  • Helper function getQuote that makes the actual API call to the Relay API's /quote/v2 endpoint to fetch fee estimates and transaction details.
    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 of behavioral disclosure. It does well by stating this is a non-committal estimation tool (not execution) and describing the return format breakdown. However, it lacks details about potential limitations, error conditions, rate limits, or authentication requirements that would be important for a fee estimation 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 perfectly concise with three sentences that each earn their place: first states the core purpose, second describes the return format, third provides usage context. No wasted words, well-structured and front-loaded with the most important information.

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 fee estimation tool with 6 parameters, 100% schema coverage, and no output schema, the description provides good contextual completeness. It explains the non-execution nature, return format breakdown, and usage scenarios. The main gap is the lack of output schema, but the description compensates by describing the return format ('breakdown of gas fees, relayer fees, and total cost impact').

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 already documents all 6 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, but it does provide context about what the tool does with those parameters (estimating fees for bridges/swaps). This meets the baseline for high schema coverage.

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 tool's purpose with specific verbs ('estimate fees for a bridge or swap') and distinguishes it from execution tools like 'execute_bridge' by emphasizing 'without committing to execution'. It explicitly identifies the resource (fees) and scope (bridge/swap operations).

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 ('useful for comparing routes or showing users expected costs'), which implicitly differentiates it from execution tools. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools like 'get_bridge_quote' or 'get_swap_quote'.

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