Inspiration

Many Magic: The Gathering (MTG) deck building resources rely on crowdsourcing and are a popularity contest for cards. This means that sometimes cards seen commonly together actually don’t synergize well. MTGraphRAG uses RelateDB on your local device to upload your deck and get an immediate analysis of card combinations, non-combinations (nonbos), and combos that are one card away based on the actual card text and game logic. Because it’s lightweight, it can fit as an app on the user’s device, so they can use it on the go at the card shop while looking for their next best upgrade even without the internet.

What it does

MTGraphRAG transforms your deck into a local labeled property graph using RelateDB. It uses enriched graph relationships between cards based on their abilities and effects to highlight combinations of cards in your deck that go well together, cards that work against each other, and cards that are one step away from creating an infinite combination to win the game. Every combo is traced step by step, so you can see what triggers what, what it costs, and where each card needs to be (battlefield, graveyard or exile). It also groups your deck into synergy strategies like sacrifice, tokens, blink and spellslinger, and suggests the next cards to add. When the graph misses a combo, you can teach it by drawing the connections between cards yourself, and the graph learns it for next time. MTGraphRAG empowers gamers to enhance their MTG deck without relying on popularity, and to focus instead on the mechanics and rules of the game, with smart data modeling as a graph in RelateDB.

How we built it

  • Every card’s rules text is split into its abilities: activated, triggered, static or spell.
  • Each ability is linked to what it costs, what it produces and what triggers it, using an LLM-assisted rules engine, then checked by rules again.
  • Abilities are also linked to game states: where a card has to be for the ability to work (battlefield, graveyard, exile, held under another card) and where it moves cards.
  • A deck becomes a small graph of cause and effect. A combo is a cycle in it that pays for itself and ends in the same state it started in.
  • Rules checks catch look-alikes that don’t work, and Commander Spellbook’s 121,885 known combos confirm what’s known. Each known combo is also traced through its own steps and starting zones.
  • The official rulings and the Comprehensive Rules live in the graph too, with 2,995 rules embedded in a RelateDB vector index, so new combos can be judged against the most relevant rules.
  • Human-reviewed combo validation: every reviewed combo, look-alike and taught mechanic becomes a regression test (135 checks).
  • All of it fits in one RelateDB file in memory: 35,576 cards and about 118,000 abilities. Analysing a deck only touches that deck’s slice of a few hundred nodes.

Challenges we ran into

  • Some combos look real but aren’t. Felidar Guardian and Lumbering Battlement look like an infinite loop, but the exile never ends. Fixing this without breaking real combos is what led us to model game states as nodes in the graph.
  • MTG rules are full of small details: “sacrifice a creature” can’t sacrifice an enchantment, a token copy isn’t the card coming back, and {C} needs colorless mana. Each mistake found by checking against the official rulings became a fix that works for every card with that wording.
  • Some things are both something you have and something that happens, like gaining life. We had to model that clearly so the graph and the app speak the same language.
  • Speed: a blink-heavy deck has about 425,000 possible cycles. Checking shortest loops first and skipping repeats took it from 152 seconds to about 7, with the same results.
  • Coverage: each new mechanic only unlocks a small slice of all known combos, so we built a way for players to teach the graph themselves.

Accomplishments that we’re proud of

  • Of 80 known combos in our sample decks, 79 trace through their steps as infinite or near-infinite, and the graph independently finds 51 of the 75 verified combos using a completely different method.
  • 256 loops were checked against official rulings, and every failure came back with a citation that became a test.
  • Combining Commander Spellbook with the graph puts the right next card in the top 10 suggestions 59% of the time, compared to 34% for Spellbook counts alone.
  • A combo the graph missed, once drawn in Teach a mechanic, becomes part of the graph and is found automatically from then on.

What we learned

A graph is more than a lookup: it can explain why cards work together, step by step. The rules of the game make great tests, because every ruling we got wrong turned into a check that keeps it right for the future. Vector search is great for finding the rules worth reading, but it should never decide whether a combo works. And game state matters: most false combos came from getting wrong where a card was.

What’s next for MTGraphRAG

  • Model more game states: counters, storm counts, graveyard size and cards that entered without being cast.
  • Turn combos taught by players into general mechanics, so one taught combo unlocks every card with the same pattern.
  • Raise how many known combos the graph can trace on its own.
  • Package it as a mobile app so the whole analysis runs on your phone at the card shop, which RelateDB’s embedded design makes possible.

Built With

Share this project:

Updates

Submission history