optimize_decklist
Optimize a Magic: The Gathering decklist by comparing prices across Czech card shops and generating a shopping plan that minimizes total cost or number of orders.
Instructions
Resolve a Magic decklist (Arena/MTGO text) against all shops in parallel
and return a shopping_plan built under one of two strategies.
Strategies (strategy param):
"cheapest"(default): per-card greedy lowest price across all shops. Minimises total CZK; may fragment the order across many shops."fewest_shops": minimises the number of distinct shops in the final plan so the user places fewer separate orders / pays less shipping. Stays within 10% of the cheapest-split total by default; override the tolerance via theCZ_MTG_CONSOLIDATE_TOLERANCE_PCTenv var (integer percent). When no single shop can cover everything, cards missing from the chosen set fall back to the globally-cheapest offer (which may add one or more shops to the plan).
Response shape:
strategy: echoes the strategy that produced the picks/plan.picks: chosen offer per card under the active strategy.shopping_plan: the picks regrouped per shop — render as a summary table. Each group has the shop name, alineslist (quantity, card name, edition, condition, foil, unit price, subtotal, url) and asubtotal_czk. Groups sorted by descending shop subtotal.cheapest_split_total_czk: total of the per-card cheapest split, always populated as a reference even in fewest_shops mode.consolidated_total_czk: total of the consolidated plan in fewest_shops mode (equals the sum ofshopping_plansubtotals).nullin cheapest mode.per_shop_bundles: how each individual shop covers the decklist on its own (cards covered/missing, single-shop total CZK), sorted best-to-worst.cheapest_split_missing: cards no shop has in stock.
When presenting results to the user, render the shopping_plan as a
per-shop chart: one section per shop with a table of cards to buy from
it, plus the shop subtotal. Then show the headline total (use
consolidated_total_czk for fewest_shops, otherwise
cheapest_split_total_czk) and any cheapest_split_missing. In
fewest_shops mode it's useful to also surface the delta vs. the cheapest
split so the user can see the consolidation premium.
The decklist must contain at most 100 cards in total (Commander deck size)
AND at most 100 unique cards (one HTTP request per unique card per shop —
the unique-cards cap exists to keep a single tool call from spawning a
runaway number of requests). Override the unique cap via the
CZ_MTG_MAX_UNIQUE_CARDS env var if you need a higher limit. Format
example:
4 Lightning Bolt
4 Counterspell
2 Sol Ring (CMR) 263
Sideboard
1 NegateDisplay-only products (Art Series, oversized, helper cards) are excluded by
default. Pass include_non_playable=True to keep them in the picks.
Shop selection mirrors search_card:
shops: allow-list (None = all configured shops).exclude_shops: deny-list (applied after the allow-list). Excluded shops also disappear fromper_shop_bundlesso the chart only shows the shops the user actually wants to see.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| shops | No | ||
| decklist | Yes | ||
| strategy | No | cheapest | |
| exclude_shops | No | ||
| in_stock_only | No | ||
| include_non_playable | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| picks | Yes | ||
| strategy | No | cheapest | |
| total_cards | Yes | ||
| unique_cards | Yes | ||
| parser_errors | No | ||
| shopping_plan | No | ||
| per_shop_bundles | Yes | ||
| cheapest_split_missing | Yes | ||
| consolidated_total_czk | No | ||
| cheapest_split_total_czk | Yes |