Skip to main content
Glama

check_token_allowance

Verify token spending permissions on Paloma DEX by checking approved allowances between owners and spenders across supported EVM chains.

Instructions

Check token allowance for a specific owner and spender.

Args:
    chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
    token_address: Address of the token
    owner_address: Address of the token owner
    spender_address: Address of the spender (typically Trader contract)

Returns:
    JSON string with allowance information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYes
token_addressYes
owner_addressYes
spender_addressYes

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the core logic for checking ERC20 token allowances on specified EVM chains using Web3.py contract calls.
    async def check_token_allowance(ctx: Context, chain_id: str, token_address: str, owner_address: str, spender_address: str) -> str:
        """Check token allowance for a specific owner and spender.
        
        Args:
            chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
            token_address: Address of the token
            owner_address: Address of the token owner
            spender_address: Address of the spender (typically Trader contract)
        
        Returns:
            JSON string with allowance information.
        """
        try:
            paloma_ctx = ctx.request_context.lifespan_context
            
            if chain_id not in CHAIN_CONFIGS:
                return f"Error: Unsupported chain ID {chain_id}"
            
            config = CHAIN_CONFIGS[chain_id]
            
            if chain_id not in paloma_ctx.web3_clients:
                return f"Error: Web3 client not available for {config.name}"
            
            # Validate addresses
            if not Web3.is_address(token_address):
                return f"Error: Invalid token address: {token_address}"
            
            if not Web3.is_address(owner_address):
                return f"Error: Invalid owner address: {owner_address}"
            
            if not Web3.is_address(spender_address):
                return f"Error: Invalid spender address: {spender_address}"
            
            web3 = paloma_ctx.web3_clients[chain_id]
            token_contract = web3.eth.contract(address=token_address, abi=ERC20_ABI)
            
            # Get allowance and token info
            allowance = token_contract.functions.allowance(owner_address, spender_address).call()
            
            try:
                token_symbol = token_contract.functions.symbol().call()
                token_decimals = token_contract.functions.decimals().call()
                balance = token_contract.functions.balanceOf(owner_address).call()
            except:
                token_symbol = "Unknown"
                token_decimals = 18
                balance = 0
            
            allowance_display = float(allowance) / (10 ** token_decimals)
            balance_display = float(balance) / (10 ** token_decimals)
            
            result = {
                "chain": config.name,
                "chain_id": config.chain_id,
                "token": {
                    "address": token_address,
                    "symbol": token_symbol,
                    "decimals": token_decimals
                },
                "owner_address": owner_address,
                "spender_address": spender_address,
                "allowance": {
                    "wei": str(allowance),
                    "display": str(allowance_display),
                    "is_unlimited": allowance == MAX_AMOUNT
                },
                "owner_balance": {
                    "wei": str(balance),
                    "display": str(balance_display)
                },
                "needs_approval": allowance == 0,
                "sufficient_allowance": allowance >= balance if balance > 0 else True
            }
            
            return json.dumps(result, indent=2)
            
        except Exception as e:
            logger.error(f"Error checking token allowance: {e}")
            return f"Error checking token allowance: {str(e)}"
  • Minimal ERC20 ABI including the allowance(), balanceOf(), decimals(), and symbol() functions used by the check_token_allowance handler to query contract state.
    ERC20_ABI = [
        {
            "constant": True,
            "inputs": [{"name": "_owner", "type": "address"}],
            "name": "balanceOf",
            "outputs": [{"name": "balance", "type": "uint256"}],
            "type": "function"
        },
        {
            "constant": True,
            "inputs": [],
            "name": "decimals",
            "outputs": [{"name": "", "type": "uint8"}],
            "type": "function"
        },
        {
            "constant": True,
            "inputs": [],
            "name": "symbol",
            "outputs": [{"name": "", "type": "string"}],
            "type": "function"
        },
        {
            "constant": False,
            "inputs": [
                {"name": "spender", "type": "address"},
                {"name": "amount", "type": "uint256"}
            ],
            "name": "approve",
            "outputs": [{"name": "", "type": "bool"}],
            "type": "function"
        },
        {
            "constant": True,
            "inputs": [
                {"name": "owner", "type": "address"},
                {"name": "spender", "type": "address"}
            ],
            "name": "allowance",
            "outputs": [{"name": "", "type": "uint256"}],
            "type": "function"
        }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool checks allowance and returns JSON, but lacks details on error handling, rate limits, authentication needs, or whether it's read-only (though implied by 'check'). For a tool with no annotations, this leaves significant behavioral gaps.

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

Conciseness4/5

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

The description is well-structured with a purpose statement followed by Args and Returns sections. It's front-loaded and efficient, though the 'Args' and 'Returns' labels are slightly redundant given the schema context. Every sentence adds value without waste.

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

Completeness3/5

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

Given no annotations, 0% schema coverage, and no output schema, the description does a decent job covering purpose and parameters. However, it lacks details on return structure (beyond 'JSON string'), error cases, or operational constraints, making it incomplete for a tool with four required parameters and no structured output.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It provides clear semantic meaning for all four parameters (e.g., 'chain_id' with specific values, 'owner_address' as token owner, 'spender_address' as typically Trader contract), adding essential context beyond the bare schema. However, it doesn't specify formats (e.g., address validation) or optionality.

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?

The description clearly states the specific action ('check token allowance') and identifies the key resources (owner and spender). It distinguishes this tool from siblings like 'approve_token_spending' (which sets allowance) and 'get_address_balances' (which checks balances rather than allowances).

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?

The description implies usage context by specifying 'typically Trader contract' for the spender, suggesting when this tool might be relevant. However, it doesn't explicitly state when to use this vs. alternatives like 'get_address_balances' or 'approve_token_spending', nor does it provide exclusion criteria or prerequisites.

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/VolumeFi/mcpPADEX'

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