menese_swap
Swap tokens across 19 blockchain networks using native DEX protocols. Supports Ethereum, Solana, ICP, SUI, Cardano, XRP, and other chains with quote and execute modes.
Instructions
Swap tokens via DEX on supported chains. EVM: Uniswap V3 | Solana: Raydium | ICP: ICPSwap/KongSwap | SUI: Cetus | Cardano: Minswap | XRP: XRPL DEX.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | Chain to swap on | |
| fromToken | Yes | Source token symbol or address | |
| toToken | Yes | Destination token symbol or address | |
| amount | Yes | Amount of fromToken to swap (decimal) | |
| slippageBps | No | Slippage tolerance in basis points (default 250 = 2.5%) | |
| mode | No | 'quote' to preview swap, 'execute' to swap. Default: execute |
Implementation Reference
- src/tools/swap.ts:15-74 (registration)The registerSwapTool function contains the server.registerTool definition for "menese_swap".
export function registerSwapTool( server: McpServer, store: IdentityStore, config: MeneseConfig, ): void { server.registerTool( "menese_swap", { description: "Swap tokens via DEX on supported chains. " + "EVM: Uniswap V3 | Solana: Raydium | ICP: ICPSwap/KongSwap | SUI: Cetus | " + "Cardano: Minswap | XRP: XRPL DEX.", inputSchema: { chain: z.enum(SUPPORTED_CHAINS as unknown as [string, ...string[]]).describe("Chain to swap on"), fromToken: z.string().describe("Source token symbol or address"), toToken: z.string().describe("Destination token symbol or address"), amount: z.string().describe("Amount of fromToken to swap (decimal)"), slippageBps: z.number().min(1).max(5000).optional() .describe("Slippage tolerance in basis points (default 250 = 2.5%)"), mode: z.enum(["quote", "execute"]).optional() .describe("'quote' to preview swap, 'execute' to swap. Default: execute"), }, }, async ({ chain, fromToken, toToken, amount, slippageBps, mode }) => { const identity = store.get(); if (!identity) { return { content: [{ type: "text" as const, text: "No wallet configured. Use menese_setup first." }], isError: true }; } const guard = checkGuard("menese_swap", { chain, fromToken, toToken, amount, slippageBps, mode }, config); if (!guard.allowed) { return { content: [{ type: "text" as const, text: guard.reason! }], isError: true }; } if (mode === "quote") { return { content: [{ type: "text" as const, text: `Ready to swap ${amount} ${fromToken} → ${toToken} on ${chain} (slippage: ${slippageBps ?? 250}bps). Call again with mode "execute" to confirm.`, }], }; } const result = await swapTokensOnChain(config, resolveActorIdentity(store), { chain, fromToken, toToken, amount, slippageBps, }); if (result.ok) { invalidateBalanceCaches(store.getPrincipal()!); } return { content: [{ type: "text" as const, text: JSON.stringify(result, bigIntReplacer, 2), }], }; }, ); } - src/tools/swap.ts:38-72 (handler)The async handler function for "menese_swap", which processes quotes and executes swaps.
async ({ chain, fromToken, toToken, amount, slippageBps, mode }) => { const identity = store.get(); if (!identity) { return { content: [{ type: "text" as const, text: "No wallet configured. Use menese_setup first." }], isError: true }; } const guard = checkGuard("menese_swap", { chain, fromToken, toToken, amount, slippageBps, mode }, config); if (!guard.allowed) { return { content: [{ type: "text" as const, text: guard.reason! }], isError: true }; } if (mode === "quote") { return { content: [{ type: "text" as const, text: `Ready to swap ${amount} ${fromToken} → ${toToken} on ${chain} (slippage: ${slippageBps ?? 250}bps). Call again with mode "execute" to confirm.`, }], }; } const result = await swapTokensOnChain(config, resolveActorIdentity(store), { chain, fromToken, toToken, amount, slippageBps, }); if (result.ok) { invalidateBalanceCaches(store.getPrincipal()!); } return { content: [{ type: "text" as const, text: JSON.stringify(result, bigIntReplacer, 2), }], }; }, - src/tools/swap.ts:27-36 (schema)The inputSchema definition for "menese_swap" using Zod.
inputSchema: { chain: z.enum(SUPPORTED_CHAINS as unknown as [string, ...string[]]).describe("Chain to swap on"), fromToken: z.string().describe("Source token symbol or address"), toToken: z.string().describe("Destination token symbol or address"), amount: z.string().describe("Amount of fromToken to swap (decimal)"), slippageBps: z.number().min(1).max(5000).optional() .describe("Slippage tolerance in basis points (default 250 = 2.5%)"), mode: z.enum(["quote", "execute"]).optional() .describe("'quote' to preview swap, 'execute' to swap. Default: execute"), },