create_product_set
Create a product set with JSON filter rules for Dynamic Product Ads (DPA) targeting from a product catalog.
Instructions
Create a product set with filter rules for DPA targeting.
Args: catalog_id: Product catalog ID. name: Product set name. filter_json: JSON string of filter rules. Example: '{"product_type":{"i_contains":"shoes"}}'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| catalog_id | Yes | ||
| name | Yes | ||
| filter_json | Yes |
Implementation Reference
- meta_ads_mcp/core/catalogs.py:468-515 (handler)The main handler function for the create_product_set tool. Decorated with @mcp.tool() and registered via the catalogs module import in server.py. Creates a product set by making a POST request to Meta's Graph API /{catalog_id}/product_sets endpoint after validating name and filter_json inputs.
@mcp.tool() def create_product_set( catalog_id: str, name: str, filter_json: str, ) -> dict: """ Create a product set with filter rules for DPA targeting. Args: catalog_id: Product catalog ID. name: Product set name. filter_json: JSON string of filter rules. Example: '{"product_type":{"i_contains":"shoes"}}' """ import json as _json if not name or not name.strip(): return {"error": "name is required.", "blocked_at": "input_validation"} try: filters = _json.loads(filter_json) if not isinstance(filters, dict): return {"error": "filter_json must be a JSON object.", "blocked_at": "input_validation"} except _json.JSONDecodeError as e: return {"error": f"Malformed filter_json: {e}", "blocked_at": "input_validation"} api_client._ensure_initialized() try: result = api_client.graph_post( f"/{catalog_id}/product_sets", data={ "name": name.strip(), "filter": _json.dumps(filters), }, ) except MetaAPIError as e: return {"error": f"Meta API error: {e}", "blocked_at": "api_call"} ps_id = result.get("id") return { "product_set_id": ps_id, "catalog_id": catalog_id, "name": name.strip(), "filter": filters, "rate_limit_usage_pct": api_client.rate_limits.max_usage_pct, } - Input parameters defined in the function signature: catalog_id (str), name (str), filter_json (str). No dedicated Pydantic schema; validation is inline.
def create_product_set( catalog_id: str, name: str, filter_json: str, ) -> dict: - meta_ads_mcp/server.py:34-35 (registration)Registration: the catalogs module (which contains create_product_set) is imported in server.py at line 34. The @mcp.tool() decorator at line 468 registers the function with the FastMCP server instance.
from meta_ads_mcp.core import catalogs # noqa: E402, F401 from meta_ads_mcp.core import audiences # noqa: E402, F401 - meta_ads_mcp/core/catalogs.py:15-18 (helper)Imports used by create_product_set: api_client (MetaAPI client for Graph API calls) and MetaAPIError for error handling.
from meta_ads_mcp.server import mcp from meta_ads_mcp.core.api import api_client, MetaAPIError from meta_ads_mcp.core.utils import ensure_account_id_format