create_product
Add new products to your Shopify store by specifying details like title, description, vendor, type, tags, status, variants, options, and images using the tool.
Instructions
新しい商品を作成する
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body_html | No | 商品の説明(HTML形式) | |
| images | No | 画像 | |
| options | No | オプション | |
| product_type | No | 商品タイプ | |
| status | No | ステータス | active |
| tags | No | タグ(カンマ区切り) | |
| title | Yes | 商品名 | |
| variants | No | バリエーション | |
| vendor | No | ベンダー名 |
Implementation Reference
- src/shopify_py_mcp/server.py:499-578 (handler)The handler function that executes the create_product tool. It validates input, creates a Shopify Product object, sets fields from arguments (title, description, vendor, type, tags, status, options, variants, images), saves the product via Shopify API, and returns a JSON response with success status and new product ID.async def handle_create_product(arguments: dict) -> list[types.TextContent]: """新しい商品を作成する""" # 必須パラメータのチェック title = arguments.get("title") if not title: raise ValueError("title is required") # 商品オブジェクトの作成 product = shopify.Product() product.title = title # オプションパラメータの設定 if "body_html" in arguments: product.body_html = arguments["body_html"] if "vendor" in arguments: product.vendor = arguments["vendor"] if "product_type" in arguments: product.product_type = arguments["product_type"] if "tags" in arguments: product.tags = arguments["tags"] if "status" in arguments: product.status = arguments["status"] # オプションの設定 if "options" in arguments and arguments["options"]: options = [] for option_data in arguments["options"]: option = shopify.Option() option.name = option_data["name"] option.position = option_data["position"] option.values = option_data["values"] options.append(option) product.options = options # バリエーションの設定 if "variants" in arguments and arguments["variants"]: variants = [] for variant_data in arguments["variants"]: variant = shopify.Variant() if "price" in variant_data: variant.price = variant_data["price"] if "sku" in variant_data: variant.sku = variant_data["sku"] if "inventory_quantity" in variant_data: variant.inventory_quantity = variant_data["inventory_quantity"] if "option1" in variant_data: variant.option1 = variant_data["option1"] if "option2" in variant_data: variant.option2 = variant_data["option2"] if "option3" in variant_data: variant.option3 = variant_data["option3"] variants.append(variant) product.variants = variants # 画像の設定 if "images" in arguments and arguments["images"]: for image_data in arguments["images"]: image = shopify.Image() image.src = image_data["src"] if "alt" in image_data: image.alt = image_data["alt"] product.images.append(image) # 商品の保存 product.save() return [ types.TextContent( type="text", text=json.dumps( { "success": True, "product_id": product.id, "message": f"商品「{product.title}」が作成されました", }, indent=2, ensure_ascii=False, ), ) ]
- src/shopify_py_mcp/server.py:181-270 (registration)Registration of the 'create_product' tool in the list_tools handler, including the tool name, description, and detailed JSON Schema for input parameters defining the structure for creating a Shopify product.types.Tool( name="create_product", description="新しい商品を作成する", inputSchema={ "type": "object", "properties": { "title": {"type": "string", "description": "商品名"}, "body_html": { "type": "string", "description": "商品の説明(HTML形式)", }, "vendor": {"type": "string", "description": "ベンダー名"}, "product_type": {"type": "string", "description": "商品タイプ"}, "tags": {"type": "string", "description": "タグ(カンマ区切り)"}, "status": { "type": "string", "description": "ステータス", "enum": ["active", "draft", "archived"], "default": "active", }, "variants": { "type": "array", "description": "バリエーション", "items": { "type": "object", "properties": { "price": {"type": "string", "description": "価格"}, "sku": {"type": "string", "description": "SKU"}, "inventory_quantity": { "type": "number", "description": "在庫数", }, "option1": { "type": "string", "description": "オプション1の値", }, "option2": { "type": "string", "description": "オプション2の値", }, "option3": { "type": "string", "description": "オプション3の値", }, }, "required": ["price"], }, }, "options": { "type": "array", "description": "オプション", "items": { "type": "object", "properties": { "name": { "type": "string", "description": "オプション名", }, "position": { "position": "number", "description": "オプション順番", }, "values": { "type": "array", "description": "オプション値", "items": {"type": "string"}, }, }, "required": ["name", "position", "values"], }, }, "images": { "type": "array", "description": "画像", "items": { "type": "object", "properties": { "src": {"type": "string", "description": "画像URL"}, "alt": { "type": "string", "description": "代替テキスト", }, }, "required": ["src"], }, }, }, "required": ["title"], }, ),
- src/shopify_py_mcp/server.py:184-269 (schema)JSON Schema defining the input parameters for the create_product tool, including required 'title', optional fields like body_html, vendor, variants (with price required), options, and images.inputSchema={ "type": "object", "properties": { "title": {"type": "string", "description": "商品名"}, "body_html": { "type": "string", "description": "商品の説明(HTML形式)", }, "vendor": {"type": "string", "description": "ベンダー名"}, "product_type": {"type": "string", "description": "商品タイプ"}, "tags": {"type": "string", "description": "タグ(カンマ区切り)"}, "status": { "type": "string", "description": "ステータス", "enum": ["active", "draft", "archived"], "default": "active", }, "variants": { "type": "array", "description": "バリエーション", "items": { "type": "object", "properties": { "price": {"type": "string", "description": "価格"}, "sku": {"type": "string", "description": "SKU"}, "inventory_quantity": { "type": "number", "description": "在庫数", }, "option1": { "type": "string", "description": "オプション1の値", }, "option2": { "type": "string", "description": "オプション2の値", }, "option3": { "type": "string", "description": "オプション3の値", }, }, "required": ["price"], }, }, "options": { "type": "array", "description": "オプション", "items": { "type": "object", "properties": { "name": { "type": "string", "description": "オプション名", }, "position": { "position": "number", "description": "オプション順番", }, "values": { "type": "array", "description": "オプション値", "items": {"type": "string"}, }, }, "required": ["name", "position", "values"], }, }, "images": { "type": "array", "description": "画像", "items": { "type": "object", "properties": { "src": {"type": "string", "description": "画像URL"}, "alt": { "type": "string", "description": "代替テキスト", }, }, "required": ["src"], }, }, }, "required": ["title"], },