Skip to main content
Glama
baskcart

W3Ship MCP Server

by baskcart

get_swap_quote

Retrieve swap quotes from Uniswap protocols to compare estimated outputs, routing paths, gas fees, and price impact before executing token trades.

Instructions

Get a swap quote from Uniswap. Returns estimated output, routing path, gas fees, and price impact. Supports V2, V3, V4, and UniswapX protocols. Requires UNISWAP_API_KEY env var.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenInYesInput token symbol (ETH, USDC, USDT, DAI, WETH) or contract address
tokenOutYesOutput token symbol (ETH, USDC, USDT, DAI, WETH) or contract address
amountYesAmount of input token to swap (in human-readable units, e.g. "100" for 100 USDC)
walletAddressNoWallet address of the swapper. Uses W3SHIP_PUBLIC_KEY if not provided.
chainIdNoChain ID (default: 8453 for Base)

Implementation Reference

  • The handler logic for 'get_swap_quote' tool, which fetches a quote from the Uniswap API.
    case 'get_swap_quote': {
        if (!UNISWAP_API_KEY) {
            return {
                content: [{ type: 'text', text: 'Error: UNISWAP_API_KEY environment variable is not set. Get your API key at https://developers.uniswap.org' }],
                isError: true,
            };
        }
    
        const { tokenIn: tokenInArg, tokenOut: tokenOutArg, amount: amountArg, walletAddress: swapWallet, chainId: swapChain } = args as any;
        const chainId = swapChain || 8453; // Default to Base
        const wallet = swapWallet || CONFIGURED_KEY;
    
        if (!wallet) {
            return {
                content: [{ type: 'text', text: 'Error: Wallet address required. Set W3SHIP_PUBLIC_KEY or provide walletAddress.' }],
                isError: true,
            };
        }
    
        // Resolve token symbols to addresses
        const resolveToken = (t: string) => {
            const upper = t.toUpperCase();
            return TOKENS[upper]?.address || t;
        };
        const resolveDecimals = (t: string) => {
            const upper = t.toUpperCase();
            return TOKENS[upper]?.decimals || 18;
        };
    
        const tokenInAddr = resolveToken(tokenInArg);
        const tokenOutAddr = resolveToken(tokenOutArg);
        const decimals = resolveDecimals(tokenInArg);
    
        // Convert human-readable amount to wei/smallest unit
        const amountRaw = BigInt(Math.floor(parseFloat(amountArg) * (10 ** decimals))).toString();
    
        try {
            const quoteRes = await fetch(`${UNISWAP_API}/quote`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'x-api-key': UNISWAP_API_KEY,
                },
                body: JSON.stringify({
                    tokenIn: tokenInAddr,
                    tokenOut: tokenOutAddr,
                    amount: amountRaw,
                    type: 'EXACT_INPUT',
                    swapper: wallet,
                    tokenInChainId: chainId,
                    tokenOutChainId: chainId,
                    protocols: ['V2', 'V3', 'V4', 'UNISWAPX'],
                }),
            });
    
            const quoteData = await quoteRes.json() as any;
    
            if (!quoteRes.ok) {
                return {
                    content: [{ type: 'text', text: `Uniswap API error: ${quoteData.errorCode || quoteData.detail || JSON.stringify(quoteData)}` }],
                    isError: true,
                };
            }
    
            // Format output amount
            const outDecimals = resolveDecimals(tokenOutArg);
            const outputRaw = BigInt(quoteData.quote?.amountOut || quoteData.amountOut || '0');
            const outputFormatted = (Number(outputRaw) / (10 ** outDecimals)).toFixed(6);
    
            return {
                content: [{
                    type: 'text',
                    text: JSON.stringify({
                        quote: {
                            tokenIn: tokenInArg.toUpperCase(),
                            tokenOut: tokenOutArg.toUpperCase(),
                            amountIn: amountArg,
                            amountOut: outputFormatted,
                            chainId,
                            gasEstimate: quoteData.quote?.gasEstimate || quoteData.gasEstimate || 'N/A',
                            priceImpact: quoteData.quote?.priceImpact || quoteData.priceImpact || 'N/A',
                            routingPath: quoteData.quote?.route || quoteData.route || [],
                        },
                        message: `Swap ${amountArg} ${tokenInArg.toUpperCase()} → ${outputFormatted} ${tokenOutArg.toUpperCase()} on chain ${chainId}`,
                        needsApproval: quoteData.permit2 ? true : false,
                    }, null, 2)
                }]
            };
        } catch (e: any) {
            return {
                content: [{ type: 'text', text: `Error getting swap quote: ${e.message}` }],
                isError: true,
            };
        }
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Discloses return structure, supported protocol versions, and critical auth requirement (UNISWAP_API_KEY). Implies read-only nature via 'Get' and quote semantics, though could explicitly state it does not execute transactions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four sentences, zero waste. Front-loaded with purpose, followed by returns, capabilities, and requirements. Every clause delivers distinct value (what, output, protocols, auth).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Compensates well for missing output schema by detailing return values (estimated output, routing, gas, impact) and operational requirements. Lacks error handling or rate limit disclosure, which would elevate to 5 for a financial API tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing complete parameter documentation (token symbols/addresses, human-readable amounts, defaults). Description does not add parameter-specific guidance beyond schema, earning baseline 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description opens with specific verb 'Get' and specific resource 'swap quote from Uniswap', clearly distinguishing it from e-commerce siblings like create_order or add_item. Unambiguous scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage context by detailing return values (output, routing, gas, impact) and supported protocols (V2-V4, UniswapX), but lacks explicit when-to-use guidance relative to sibling check_token_approval or which protocol version to select.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/baskcart/w3ship-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server