Skip to main content
Glama

amazon_search

Search Amazon products by keyword to get an Opportunity Score (0–100) based on demand, rating gap, and price. Identify product opportunities.

Instructions

Search Amazon products by keyword. Returns an Opportunity Score (0–100) for each result based on demand, rating gap, and price.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYesSearch keyword, e.g. 'yoga mat'
marketplaceNoMarketplace: US, UK, DE, CA, AU (default: US)

Implementation Reference

  • The main handler function 'searchAmazon' that executes the amazon_search tool logic. It scrapes Amazon search results using cheerio, parses product data, calculates opportunity scores, and returns an AmazonSearchResult.
    export async function searchAmazon(
      keyword: string,
      marketplace: string = "US"
    ): Promise<AmazonSearchResult> {
      const domain = MARKETPLACE_DOMAINS[marketplace.toUpperCase()] ?? MARKETPLACE_DOMAINS.US;
      const url = `https://${domain}/s?k=${encodeURIComponent(keyword)}`;
    
      const res = await fetch(url, { headers: HEADERS });
    
      if (res.status === 503 || res.status === 429) {
        throw new Error("Amazon rate limited — retry in 30s");
      }
    
      if (!res.ok) {
        throw new Error(`Amazon search failed: HTTP ${res.status}`);
      }
    
      const html = await res.text();
    
      // Detect CAPTCHA / robot check
      if (html.includes("Type the characters you see") || html.includes("robot check")) {
        throw new Error("Amazon rate limited — retry in 30s");
      }
    
      const $ = cheerio.load(html);
      const products: AmazonProduct[] = [];
    
      $('[data-component-type="s-search-result"]').each((_, el) => {
        const $el = $(el);
        const asin = $el.attr("data-asin") ?? "";
        if (!asin) return;
    
        const title = $el.find("h2 a span").first().text().trim();
        const priceWhole = $el.find(".a-price-whole").first().text().trim();
        const priceFraction = $el.find(".a-price-fraction").first().text().trim();
        const priceStr = priceWhole ? `${priceWhole}${priceFraction || "00"}` : null;
        const price = parsePrice(priceStr);
    
        const originalPriceStr = $el.find(".a-text-price .a-offscreen").first().text().trim();
        const original_price = parsePrice(originalPriceStr);
    
        const ratingStr = $el.find(".a-icon-alt").first().text().trim();
        const rating = ratingStr ? parseFloat(ratingStr) : null;
    
        const reviewStr = $el.find('[aria-label*="ratings"] span, .a-size-base.puis-normal-weight-text').first().text().trim();
        const review_count = parseReviewCount(reviewStr);
    
        const seller = $el.find(".a-size-base-plus.a-color-base.s-underline-text").first().text().trim() || "Amazon";
        const prime = $el.find(".s-prime").length > 0;
        const badge = $el.find(".a-badge-text").first().text().trim() || null;
        const image_url = $el.find(".s-image").first().attr("src") ?? null;
    
        const opportunity_score = calculateOpportunityScore({ review_count, rating, price, prime });
    
        products.push({
          asin,
          title,
          price,
          original_price,
          rating,
          review_count,
          seller,
          prime,
          badge,
          image_url,
          url: `https://${domain}/dp/${asin}`,
          opportunity_score,
        });
      });
    
      return {
        keyword,
        marketplace: marketplace.toUpperCase(),
        total_results: products.length,
        products,
        searched_at: new Date().toISOString(),
      };
    }
  • Type definitions for AmazonSearchResult and AmazonProduct interfaces used as the output schema for the amazon_search tool.
    export interface AmazonSearchResult {
      keyword: string;
      marketplace: string;
      total_results: number;
      products: AmazonProduct[];
      searched_at: string;
    }
  • src/mcp-stdio.ts:71-90 (registration)
    Tool registration in the MCP ListTools schema: defines the 'amazon_search' tool name, description, and inputSchema (keyword required, marketplace optional with enum).
    {
      name: "amazon_search",
      description:
        "Search Amazon products by keyword. Returns an Opportunity Score (0–100) for each result based on demand, rating gap, and price.",
      inputSchema: {
        type: "object",
        properties: {
          keyword: {
            type: "string",
            description: "Search keyword, e.g. 'yoga mat'",
          },
          marketplace: {
            type: "string",
            description: "Marketplace: US, UK, DE, CA, AU (default: US)",
            enum: ["US", "UK", "DE", "CA", "AU"],
          },
        },
        required: ["keyword"],
      },
    },
  • Tool call dispatch in the MCP CallTool handler: routes 'amazon_search' requests to the searchAmazon function, extracting keyword and marketplace from arguments.
    case "amazon_search": {
      const { keyword, marketplace } = args as {
        keyword: string;
        marketplace?: string;
      };
      result = await searchAmazon(keyword, marketplace);
      break;
  • Helper function 'calculateOpportunityScore' that computes a 0-100 opportunity score based on review count, rating, price, and Prime availability.
    function calculateOpportunityScore(product: {
      review_count: number | null;
      rating: number | null;
      price: number | null;
      prime: boolean;
    }): number {
      let score = 50; // base
    
      // Review count (demand)
      const reviews = product.review_count ?? 0;
      if (reviews > 10000) score += 20;
      else if (reviews > 1000) score += 15;
      else if (reviews > 100) score += 10;
      else if (reviews > 10) score += 5;
      else score -= 5; // untested market
    
      // Rating (quality gap — lower rating = more room to win)
      const rating = product.rating ?? 4.0;
      if (rating < 3.5) score += 15;
      else if (rating < 4.0) score += 8;
      else if (rating >= 4.5) score -= 5;
    
      // Price sweet spot ($15–$60)
      const price = product.price ?? 0;
      if (price >= 15 && price <= 60) score += 10;
      else if (price > 60) score += 5;
      else score -= 5;
    
      // Prime availability (easier fulfillment)
      if (product.prime) score += 5;
    
      return Math.max(0, Math.min(100, score));
    }
Behavior3/5

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

No annotations are provided, so the description must cover behavioral traits. It discloses the return of an Opportunity Score with factors, but omits details like read-only nature, pagination, rate limits, or authentication needs.

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?

The description is two sentences, front-loaded with the core function, and includes a key output feature in the second sentence. Every word earns its place.

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?

For a simple search tool with 2 params and no output schema, the description adequately states purpose and return score, but lacks details about full return structure (e.g., other product fields). Without output schema, more completeness would be beneficial.

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 coverage is 100%, with both parameters having clear descriptions in the schema (keyword and marketplace with enum). The tool description adds no additional semantic value beyond what the schema provides.

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 searches Amazon products by keyword and returns an Opportunity Score. It distinguishes from siblings like amazon_product (for product details) and Shopif/ maps tools.

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 for searching Amazon products but provides no explicit guidance on when to use this tool versus siblings. No 'when not to use' or alternative recommendations.

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/samrothschild23/intelligence-api'

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