get_swap_price
Retrieve indicative token swap prices using Aggregator Protocol for efficient DeFi trading. Specify chain ID, buy/sell tokens, and sell amount to analyze trade opportunities across multiple blockchains.
Instructions
Get indicative price for a token swap using Aggregator Protocol
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| buyToken | Yes | Contract address of token to buy | |
| chainId | Yes | Blockchain ID (e.g., 1 for Ethereum) | |
| sellAmount | Yes | Amount of sellToken in base units | |
| sellToken | Yes | Contract address of token to sell | |
| taker | No | Address executing the trade (optional) |
Input Schema (JSON Schema)
{
"properties": {
"buyToken": {
"description": "Contract address of token to buy",
"type": "string"
},
"chainId": {
"description": "Blockchain ID (e.g., 1 for Ethereum)",
"type": "integer"
},
"sellAmount": {
"description": "Amount of sellToken in base units",
"type": "string"
},
"sellToken": {
"description": "Contract address of token to sell",
"type": "string"
},
"taker": {
"description": "Address executing the trade (optional)",
"type": "string"
}
},
"required": [
"chainId",
"buyToken",
"sellToken",
"sellAmount"
],
"type": "object"
}
Implementation Reference
- src/services/agService.js:9-28 (handler)Core handler function that executes the tool logic: constructs query params and fetches indicative swap price from Aggregator Protocol API endpoint /api/swap/priceasync 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/toolService.js:22-38 (handler)ToolService wrapper handler: validates input parameters and delegates to AgService.getSwapPrice, formats response for MCPasync 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/index.js:90-119 (schema)Input/output schema definition for the get_swap_price tool in MCP ListToolsRequestHandlername: 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/index.js:984-986 (registration)MCP CallToolRequestHandler registration: switch case dispatching get_swap_price tool calls to ToolService.getSwapPricecase TOOL_NAMES.GET_SWAP_PRICE: result = await toolService.getSwapPrice(args); break;
- src/constants.js:4-4 (registration)Tool name constant definition used in registration and schemaGET_SWAP_PRICE: "get_swap_price",