Skip to main content
Glama
baskcart

W3Ship MCP Server

by baskcart

check_token_approval

Verify token approval status for Uniswap swaps. Determines if approval is required and provides the approval transaction when needed.

Instructions

Check if a token is approved for swapping on Uniswap. Returns whether approval is needed and the approval transaction if so. Requires UNISWAP_API_KEY env var.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesToken symbol (USDC, USDT, DAI, WETH) or contract address
amountYesAmount to approve (in human-readable units)
walletAddressNoWallet address. Uses W3SHIP_PUBLIC_KEY if not provided.
chainIdNoChain ID (default: 8453 for Base)

Implementation Reference

  • The handler implementation for the check_token_approval tool in src/index.ts.
    case 'check_token_approval': {
        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 { token: tokenArg, amount: approveAmount, walletAddress: approveWallet, chainId: approveChain } = args as any;
        const appChainId = approveChain || 8453;
        const appWallet = approveWallet || CONFIGURED_KEY;
    
        if (!appWallet) {
            return {
                content: [{ type: 'text', text: 'Error: Wallet address required. Set W3SHIP_PUBLIC_KEY or provide walletAddress.' }],
                isError: true,
            };
        }
    
        const resolveTokenAddr = (t: string) => {
            const upper = t.toUpperCase();
            return TOKENS[upper]?.address || t;
        };
        const resolveTokenDec = (t: string) => {
            const upper = t.toUpperCase();
            return TOKENS[upper]?.decimals || 18;
        };
    
        const tokenAddr = resolveTokenAddr(tokenArg);
        const tokenDec = resolveTokenDec(tokenArg);
        const approveAmountRaw = BigInt(Math.floor(parseFloat(approveAmount) * (10 ** tokenDec))).toString();
    
        try {
            const approvalRes = await fetch(`${UNISWAP_API}/check_approval`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'x-api-key': UNISWAP_API_KEY,
                },
                body: JSON.stringify({
                    token: tokenAddr,
                    amount: approveAmountRaw,
                    walletAddress: appWallet,
                    chainId: appChainId,
                }),
            });
    
            const approvalData = await approvalRes.json() as any;
    
            if (!approvalRes.ok) {
                return {
                    content: [{ type: 'text', text: `Uniswap API error: ${approvalData.errorCode || JSON.stringify(approvalData)}` }],
                    isError: true,
                };
            }
    
            return {
                content: [{
                    type: 'text',
                    text: JSON.stringify({
                        token: tokenArg.toUpperCase(),
                        amount: approveAmount,
                        chainId: appChainId,
                        approved: approvalData.approved || false,
                        approvalNeeded: !approvalData.approved,
                        approvalTransaction: approvalData.approvalTransaction || null,
                        message: approvalData.approved
                            ? `${tokenArg.toUpperCase()} is already approved for swapping`
                            : `${tokenArg.toUpperCase()} needs approval before swapping. Transaction data provided.`,
                    }, null, 2)
                }]
            };
        } catch (e: any) {
            return {
                content: [{ type: 'text', text: `Error checking approval: ${e.message}` }],
                isError: true,
            };
        }
    }
  • src/index.ts:236-248 (registration)
    Tool registration for check_token_approval in src/index.ts.
        name: 'check_token_approval',
        description: 'Check if a token is approved for swapping on Uniswap. Returns whether approval is needed and the approval transaction if so. Requires UNISWAP_API_KEY env var.',
        inputSchema: {
            type: 'object',
            properties: {
                token: { type: 'string', description: 'Token symbol (USDC, USDT, DAI, WETH) or contract address' },
                amount: { type: 'string', description: 'Amount to approve (in human-readable units)' },
                walletAddress: { type: 'string', description: 'Wallet address. Uses W3SHIP_PUBLIC_KEY if not provided.' },
                chainId: { type: 'number', description: 'Chain ID (default: 8453 for Base)' },
            },
            required: ['token', 'amount'],
        },
    },
Behavior3/5

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

No annotations provided, so description carries full burden. Successfully discloses return values ('whether approval is needed and the approval transaction') and environment requirement. However, lacks safety profile (read-only vs. state-changing), rate limits, or error handling behavior.

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?

Three sentences with zero waste: purpose statement, return value disclosure, and prerequisite warning. Front-loaded with specific action verb and efficiently structured.

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?

Given 100% input schema coverage and no output schema, the description adequately covers return behavior textually and documents the API key requirement. Minor gap: lacks safety classification (destructive vs. safe) which annotations would normally provide.

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%, establishing baseline 3. Description does not add parameter-specific semantics (e.g., valid token formats, amount precision), but the comprehensive schema makes this acceptable.

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?

Specific verb 'Check' + resource 'token approval' + domain 'Uniswap' provides clear purpose. Effectively distinguishes from sibling 'get_swap_quote' and non-crypto tools like 'create_cart' by specifying the Uniswap swapping context.

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 workflow context ('for swapping') and prerequisite (UNISWAP_API_KEY), but lacks explicit when-to-use guidance versus sibling 'get_swap_quote' or confirmation that this should be called before executing swaps. No exclusion criteria provided.

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