Skip to main content
Glama

scan_yields

Identify top DeFi yields from Aave, Compound, Morpho, Lido, Pendle. Filter by chain, asset, minimum TVL. Returns APY, TVL, risk score.

Instructions

Scan top DeFi yield opportunities across protocols: Aave, Compound, Morpho, Lido, Pendle, and more. Filter by chain, asset, and minimum TVL. Returns APY, TVL, risk score, and protocol details. Costs 0.005 USDC per call (x402 micropayment on Base).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoBlockchain to filter by (e.g. "ethereum", "base", "arbitrum", "polygon"). Omit for all chains.
assetNoFilter by asset symbol (e.g. "ETH", "USDC", "stETH"). Omit for all assets.
min_tvlNoMinimum TVL in USD (e.g. 1000000 for $1M). Omit for no minimum.
limitNoMaximum number of results to return (1–50). Defaults to 20.

Implementation Reference

  • src/index.ts:342-372 (registration)
    Tool definition registration for 'scan_yields' — defines the name, description, and input schema (chain, asset, min_tvl, limit) in the TOOLS array.
    {
      name: 'scan_yields',
      description:
        'Scan top DeFi yield opportunities across protocols: Aave, Compound, Morpho, Lido, Pendle, and more. ' +
        'Filter by chain, asset, and minimum TVL. Returns APY, TVL, risk score, and protocol details. ' +
        'Costs 0.005 USDC per call (x402 micropayment on Base).',
      inputSchema: {
        type: 'object',
        properties: {
          chain: {
            type: 'string',
            description:
              'Blockchain to filter by (e.g. "ethereum", "base", "arbitrum", "polygon"). ' +
              'Omit for all chains.',
          },
          asset: {
            type: 'string',
            description: 'Filter by asset symbol (e.g. "ETH", "USDC", "stETH"). Omit for all assets.',
          },
          min_tvl: {
            type: 'number',
            description: 'Minimum TVL in USD (e.g. 1000000 for $1M). Omit for no minimum.',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results to return (1–50). Defaults to 20.',
          },
        },
        required: [],
      },
    },
  • Handler for the 'scan_yields' tool — calls the '/api/yield-scanner' API endpoint with chain, asset, min_tvl, and limit parameters.
    case 'scan_yields':
      result = await callApi('/api/yield-scanner', {
        chain: params.chain,
        asset: params.asset,
        min_tvl: params.min_tvl,
        limit: params.limit,
      });
      break;
  • The callApi helper function that makes HTTP requests to the backend API, used by the scan_yields handler to call /api/yield-scanner.
    async function callApi(
      endpoint: string,
      params: Record<string, string | number | undefined> = {}
    ): Promise<ApiResponse> {
      const url = new URL(`${API_BASE_URL}${endpoint}`);
      for (const [key, value] of Object.entries(params)) {
        if (value !== undefined && value !== '') {
          url.searchParams.set(key, String(value));
        }
      }
    
      const fetchFn = await getX402Fetch();
    
      let response: Response;
      const controller = new AbortController();
      const fetchTimeout = setTimeout(() => controller.abort(), 30_000);
      try {
        response = await fetchFn(url.toString(), {
          headers: {
            'Accept': 'application/json',
            'User-Agent': `x402-api-mcp/${SERVER_VERSION}`,
          },
          signal: controller.signal,
        });
      } catch (err) {
        const isTimeout = err instanceof Error && err.name === 'AbortError';
        throw new McpError(
          ErrorCode.InternalError,
          isTimeout
            ? `Request to ${endpoint} timed out after 30 seconds`
            : `Network error calling ${endpoint}: ${err instanceof Error ? err.message : String(err)}`
        );
      } finally {
        clearTimeout(fetchTimeout);
      }
    
      if (response.status === 402) {
        // Clone before reading so we can fall back to text() if JSON parsing fails.
        // Without the clone, calling response.json() consumes the body; a subsequent
        // response.text() call then throws "body already used".
        const cloned = response.clone();
        let paymentDetails: unknown;
        try {
          paymentDetails = await response.json();
        } catch {
          paymentDetails = await cloned.text();
        }
        return { status: 402, data: null, paymentRequired: true, paymentDetails };
      }
    
      if (!response.ok) {
        const errorText = await response.text();
        if (response.status === 400 || response.status === 422) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Invalid request to ${endpoint}: ${errorText}`
          );
        }
        throw new McpError(
          ErrorCode.InternalError,
          `API error ${response.status} from ${endpoint}: ${errorText}`
        );
      }
    
      const data = await response.json();
      return { status: response.status, data };
    }
  • The formatResult helper function that formats the API response, including handling 402 payment-required responses for scan_yields.
    function formatResult(result: ApiResponse, toolName: string): string {
      if (result.paymentRequired) {
        const details = result.paymentDetails as Record<string, unknown> | null;
        const accepts = details?.accepts as Array<Record<string, unknown>> | undefined;
        const first = accepts?.[0];
    
        let message = `## Payment Required — ${toolName}\n\n`;
        message += `This endpoint requires a USDC micropayment on Base network.\n\n`;
    
        if (first) {
          const amountRaw = Number(first.maxAmountRequired ?? 0);
          const amountUsdc = (amountRaw / 1_000_000).toFixed(6);
          message += `**Cost:** ${amountUsdc} USDC\n`;
          message += `**Pay to:** \`${first.payTo}\`\n`;
          message += `**Network:** Base mainnet (chain ID 8453)\n`;
          message += `**Asset:** USDC (\`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\`)\n\n`;
        }
    
        message += `### To enable automatic payments:\n\n`;
        message += `1. Install dependencies:\n`;
        message += `   \`\`\`bash\n   npm install x402-fetch viem\n   \`\`\`\n\n`;
        message += `2. Set your wallet private key:\n`;
        message += `   \`\`\`bash\n   export X402_WALLET_PRIVATE_KEY=0x...\n   \`\`\`\n\n`;
        message += `3. Restart the MCP server.\n\n`;
        message += `### To pay manually:\n\n`;
        message += `1. Send USDC to the address above on Base (chain ID 8453).\n`;
        message += `2. Encode the payment as Base64 JSON and send it as the \`X-Payment\` header:\n\n`;
        message += `   \`\`\`js\n`;
        message += `   // After sending the transaction on-chain:\n`;
        message += `   const payment = Buffer.from(JSON.stringify({ txHash: "0x<your_tx_hash>", payer: "0x<your_wallet_address>" })).toString("base64");\n`;
        message += `   // Then set the header: X-Payment: <payment>\n`;
        message += `   \`\`\`\n\n`;
        message += `   Or for EIP-3009 transferWithAuthorization (advanced):\n\n`;
        message += `   \`\`\`js\n`;
        message += `   const payment = Buffer.from(JSON.stringify({\n`;
        message += `     signature: "0x...",\n`;
        message += `     payload: {\n`;
        message += `       authorization: {\n`;
        message += `         from: "0x<your_wallet>",\n`;
        message += `         to: "0x<payTo_address>",\n`;
        message += `         value: "<amount_in_micro_usdc>",\n`;
        message += `         validAfter: "0",\n`;
        message += `         validBefore: "<unix_timestamp>",\n`;
        message += `         nonce: "0x<random_32_bytes>"\n`;
        message += `       }\n`;
        message += `     }\n`;
        message += `   })).toString("base64");\n`;
        message += `   \`\`\`\n\n`;
        message += `   **Note:** The \`X-Payment\` header must be Base64-encoded JSON — raw transaction hashes are not accepted.\n\n`;
        message += `---\n**Raw 402 response:**\n\`\`\`json\n`;
        message += JSON.stringify(result.paymentDetails, null, 2);
        message += `\n\`\`\``;
    
        return message;
      }
    
      return JSON.stringify(result.data, null, 2);
    }
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses the cost (0.005 USDC per call) and what the tool returns (APY, TVL, risk score). It is a read operation, and no contradictions exist. Could mention rate limits or data freshness, but sufficient.

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?

Two sentences: first states purpose and protocols, second lists filters, outputs, and cost. Front-loaded with key information, no wasted words.

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 no output schema, the description adequately explains what is returned (APY, TVL, risk score, protocol details) and mentions cost. Could specify ranking logic or data source, but it's reasonably complete for a scanning tool.

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 coverage is 100%, but description adds value by explaining that results include APY, TVL, risk score, and protocol details—information not in the schema. The description reinforces the filter options but does not add new parameter-level details.

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 tool scans top DeFi yields across specific protocols (Aave, Compound, etc.) and lists filtering options and output fields. It distinguishes well from sibling tools covering prices, quotes, and gas.

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

Usage Guidelines4/5

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

The description implies when to use (for DeFi yield opportunities) and lists filters, but does not explicitly state when not to use or compare to alternatives. However, sibling tools are distinct enough to avoid confusion.

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/fernsugi/x402-api-mcp-server'

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