Scaffold a new Shopify app with the CLI and add a product discount Function extension using `shopify app generate extension`, selecting the product discount Function type.
Define your `run.graphql` input query to declare exactly which cart and product fields your Function needs — Shopify only provides fields you explicitly request in this query.
Implement the `run` entrypoint (in Rust: via the `shopify_function` macro; in JS: as the default export) to receive the typed input and return a `FunctionRunResult` with a `discounts` array specifying targets and percentage or fixed-amount values.
Use `shopify app dev` to run the Function locally against a development store and trigger it by adding qualifying products to a cart, inspecting the discount result via the Function tracing panel in the Partner Dashboard.
Register the Function as a discount automation via the Admin GraphQL API (verify mutation name against current API docs, e.g. a variant of `discountAutomaticAppCreate`) with a title, function ID from the extension handle, and `combinesWith` settings.
Test edge cases: zero-item carts, products not in scope, combine-with-other-discounts behavior, and maximum discount caps enforced by Shopify.
Known gotchas
The `run.graphql` input query is strictly gated — if a field is not declared in that file, the runtime returns null or zero for it even if it exists on the resource. Always add all fields you intend to read.
Shopify Functions run in a sandboxed Wasm environment with strict CPU and memory limits (currently 5 ms instruction limit for most Function types). Avoid complex external lookups inside the Function itself; pre-compute data via metafields on products.
Function IDs are environment-specific: the ID generated on a development store differs from production. Re-register the automation after deploying to production.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp