Skip to main content
Glama
kishimoto-banana

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

TableJSON 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
Install Server

Other Tools

Related 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/kishimoto-banana/shopify-py-mcp'

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