get_swap_price
Calculate token swap prices using aggregated DeFi liquidity across multiple blockchains for informed trading decisions.
Instructions
Get indicative price for a token swap using Aggregator Protocol
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | Yes | Blockchain ID (e.g., 1 for Ethereum) | |
| buyToken | Yes | Contract address of token to buy | |
| sellToken | Yes | Contract address of token to sell | |
| sellAmount | Yes | Amount of sellToken in base units | |
| taker | No | Address executing the trade (optional) |
Implementation Reference
- src/toolService.js:22-38 (handler)Primary MCP tool handler for 'get_swap_price': validates input parameters and delegates to AgService.getSwapPriceasync getSwapPrice(params) { // Validate required parameters const { chainId, buyToken, sellToken, sellAmount } = params; if (!chainId || !buyToken || !sellToken || !sellAmount) { throw new Error( "Missing required parameters: chainId, buyToken, sellToken, sellAmount" ); } const result = await this.agg.getSwapPrice(params); return { message: "Swap price retrieved successfully", data: result, }; }
- src/services/agService.js:9-27 (handler)Core implementation of getSwapPrice: makes HTTP GET request to aggregator API endpoint /api/swap/price with query parametersasync getSwapPrice(params) { try { const queryParams = new URLSearchParams(params); const response = await fetch(`${this.baseUrl}/api/swap/price?${queryParams}`); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'API request failed'); } return data.data; } catch (error) { throw new Error(`Failed to get swap price: ${error.message}`); }
- src/index.js:984-985 (registration)MCP server registration: routes 'get_swap_price' tool calls to ToolService.getSwapPrice methodcase TOOL_NAMES.GET_SWAP_PRICE: result = await toolService.getSwapPrice(args);
- src/index.js:90-119 (schema)Tool specification including name, description, and input schema validation for 'get_swap_price' in MCP ListTools responsename: TOOL_NAMES.GET_SWAP_PRICE, description: "Get indicative price for a token swap using Aggregator Protocol", inputSchema: { type: "object", properties: { chainId: { type: "integer", description: "Blockchain ID (e.g., 1 for Ethereum)", }, buyToken: { type: "string", description: "Contract address of token to buy", }, sellToken: { type: "string", description: "Contract address of token to sell", }, sellAmount: { type: "string", description: "Amount of sellToken in base units", }, taker: { type: "string", description: "Address executing the trade (optional)", }, }, required: ["chainId", "buyToken", "sellToken", "sellAmount"], }, },
- src/constants.js:4-4 (registration)Constant definition mapping TOOL_NAMES.GET_SWAP_PRICE to the tool name string 'get_swap_price' used throughout the codebaseGET_SWAP_PRICE: "get_swap_price",