Skip to main content
Glama

Pricing Analysis

pricing_analyze
Read-onlyIdempotent

Analyze pricing across products using margin calculation and sales velocity to generate price optimization suggestions. Returns per-product data including current price, cost, margin, daily units sold, revenue, and suggested price.

Instructions

Analyze pricing across products with margin calculation, sales velocity, and rule-based price optimization suggestions. Returns an array where each element contains product_title, current_price, cost, margin_percent, daily_units_sold, revenue_per_day, suggested_price (or null if no change recommended), and suggestion_reason. Pass product_id to scope to a single product, omit for full catalog.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
store_idYesUUID of a connected store (returned by store_connect with action="connect" or visible in store_connect with action="list" / the store_overview resource)
product_idNoRestrict the analysis to a single product by external_id. Omit to analyse the entire active catalog.

Implementation Reference

  • The actual handler function 'analyzePricing' that executes pricing analysis logic. It fetches products/orders from storage, calculates margins, sales velocity, discounts, and applies rule-based logic to suggest price changes (or none). Returns sorted array of PricingAnalysis objects.
    export async function analyzePricing(storeId: string, productId?: string): Promise<PricingAnalysis[]> {
      validateUUID(storeId, 'store');
      const store = await storage.getStoreById(storeId);
      if (!store) throw new NotFoundError('Store', storeId);
    
      const products = await storage.getProducts(storeId);
      const orders = await storage.getOrders(storeId);
    
      const targetProducts = productId
        ? products.filter((p) => p.id === productId)
        : products.filter((p) => p.status === 'active');
    
      if (productId && targetProducts.length === 0) throw new NotFoundError('Product', productId);
    
      const now = Date.now();
      const thirtyDaysAgo = now - 30 * MS_PER_DAY;
      const recentOrders = orders.filter((o) =>
        new Date(o.created_at).getTime() >= thirtyDaysAgo &&
        o.status !== 'cancelled' && o.status !== 'refunded'
      );
    
      return targetProducts.map((product) => {
        // Count units sold and revenue in last 30 days
        let unitsSold = 0;
        let revenue = 0;
        for (const order of recentOrders) {
          for (const item of order.items) {
            if (item.product_id === product.id) {
              unitsSold += item.quantity;
              revenue += item.total;
            }
          }
        }
    
        const avgUnitsPerDay = unitsSold / 30;
        const revenuePerDay = revenue / 30;
    
        // Margin calculation
        const marginPercent = product.cost_price !== null && product.cost_price > 0
          ? Math.round(((product.price - product.cost_price) / product.price) * 10000) / 100
          : null;
    
        // Discount from compare_at_price
        const discountPercent = product.compare_at_price !== null && product.compare_at_price > product.price
          ? Math.round(((product.compare_at_price - product.price) / product.compare_at_price) * 10000) / 100
          : null;
    
        // Price elasticity hint and suggestion
        let elasticityHint: string;
        let suggestedPrice: number | null = null;
        let suggestionReason: string;
    
        if (unitsSold === 0) {
          elasticityHint = 'No sales data — consider lowering price to attract buyers or improving visibility';
          suggestedPrice = product.price > 0 ? Math.round(product.price * 0.85 * 100) / 100 : null;
          suggestionReason = 'No sales in 30 days. A 15% price reduction may increase conversion.';
        } else if (avgUnitsPerDay > 5 && marginPercent !== null && marginPercent < 20) {
          elasticityHint = 'High volume but low margin — demand is strong, consider gradual price increase';
          suggestedPrice = Math.round(product.price * 1.10 * 100) / 100;
          suggestionReason = 'Strong demand with low margin. A 10% increase likely sustainable.';
        } else if (avgUnitsPerDay > 3 && (marginPercent === null || marginPercent >= 40)) {
          elasticityHint = 'Good volume and healthy margin — pricing appears optimal';
          suggestionReason = 'Current pricing is well-balanced. No change recommended.';
        } else if (avgUnitsPerDay < 0.5 && (marginPercent === null || marginPercent > 50)) {
          elasticityHint = 'Low volume with high margin — price may be too high for demand';
          suggestedPrice = Math.round(product.price * 0.90 * 100) / 100;
          suggestionReason = 'Low sales volume despite high margin. Consider a 10% price reduction.';
        } else {
          elasticityHint = 'Moderate performance — test small price changes and measure impact';
          suggestionReason = 'No strong signal. A/B test with 5% variation to find optimal price point.';
        }
    
        return {
          product_id: product.id,
          product_title: product.title,
          current_price: product.price,
          cost_price: product.cost_price,
          margin_percent: marginPercent,
          compare_at_price: product.compare_at_price,
          discount_percent: discountPercent,
          avg_units_per_day: Math.round(avgUnitsPerDay * 100) / 100,
          revenue_per_day: Math.round(revenuePerDay * 100) / 100,
          price_elasticity_hint: elasticityHint,
          suggested_price: suggestedPrice,
          suggestion_reason: suggestionReason,
        };
      }).sort((a, b) => b.revenue_per_day - a.revenue_per_day);
    }
  • Zod schema and TypeScript type 'PricingAnalysis' defining the return shape: product_id, product_title, current_price, cost_price, margin_percent, avg_units_per_day, revenue_per_day, suggested_price, suggestion_reason, etc.
    export const PricingAnalysisSchema = z.object({
      product_id: z.string(),
      product_title: z.string(),
      current_price: z.number(),
      cost_price: z.number().nullable(),
      margin_percent: z.number().nullable(),
      compare_at_price: z.number().nullable(),
      discount_percent: z.number().nullable(),
      avg_units_per_day: z.number(),
      revenue_per_day: z.number(),
      price_elasticity_hint: z.string(),
      suggested_price: z.number().nullable(),
      suggestion_reason: z.string(),
    });
    export type PricingAnalysis = z.infer<typeof PricingAnalysisSchema>;
  • src/index.ts:168-186 (registration)
    Registration of the 'pricing_analyze' tool via server.registerTool, with inputSchema (store_id UUID, optional product_id), description, and async handler that calls analyzePricing.
    // ── Tool: pricing_analyze ─────────────────────────────────────────
    server.registerTool(
      'pricing_analyze',
      {
        title: 'Pricing Analysis',
        description: 'Analyze pricing across products with margin calculation, sales velocity, and rule-based price optimization suggestions. Returns an array where each element contains product_title, current_price, cost, margin_percent, daily_units_sold, revenue_per_day, suggested_price (or null if no change recommended), and suggestion_reason. Pass product_id to scope to a single product, omit for full catalog.',
        inputSchema: z.object({
          store_id: z.string().uuid().describe('UUID of a connected store (returned by store_connect with action="connect" or visible in store_connect with action="list" / the store_overview resource)'),
          product_id: z.string().optional().describe('Restrict the analysis to a single product by external_id. Omit to analyse the entire active catalog.'),
        }),
        annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
      },
      async ({ store_id, product_id }) => {
        try {
          const result = await analyzePricing(store_id, product_id);
          return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }] };
        } catch (e) { return handleToolError(e); }
      }
    );
Behavior3/5

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

Annotations (readOnlyHint=true, destructiveHint=false, idempotentHint=true) already cover safety and idempotency. The description adds the return format but does not disclose potential performance implications, data freshness, or other behavioral traits beyond what annotations provide.

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 concise with two sentences, front-loading the main purpose. It lists output fields efficiently and includes parameter usage, with no redundant or vague statements.

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 moderate complexity (2 params, no output schema), the description covers purpose, output structure, and parameter usage. Sibling tools are present, but no guidance on when to use this vs. 'pricing_optimize' is missing, and pagination or error handling are not addressed. Still, it is largely complete.

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%, and the description largely restates the schema's parameter descriptions. It adds no new semantic meaning; the instruction to use product_id for scoping is already in the schema. Thus baseline score of 3 is appropriate.

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 it analyzes pricing with margin calculation, sales velocity, and rule-based price optimization suggestions. It specifies the exact output fields, making it distinct from siblings like 'pricing_optimize' which likely focuses on applying changes rather than analysis.

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 gives clear guidance on parameter usage: 'Pass product_id to scope to a single product, omit for full catalog.' It does not explicitly mention when not to use or compare with siblings, but the usage context is well stated.

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/enzoemir1/shopops-mcp'

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