Skip to main content
Glama

ODOS_SWAP

Facilitates token swaps on decentralized exchanges via the MCP-ODOS server by specifying blockchain, tokens, and amount, ensuring efficient cross-token transactions.

Instructions

Execute a swap transaction

Input Schema

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

Implementation Reference

  • The main execute function that implements the ODOS_SWAP tool logic: initializes wallet, fetches quote via GetQuoteActionService, assembles transaction via AssembleService, checks/sets allowance, and executes the swap via ExecuteSwapService.
    execute: async (args: z.infer<typeof swapParamsSchema>) => {
    	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.",
    			);
    		}
    
    		console.log("[ODOS_SWAP] Called...");
    		const inputChain = args.chain.toLowerCase();
    
    		const chainObject = getChainFromName(inputChain);
    
    		const walletService = new WalletService(
    			walletPrivateKey,
    			chainObject ?? fraxtal,
    		);
    
    		console.log(
    			`[ODOS_SWAP] Using chain: ${chainObject} (${chainObject.id})`,
    		);
    		console.log(
    			walletService.getWalletClient()?.account?.address ??
    				"No wallet address found",
    		);
    
    		const getQuoteService = new GetQuoteActionService(walletService);
    		const quote = await getQuoteService.execute(
    			args.fromToken,
    			args.toToken,
    			chainObject.id,
    			args.amount,
    		);
    
    		if (quote instanceof Error || !quote.pathId) {
    			return `Error fetching quote: ${quote instanceof Error ? quote.message : String(quote)}`;
    		}
    
    		const assembleService = new AssembleService(walletService);
    		const txn = await assembleService.execute(quote.pathId);
    		if (!txn) {
    			return `Error assembling transaction: ${txn}`;
    		}
    
    		const executeSwapService = new ExecuteSwapService(walletService);
    
    		try {
    			await executeSwapService.checkAndSetAllowance(
    				quote.inTokens[0],
    				BigInt(quote.inAmounts[0]),
    				txn.to,
    			);
    
    			const hash = await executeSwapService.execute(txn);
    
    			return args.prettyFormat
    				? await executeSwapService.formatWithConfirmation(txn, hash)
    				: JSON.stringify({ hash, txn }, null, 2);
    		} catch (error: unknown) {
    			const message =
    				error instanceof Error
    					? error.message
    					: "An unknown error occurred during the execution.";
    			throw new Error(`Error executing swap: ${message}`);
    		}
    	} catch (error: unknown) {
    		const message =
    			error instanceof Error
    				? error.message
    				: "An unknown error occurred during the fetch.";
    		console.error(`[ODOS_SWAP] Error: ${message}`);
    		throw new Error(`Failed in swap process: ${message}`);
    	}
    },
  • Zod schema defining the input parameters for ODOS_SWAP: chain (default fraxtal), fromToken, toToken addresses, amount in wei, optional prettyFormat.
    const swapParamsSchema = 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:15-15 (registration)
    Registers the swapTool (ODOS_SWAP) with the FastMCP server.
    server.addTool(swapTool);
Behavior2/5

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

With no annotations provided, the description carries full burden but only states 'Execute a swap transaction,' which implies a write/mutation operation. It lacks disclosure of behavioral traits such as authentication needs, rate limits, transaction costs, reversibility, or error handling. This is insufficient for a tool that likely involves blockchain interactions and financial risks.

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 ('Execute a swap transaction') with zero waste. It's appropriately sized and front-loaded, making it easy to parse quickly without unnecessary elaboration.

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 tool's complexity (likely involving blockchain transactions and financial operations), no annotations, and no output schema, the description is incomplete. It doesn't cover return values, error cases, or behavioral nuances, leaving significant gaps for an agent to understand and use the tool safely and effectively.

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 5 parameters (e.g., amount in wei, chain default, token addresses). The description adds no additional meaning beyond the schema, as it doesn't explain parameter interactions or usage context. Baseline 3 is appropriate since the schema handles the heavy lifting.

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

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute a swap transaction' states a clear verb ('Execute') and resource ('swap transaction'), but it's vague about what a 'swap transaction' entails—it doesn't specify token swapping or distinguish it from siblings like ODOS_GET_QUOTE, which likely provides quotes without execution. This is adequate but lacks specificity for differentiation.

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 alternatives. Given siblings ODOS_GET_QUOTE (for quotes) and ODOS_GET_CHAIN_ID (for chain info), the description implies usage for executing swaps but doesn't state prerequisites, exclusions, or direct comparisons, leaving the agent to infer context without explicit direction.

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

Related 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