tapp_get_swap_estimate
Calculate the estimated input or output amount for a token swap on Tapp Exchange, specifying pool, token pair, direction, and amount type.
Instructions
Estimate the amount received or needed for a swap on Tapp Exchange
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a2b | Yes | Swap direction - true for token at pair[0] to pair[1], false for pair[1] to pair[0] | |
| amount | Yes | The amount for estimation (used as input or desired output depending on field) | |
| field | No | Indicates if amount is an 'input' or 'output' amount (defaults to 'input') | |
| pair | Yes | A tuple of token indexes to swap, e.g., [0, 1] means token at index 0 is being swapped for token at index 1 | |
| poolId | Yes | The identifier of the pool |
Implementation Reference
- src/mcp/tapp/swap-tools.ts:15-27 (handler)The MCP tool handler function that parses input and delegates to TappAgent.getEstimateSwapAmount, returning the estimate result.handler: async (agent: TappAgent, input: Record<string, any>) => { const estimate = await agent.getEstimateSwapAmount({ amount: input.amount, poolId: input.poolId, pair: input.pair as [number, number], a2b: input.a2b, field: input.field || 'input' }); return { status: "success", estimate }; },
- src/mcp/tapp/swap-tools.ts:8-14 (schema)Zod-based input schema defining parameters: amount, poolId, pair, a2b, and optional field.schema: { amount: z.number().describe("The amount for estimation (used as input or desired output depending on field)"), poolId: z.string().describe("The identifier of the pool"), pair: z.array(z.number()).describe("A tuple of token indexes to swap, e.g., [0, 1] means token at index 0 is being swapped for token at index 1"), a2b: z.boolean().describe("Swap direction - true for token at pair[0] to pair[1], false for pair[1] to pair[0]"), field: z.enum(['input', 'output']).optional().describe("Indicates if amount is an 'input' or 'output' amount (defaults to 'input')") },
- src/mcp/index.ts:31-31 (registration)The tool is registered in the TappExchangeMcpTools object by mapping the export name to the tool object, which is later iterated to register with MCP server."GetSwapEstimateTool": GetSwapEstimateTool,
- src/agent/index.ts:236-245 (helper)TappAgent helper method that calls the underlying SDK to compute the swap estimate.async getEstimateSwapAmount(params: { amount: number; poolId: string; pair: [number, number]; a2b: boolean; field?: 'input' | 'output'; }): Promise<SwapEstimate> { const result = await this.sdk.Swap.getEstSwapAmount(params); return result; }
- src/index.ts:20-52 (registration)The dynamic registration loop in the MCP server creation that registers the tool using its internal name, description, schema, and wrapped handler.for (const [_key, tool] of Object.entries(TappExchangeMcpTools)) { server.tool(tool.name, tool.description, tool.schema, async (params: any): Promise<any> => { try { // Execute the handler with the params directly const result = await tool.handler(agent, params); // Format the result as MCP tool response return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { console.error("error", error); // Handle errors in MCP format return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error occurred", }, ], }; } }) }