Skip to main content
Glama

ODOS_GET_QUOTE

Retrieve a swap quote for token exchange on a decentralized exchange. Input the from token, to token, and amount in wei to receive a quote.

Instructions

Get a quote for a swap or exchange operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoThe blockchain network to execute the transaction on. uses fraxtal as defaultfraxtal
fromTokenYesThe token to swap from (address).
toTokenYesThe token to swap to (address).
amountYesThe amount of tokens to swap, in wei.
prettyFormatNoWhether to pretty format the quote.

Implementation Reference

  • The main handler for the ODOS_GET_QUOTE tool. It validates env vars, resolves the chain, creates a WalletService, calls GetQuoteActionService.execute() to fetch a quote from the Odos API, and formats the result.
    export const getQuoteTool = {
    	name: "ODOS_GET_QUOTE",
    	description: "Get a quote for a swap or exchange operation",
    	parameters: getQuoteParamsSchema,
    	execute: async (args: z.infer<typeof getQuoteParamsSchema>) => {
    		try {
    			const walletPrivateKey = process.env.WALLET_PRIVATE_KEY;
    			if (!walletPrivateKey) {
    				throw new Error(
    					"WALLET_PRIVATE_KEY is not set in the environment. This is required to execute trades.",
    				);
    			}
    
    			const inputChain = args.chain.toLowerCase();
    
    			const chainObject = getChainFromName(inputChain);
    
    			const walletService = new WalletService(
    				walletPrivateKey,
    				chainObject ?? fraxtal,
    			);
    
    			console.log(
    				`[ODOS_GET_QUOTE] Using chain: ${chainObject} (${chainObject.id})`,
    			);
    			console.log(
    				walletService.getWalletClient()?.account?.address ??
    					"No wallet address found",
    			);
    
    			const service = new GetQuoteActionService(walletService);
    
    			const quote = await service.execute(
    				args.fromToken,
    				args.toToken,
    				chainObject.id,
    				args.amount,
    			);
    			if (quote instanceof Error) {
    				return `Error fetching quote: ${quote.message}`;
    			}
    
    			return args.prettyFormat
    				? service.format(quote)
    				: JSON.stringify(quote, null, 2);
    		} catch (error: unknown) {
    			const message =
    				error instanceof Error
    					? error.message
    					: "An unknown error occurred while fetching quote.";
    			console.error(`[ODOS_GET_QUOTE] Error: ${message}`);
    			throw new Error(`Failed to fetch quote: ${message}`);
    		}
    	},
    };
  • Zod schema defining input parameters for ODOS_GET_QUOTE: chain (defaults to fraxtal), fromToken, toToken (both validated as Ethereum addresses), amount (string in wei), and prettyFormat (boolean, defaults true).
    const getQuoteParamsSchema = z.object({
    	chain: z
    		.string()
    		.optional()
    		.describe(
    			"The blockchain network to execute the transaction on. uses fraxtal as default",
    		)
    		.default("fraxtal"),
    	fromToken: z
    		.string()
    		.refine(isAddress, { message: "Invalid fromToken address" })
    		.describe("The token to swap from (address)."),
    	toToken: z
    		.string()
    		.refine(isAddress, { message: "Invalid toToken address" })
    		.describe("The token to swap to (address)."),
    	amount: z
    		.string()
    		.regex(/^\d+$/, { message: "Amount must be a string in wei (no decimals)" })
    		.describe("The amount of tokens to swap, in wei."),
    	prettyFormat: z
    		.boolean()
    		.optional()
    		.describe("Whether to pretty format the quote.")
    		.default(true),
    });
  • src/index.ts:5-18 (registration)
    Registration of the ODOS_GET_QUOTE tool in the FastMCP server via server.addTool(getQuoteTool).
    import { getQuoteTool } from "./tools/get-quote.js";
    import { swapTool } from "./tools/swap.js";
    
    async function main() {
    	console.log("Initializing MCP Odos Server...");
    
    	const server = new FastMCP({
    		name: "IQAI Odos MCP Server",
    		version: "0.0.1",
    	});
    
    	server.addTool(getQuoteTool);
    	server.addTool(swapTool);
    	server.addTool(chainIdTool);
  • Service class that executes the Odos API quote request (POST to /sor/quote/v2) and formats the QuoteResponse into a human-readable string.
    export class GetQuoteActionService {
    	private readonly walletService: WalletService;
    
    	constructor(walletService: WalletService) {
    		this.walletService = walletService;
    	}
    
    	async execute(
    		fromToken: string,
    		toToken: string,
    		chainId: number,
    		amount: string,
    	) {
    		const userAddr = this.walletService.getWalletClient()?.account?.address;
    
    		if (!userAddr) {
    			throw new Error("User address is not defined");
    		}
    
    		try {
    			const response = await fetch(`${ODOS_API_URL}/sor/quote/v2`, {
    				method: "POST",
    				headers: {
    					"Content-Type": "application/json",
    				},
    				body: JSON.stringify({
    					chainId,
    					userAddr,
    					inputTokens: [
    						{
    							tokenAddress: fromToken,
    							amount,
    						},
    					],
    					outputTokens: [
    						{
    							proportion: 1,
    							tokenAddress: toToken,
    						},
    					],
    					slippageLimitPercent: 0.3,
    					referralCode: 0,
    					disableRFQs: true,
    					compact: true,
    				}),
    			});
    
    			const data = await response.json();
    
    			if (!response.ok) {
    				const errorData = data as ErrorResponse;
    				throw new Error(
    					`Failed to fetch quote: ${errorData.detail} (Trace ID: ${errorData.traceId}, Error Code: ${errorData.errorCode})`,
    				);
    			}
    
    			return data as QuoteResponse;
    		} catch (error) {
    			console.error("Error fetching quote:", error);
    			throw new Error(
    				`Fatally Failed to fetch quote: ${(error as Error).message} with code ${
    					(error as { code?: string }).code || "unknown"
    				}`,
    			);
    		}
    	}
    
    	format(quote: QuoteResponse) {
    		const formattedQuote = dedent`
          💱 Quote Details
          - Input: ${formatUnits(BigInt(quote.inAmounts[0]), 18)} ${quote.inTokens[0]}
          - Output: ${formatUnits(BigInt(quote.outAmounts[0]), 18)} ${quote.outTokens[0]}
          - Price Impact: ${quote.priceImpact ? `${quote.priceImpact?.toFixed(2)}%` : "N/A"}
          - Gas Estimate: ${quote.gasEstimate} (${quote.gasEstimateValue.toFixed(2)} USD)
          - Net Output Value: $${quote.netOutValue.toFixed(2)}
    	  - Deprecated: ${quote.deprecated ? quote.deprecated : "N/A"}
    	  - Partner Fee Percent: ${quote.partnerFeePercent} %
    	  - Path Viz Image: ${quote.pathVizImage ? quote.pathVizImage : "N/A"}
    	  - Path ID: ${quote.pathId ? quote.pathId : "N/A"}
    	  - Block Number: ${quote.blockNumber}
    	  - Percent Diff: ${quote.percentDiff.toFixed(2)}%
    	  - Data Gas Estimate: ${quote.dataGasEstimate} units
    	  - Gwei Per Gas: ${quote.gweiPerGas} gwei
    	  - In Values: ${quote.inValues.map((v) => v.toFixed(2)).join(", ")}
    	  - Out Values: ${quote.outValues.map((v) => v.toFixed(2)).join(", ")}
    	  - other data: ${JSON.stringify(quote, null, 2)}
        `;
    		return formattedQuote;
    	}
    }
Behavior2/5

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

No annotations exist, and the description gives no behavioral details beyond stating it gets a quote. There is no mention of side effects, authentication, rate limits, or whether the operation is read-only.

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?

The description is a single, efficient sentence with no wasted words. However, it could still include more useful information without being verbose.

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

Completeness2/5

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

With no output schema, the description should explain what the tool returns (e.g., a quote object). It does not mention the return format, pagination, or error cases, leaving the agent underinformed.

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 already documents all parameters. The description adds no additional meaning or context for the parameters, such as token address format or amount precision.

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 'Get a quote for a swap or exchange operation' clearly states the verb (Get), resource (quote), and context (swap/exchange). It distinguishes from sibling tools like ODOS_SWAP (which performs the swap) and ODOS_GET_CHAIN_ID (which retrieves chain ID).

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus siblings or alternatives. It does not mention that getting a quote is a prerequisite for swapping, nor does it advise against using it in certain contexts.

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/IQAIcom/mcp-odos'

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