Skip to main content
Glama

enrich_product

Extract structured product data from URLs, including name, price, brand, images, and availability using schema.org and AI fallback.

Instructions

Extract comprehensive product data from a URL including name, price, brand, images, availability, and more. Uses schema.org structured data when available, with LLM fallback. Costs $0.02 per call (cached results are free).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesProduct page URL to extract data from
payment_method_idNoStripe payment method ID for MPP payment

Implementation Reference

  • src/server.ts:22-32 (registration)
    The 'enrich_product' tool is registered on the McpServer, accepting a URL and optional payment method, then calling handleEnrichment.
    server.tool(
      'enrich_product',
      'Extract comprehensive product data from a URL including name, price, brand, images, availability, and more. Uses schema.org structured data when available, with LLM fallback. Costs $0.02 per call (cached results are free).',
      {
        url: z.string().url().describe('Product page URL to extract data from'),
        payment_method_id: z.string().optional().describe('Stripe payment method ID for MPP payment'),
      },
      async ({ url, payment_method_id }) => {
        return handleEnrichment('enrich_product', url, payment_method_id, cache, payments);
      },
    );
  • The handleEnrichment function handles the logic for 'enrich_product', including caching, payment gating, and extracting product data using extractProduct.
    async function handleEnrichment(
      toolName: 'enrich_product' | 'enrich_basic',
      url: string,
      paymentMethodId: string | undefined,
      cache: EnrichmentCache,
      payments: PaymentManager,
    ): Promise<{ content: Array<{ type: 'text'; text: string }>; isError?: boolean }> {
      // Check cache first (free, no payment needed)
      const cached = cache.get(url);
      if (cached) {
        const result: EnrichmentResult = {
          product: cached,
          cached: true,
        };
        return {
          content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
        };
      }
    
      // No payment method — return 402 challenge
      if (!paymentMethodId) {
        const challenge: MppChallenge = payments.createChallenge(toolName);
        return {
          content: [{
            type: 'text' as const,
            text: JSON.stringify({
              error: 'payment_required',
              status: 402,
              challenge,
              message: `Payment required. Include a payment_method_id to proceed. Cost: $${(TOOL_PRICING[toolName] / 100).toFixed(2)}`,
            }, null, 2),
          }],
          isError: true,
        };
      }
    
      // Process payment
      let receipt;
      try {
        receipt = await payments.processPayment(toolName, paymentMethodId);
      } catch (err) {
        const message = err instanceof Error ? err.message : 'Payment processing failed';
        return {
          content: [{
            type: 'text' as const,
            text: JSON.stringify({ error: 'payment_failed', message }, null, 2),
          }],
          isError: true,
        };
      }
    
      // Extract product data
      let product: ProductData;
      try {
        product = await extractProduct(url);
      } catch (err) {
        const message = err instanceof Error ? err.message : 'Extraction failed';
        return {
          content: [{
            type: 'text' as const,
            text: JSON.stringify({
              error: 'extraction_failed',
              message,
              receipt,
            }, null, 2),
          }],
          isError: true,
        };
      }
    
      // For basic enrichment, strip image analysis fields
      if (toolName === 'enrich_basic') {
        product.image_urls = [];
        product.primary_image_url = null;
      }
    
      // Cache the result
      cache.set(url, product);
    
      const result: EnrichmentResult = {
        product,
        receipt,
        cached: false,
      };
    
      return {
        content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
      };
    }
Behavior4/5

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

No annotations provided, so description carries full behavioral burden. Excellently discloses cost model (price per call, caching behavior) and extraction methodology (structured data priority with AI fallback). Missing: rate limits, timeout behavior, or failure modes when extraction fails.

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: (1) Function and data scope, (2) Technical implementation, (3) Cost model. Front-loaded with the core value proposition. Every word serves selection or invocation logic.

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 enumerating expected return fields (name, price, brand, etc.). Input schema is simple (2 params) and fully documented. Could be improved with error behavior description or return format specification.

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% (both parameters documented), establishing baseline 3. Description adds significant value by contextualizing the URL as a product page requiring comprehensive extraction, and the cost disclosure ($0.02) implicitly explains the purpose of payment_method_id without duplicating schema text.

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 ('Extract') plus explicit resource ('product data from a URL') with concrete field enumeration (name, price, brand, images, availability). The term 'comprehensive' effectively distinguishes this from sibling 'enrich_basic', clearly positioning this as the richer alternative.

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?

Provides crucial usage context through pricing disclosure ('$0.02 per call, cached results are free'), which implicitly guides cost-sensitive decisions. Describes implementation strategy (schema.org with LLM fallback), helping agents understand reliability characteristics. Lacks explicit sibling comparison (e.g., 'use enrich_basic for simpler needs').

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/laundromatic/shopgraph'

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