Skip to main content
Glama

QUOTE

Get real-time price quotes for token swaps on decentralized exchanges. Specify token addresses, amount, and slippage to calculate exchange rates across blockchain networks.

Instructions

Quote the price of a specific trading pair

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoThe blockchain network to execute the transaction on. uses fraxtal as defaultfraxtal
inTokenAddressYesThe token to swap from (address).
outTokenAddressYesThe token to swap to (address).
amountYesToken amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6).
slippageNoDefine the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1.1

Implementation Reference

  • The main handler function for the 'QUOTE' tool. It processes input arguments, retrieves chain and gas price information, calls the SwapService to fetch the quote, and returns the result as JSON.
    export const quote = async (args: z.infer<typeof getQuoteParamsSchema>) => {
    	try {
    		const inputChain = args.chain.toLowerCase();
    		const chainObject = getChainFromName(inputChain);
    
    		console.error(`[QUOTE] Using chain: ${chainObject.name}`, args);
    
    		const chainService = new ChainService();
    		const gasRes: any = await chainService.gasPrice(chainObject.id);
    		const gasPrice = gasRes.data.fast;
    
    		const swapService = new SwapService();
    		const quote = await swapService.quote(
    			args.inTokenAddress,
    			args.outTokenAddress,
    			chainObject.id,
    			args.amount,
    			args.slippage ? Number(args.slippage) * 100 : 100,
    			gasPrice,
    		);
    		if (quote instanceof Error) {
    			return `Error fetching quote: ${quote.message}`;
    		}
    
    		// return JSON.stringify(quote);
    		return JSON.stringify(quote, null, 2);
    	} catch (error: unknown) {
    		const message =
    			error instanceof Error
    				? error.message
    				: "An unknown error occurred while fetching quote.";
    		console.error(`[QUOTE] Error: ${message}`);
    		throw new Error(`Failed to fetch quote: ${message}`);
    	}
    };
  • Registration of the 'QUOTE' tool in the tools export object, specifying name, description, parameters schema, and execute function.
    quote: {
    	name: "QUOTE",
    	description: "Quote the price of a specific trading pair",
    	parameters: getQuoteParamsSchema,
    	execute: swapExecute.quote
    },
  • Zod schema defining the input parameters for the 'QUOTE' tool: chain, inTokenAddress, outTokenAddress, amount, slippage.
    export const getQuoteParamsSchema = z.object({
    	chain: z
    		.string()
    		.optional()
    		.describe(
    			"The blockchain network to execute the transaction on. uses fraxtal as default",
    		)
    		.default("fraxtal"),
    	inTokenAddress: z
    		.string()
    		.refine(isAddress, { message: "Invalid inToken address" })
    		.describe("The token to swap from (address)."),
    	outTokenAddress: z
    		.string()
    		.refine(isAddress, { message: "Invalid outToken address" })
    		.describe("The token to swap to (address)."),
    	amount: z
    		.string()
    		.regex(/^\d+$/, { message: "Amount must be a string in wei (no decimals)" })
    		.describe("Token amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6). "),
    	slippage: z
    		.string()
    		.optional()
    		.describe("Define the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1.")
    		.default('1'),
    });
  • The SwapService.quote method, which makes the actual API call to the DEX to retrieve the quote data used by the QUOTE tool handler.
    async quote(
    	inTokenAddress: string,
    	outTokenAddress: string,
    	chainId: number,
    	amount: string,
    	slippage: number,
    	gasPrice: string
    ) {
    	try {
    		const response = await fetch(`${DEX_API_URL}/v2/${chainId}/quote?inTokenAddress=${inTokenAddress}&outTokenAddress=${outTokenAddress}&amount=${amount}&gasPrice=${gasPrice}&slippage=${slippage}&referrer=0xC5d4de874CfE6aac6BC9CAD5Cb6b2B35bd7b8392&flags=4`, {
    			method: "GET",
    			headers: {
    				"Content-Type": "application/json",
    			}
    		});
    
    		const data: any = 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})`,
    			);
    		}
    
    		const { inToken, outToken, inAmount, outAmount, estimatedGas }  = data;
    		return { inToken, outToken, inAmount, outAmount, estimatedGas } 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"
    			}`,
    		);
    	}
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool quotes prices but doesn't describe what the quote includes (e.g., exchange rate, fees, validity period), whether it's a read-only operation, potential rate limits, or error conditions. This leaves significant gaps for a tool that likely interacts with external APIs.

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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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?

Given the complexity of a financial quoting tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the quote output includes (e.g., price, fees, timestamp), how it's calculated, or any behavioral aspects like caching or reliability. This leaves the agent with incomplete information for proper tool invocation.

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?

The schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain relationships between parameters or provide usage examples). With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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 as 'Quote the price of a specific trading pair,' which specifies the verb ('quote') and resource ('price of a specific trading pair'). It distinguishes from siblings like SWAP (which executes trades) and TOKEN_LIST (which lists tokens), but doesn't explicitly differentiate from all siblings (e.g., GAS_PRICE also provides pricing information).

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to use QUOTE instead of SWAP (for execution) or other pricing-related tools like GAS_PRICE, nor does it specify prerequisites or exclusions for usage.

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/openocean-finance/openocean-mcp'

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