jupiter_swap_build
Get raw swap instructions to construct custom transactions that combine Jupiter swaps with other operations like flash loans or multi-step trades.
Instructions
Get raw swap instructions for custom transaction construction. Use when composing Jupiter swaps with other instructions (flashloans, multi-step). Metis router only.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMint | Yes | Mint address of token to sell | |
| outputMint | Yes | Mint address of token to buy | |
| amount | Yes | Amount in smallest unit | |
| taker | Yes | Wallet address | |
| slippageBps | No | Max slippage in basis points |
Implementation Reference
- src/tools/swap.ts:22-36 (handler)Tool handler for 'jupiter_swap_build'. Calls client.swapBuild() to get raw swap instructions via the Jupiter /swap/v2/build endpoint. Returns the response as formatted JSON.
register( "jupiter_swap_build", "Get raw swap instructions for custom transaction construction. Use when composing Jupiter swaps with other instructions (flashloans, multi-step). Metis router only.", { inputMint: z.string().describe("Mint address of token to sell"), outputMint: z.string().describe("Mint address of token to buy"), amount: z.string().describe("Amount in smallest unit"), taker: z.string().describe("Wallet address"), slippageBps: z.number().optional().describe("Max slippage in basis points"), }, async (args) => { const result = await client.swapBuild(args); return JSON.stringify(result, null, 2); }, ); - src/tools/swap.ts:25-30 (schema)Zod schema defining input parameters for the jupiter_swap_build tool: inputMint, outputMint, amount, taker (all required strings), and optional slippageBps (number).
{ inputMint: z.string().describe("Mint address of token to sell"), outputMint: z.string().describe("Mint address of token to buy"), amount: z.string().describe("Amount in smallest unit"), taker: z.string().describe("Wallet address"), slippageBps: z.number().optional().describe("Max slippage in basis points"), - src/index.ts:40-57 (registration)The 'register' function that registers each tool with the MCP server (via McpServer.tool()). It wraps the handler with error handling and content formatting.
function register( name: string, description: string, shape: Record<string, z.ZodType>, handler: (args: any) => Promise<string>, ) { server.tool(name, description, shape, async (args) => { try { const text = await handler(args); return { content: [{ type: "text" as const, text }] }; } catch (err: any) { return { content: [{ type: "text" as const, text: `Error: ${err.message}` }], isError: true, }; } }); toolCount++; - src/client.ts:82-90 (helper)JupiterClient.swapBuild() — the API client method that sends a GET request to /swap/v2/build with the swap parameters to get raw swap instructions.
async swapBuild(params: { inputMint: string; outputMint: string; amount: string; taker: string; slippageBps?: number; }) { return this.request("/swap/v2/build", { params: params as any }); }