Skip to main content
Glama
Shopify Python MCP Server

Shopify Python MCP Server

list_products

Retrieve a list of products from a Shopify store using the Shopify Python MCP Server. Specify the number of products to fetch, up to 250, for efficient product management.

Instructions

商品一覧を取得する

Input Schema

NameRequiredDescriptionDefault
limitNo取得する商品数(最大250)

Implementation Reference

  • The handler function that implements the core logic for the 'list_products' tool. It extracts the optional 'limit' from arguments, fetches products using the helper get_all_shopify_products, summarizes each product, and returns a JSON-formatted list as TextContent.
    async def handle_list_products(arguments: dict) -> list[types.TextContent]:
        """商品一覧を取得する"""
        limit = int(arguments.get("limit", 50))
        products = get_all_shopify_products(
            total_limit=limit, per_page_limit=250  # 1回のリクエストで最大250件取得
        )
    
        result = []
        for product in products:
            result.append(
                {
                    "id": product.id,
                    "title": product.title,
                    "vendor": product.vendor,
                    "product_type": product.product_type,
                    "created_at": product.created_at,
                    "updated_at": product.updated_at,
                    "status": product.status,
                    "variants_count": len(product.variants),
                    "images_count": len(product.images),
                }
            )
    
        return [
            types.TextContent(
                type="text",
                text=json.dumps(result, indent=2, ensure_ascii=False),
            )
        ]
  • The registration of the 'list_products' tool in the MCP server's list_tools handler, specifying name, description, and input schema.
        name="list_products",
        description="商品一覧を取得する",
        inputSchema={
            "type": "object",
            "properties": {
                "limit": {
                    "type": "number",
                    "description": "取得する商品数(最大250)",
                    "minimum": 1,
                    "maximum": 250,
                    "default": 50,
                },
            },
        },
    ),
  • JSON Schema defining the input parameters for the 'list_products' tool: an object with an optional 'limit' number (1-250, default 50).
        "type": "object",
        "properties": {
            "limit": {
                "type": "number",
                "description": "取得する商品数(最大250)",
                "minimum": 1,
                "maximum": 250,
                "default": 50,
            },
        },
    },
  • Key helper function that implements pagination-aware fetching of Shopify products using the shopify Python library, handling Link headers for next pages, rate limiting, and configurable limits.
    def get_all_shopify_products(total_limit=None, per_page_limit=250):
        """
        ShopifyAPIライブラリを使用して複数ページにわたる商品一覧を取得する関数
    
        Parameters:
        total_limit (int): 取得する総商品数(Noneの場合はすべての商品を取得)
        per_page_limit (int): 1回のリクエストあたりの商品数(最大250)
    
        Returns:
        list: 商品のリスト
        """
        # 1ページあたりの上限を250に制限
        per_page_limit = min(per_page_limit, 250)
    
        all_products = []
        next_page_url = None
    
        try:
            while True:
                # 既に十分な商品が取得されているか確認
                if total_limit is not None and len(all_products) >= total_limit:
                    break
    
                # 残りの取得数を計算
                current_limit = per_page_limit
                if total_limit is not None:
                    current_limit = min(per_page_limit, total_limit - len(all_products))
                    if current_limit <= 0:
                        break
    
                # 商品一覧の取得
                if next_page_url:
                    # next_page_urlからpage_infoを抽出
                    page_info = extract_page_info(next_page_url)
                    products = shopify.Product.find(
                        limit=current_limit, page_info=page_info
                    )
                else:
                    products = shopify.Product.find(limit=current_limit)
    
                # 結果が空の場合は終了
                if not products:
                    break
    
                # 取得した商品を追加
                all_products.extend(products)
    
                # レスポンスヘッダーからページネーション情報を取得
                response_headers = shopify.ShopifyResource.connection.response.headers
                link_header = response_headers.get("Link", "")
    
                # 次のページURLを抽出
                next_page_url = extract_next_page_url(link_header)
                if not next_page_url:
                    break
    
                # レート制限を避けるために少し待機
                time.sleep(0.5)
    
        except Exception as e:
            print(f"エラーが発生しました: {e}")
    
        # total_limitが指定されている場合、指定した数だけ返す
        if total_limit is not None:
            return all_products[:total_limit]
    
        return all_products

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.7/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('取得する' - get) but doesn't describe what '一覧' (list) entails (e.g., pagination, sorting, filtering beyond the limit parameter), return format, or any constraints like rate limits or authentication needs. This is a significant gap for a tool with no annotation coverage.

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 a single, efficient phrase ('商品一覧を取得する') with zero wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a list of product objects, pagination details) or behavioral aspects like error handling. For a list-retrieval tool with no structured context, this leaves the agent under-informed.

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?

The input schema has 100% description coverage, with the 'limit' parameter fully documented (default: 50, min: 1, max: 250). The description adds no parameter information beyond what the schema provides, so it meets the baseline of 3 for high schema coverage without compensating value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '商品一覧を取得する' (Get product list) states a clear verb ('取得する' - get) and resource ('商品一覧' - product list), which establishes the basic purpose. However, it doesn't distinguish this from its sibling 'get_product' (which presumably gets a single product), leaving ambiguity about when to use each tool.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_product' (for single products) or other siblings. There's no mention of prerequisites, context, or exclusions, leaving the agent to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools

Related Tools