edhvault-mcp 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/dist/cli.js +192 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -63,12 +63,13 @@ With a local model, nothing the tools return leaves your computer.
63
63
  | `collection_lookup` | What you own of some cards, a search, or a deck: copies, printings, binders, decks using it, wishlist |
64
64
  | `card_search` | Every Magic card, in EDHVault's Scryfall-style search, including every Scryfall tag (`otag:`), sets and finishes. Each result lists its roles and tags. Works without a code |
65
65
  | `get_card` | Everything about one card: the printed rules text (every face), legality in every format, EDHREC rank, Game Changer, roles and Scryfall tags, today's price and its 1/7/30-day change, every printing with its prices, its land cycle, the combos it's in (and how each works, on ask), and with a code what you own of it and which decks use it. Works without a code |
66
+ | `get_commander` | A commander's EDHREC page, as EDHVault shows it: decks, rank overall and this week, bracket estimate, and every section (New Cards, Top Cards, High Lift, Creatures, Lands, ...) with each card's inclusion, synergy, lift and trending score. `cedh` gives the cEDH decks' cut; partners take both names. With a code, each card says how many you own. Works without a code |
66
67
  | `deck_combos` | The combos in a deck and the ones it's one card from, as the deck builder finds them, and how many count toward its bracket |
67
68
  | `plan_odds` | The odds a deck's plan comes together by turn N: your saved Plan by turn, or rows you ask about (cards, groups, tags, or counts like cards in hand). The same 20,000 games as the Odds tab, with your own card reads. It lists what it had to assume, and can try card reads for one run (what-if, not saved) |
68
69
 
69
70
  Bracket floors count two-card infinite combos, as the deck builder does. Legality here is information, the same as on the site. It never stops you doing anything.
70
71
 
71
- The first combo question downloads the combo index (about 28 MB) once; after that it's cached like the card data. Combo data comes from [Commander Spellbook](https://commanderspellbook.com).
72
+ The first combo question downloads the combo index (about 28 MB) once; after that it's cached like the card data. Combo data comes from [Commander Spellbook](https://commanderspellbook.com). Commander data comes from [EDHREC](https://edhrec.com), refreshed weekly.
72
73
 
73
74
  Prices are today's, the same the site shows. Everything comes from edhvault.com: nothing calls Scryfall directly. Asking how combos work downloads their steps (about 57 MB) once; answers say so until then.
74
75
 
package/dist/cli.js CHANGED
@@ -50,6 +50,9 @@ function computeSlug(name, joined) {
50
50
  }
51
51
  return s.replace(/['’‘.]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
52
52
  }
53
+ function edhrecCommanderUrl(slug) {
54
+ return `https://edhrec.com/commanders/${slug}`;
55
+ }
53
56
  var SLUG_CACHE_MAX, FRONT_CACHE, JOINED_CACHE;
54
57
  var init_slug = __esm({
55
58
  "../src/lib/edhrec/slug.ts"() {
@@ -11197,14 +11200,16 @@ import { join as join5 } from "node:path";
11197
11200
 
11198
11201
  // src/dataFile.ts
11199
11202
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
11200
- import { join as join4 } from "node:path";
11203
+ import { dirname, join as join4 } from "node:path";
11204
+ var DATA_PATH = /^(?:commanders\/)?[a-z0-9_.-]+\.json$/i;
11201
11205
  async function ensureFile(opts, name) {
11202
- if (!SAFE_NAME.test(name)) throw new Error(`Not a data file name: ${name}`);
11206
+ if (!DATA_PATH.test(name) || name.includes("..")) throw new Error(`Not a data file name: ${name}`);
11203
11207
  const fetchImpl = opts.fetchImpl ?? fetch;
11204
11208
  const origin = opts.origin ?? "https://edhvault.com";
11205
11209
  const dir = join4(opts.dir, "files");
11206
11210
  mkdirSync2(dir, { recursive: true });
11207
11211
  const path = join4(dir, name);
11212
+ mkdirSync2(dirname(path), { recursive: true });
11208
11213
  const metaPath = `${path}.meta.json`;
11209
11214
  const cached2 = existsSync2(path) && existsSync2(metaPath) ? JSON.parse(readFileSync4(metaPath, "utf8")) : null;
11210
11215
  const headers = {};
@@ -11264,6 +11269,16 @@ var parse = {
11264
11269
  if (typeof doc.builtAt !== "string" || !Array.isArray(doc.formats) || !doc.text || !doc.legal) throw new Error("card-text.json is damaged.");
11265
11270
  return doc;
11266
11271
  },
11272
+ commandersIndex(raw) {
11273
+ const doc = raw;
11274
+ if (typeof doc.builtAt !== "string" || !Array.isArray(doc.commanders) || doc.commanders.length < 1500) throw new Error("commanders/_index.json is damaged.");
11275
+ return doc;
11276
+ },
11277
+ commanderDetail(raw, slug) {
11278
+ const doc = raw;
11279
+ if (doc?.slug !== slug || !Array.isArray(doc.categories)) throw new Error(`commanders/${slug}.json is damaged.`);
11280
+ return doc;
11281
+ },
11267
11282
  /** Every detail file of one build, as one map. A part from another build is
11268
11283
  * refused (it would pair one build's ids with another's steps). */
11269
11284
  comboDetail(docs) {
@@ -11279,6 +11294,7 @@ var parse = {
11279
11294
  };
11280
11295
  function extrasLoader(opts) {
11281
11296
  const stale = /* @__PURE__ */ new Set();
11297
+ const details = /* @__PURE__ */ new Map();
11282
11298
  const once = (load) => {
11283
11299
  let p = null;
11284
11300
  return () => p ??= load().catch((e) => {
@@ -11302,6 +11318,13 @@ function extrasLoader(opts) {
11302
11318
  if (files.stale) stale.add("combos-detail.json");
11303
11319
  return parse.comboDetail(files.files.map((n) => JSON.parse(readFileSync5(join5(files.dir, n), "utf8"))));
11304
11320
  }),
11321
+ commandersIndex: file3("commanders/_index.json", parse.commandersIndex),
11322
+ commanderDetail: (slug) => {
11323
+ if (!/^[a-z0-9-]+$/.test(slug)) return Promise.reject(new Error(`Not a commander slug: ${slug}`));
11324
+ let load = details.get(slug);
11325
+ if (!load) details.set(slug, load = file3(`commanders/${slug}.json`, (raw) => parse.commanderDetail(raw, slug)));
11326
+ return load();
11327
+ },
11305
11328
  comboStepsOnDisk: () => existsSync3(join5(opts.dir, COMBO_DETAIL_SET.name, "manifest.json")),
11306
11329
  stale: () => [...stale]
11307
11330
  };
@@ -11513,13 +11536,13 @@ var Library = class {
11513
11536
 
11514
11537
  // src/log.ts
11515
11538
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
11516
- import { dirname } from "node:path";
11539
+ import { dirname as dirname2 } from "node:path";
11517
11540
  var file = null;
11518
11541
  var debugOn = false;
11519
11542
  function configureLog(opts) {
11520
11543
  file = opts.file ?? null;
11521
11544
  debugOn = !!opts.debug;
11522
- if (file) mkdirSync4(dirname(file), { recursive: true });
11545
+ if (file) mkdirSync4(dirname2(file), { recursive: true });
11523
11546
  }
11524
11547
  function write(level, message) {
11525
11548
  const line = `${(/* @__PURE__ */ new Date()).toISOString()} ${level} ${message}
@@ -11589,7 +11612,7 @@ init_syncKeys();
11589
11612
  import { execFileSync } from "node:child_process";
11590
11613
  import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
11591
11614
  import { userInfo } from "node:os";
11592
- import { dirname as dirname2, join as join7 } from "node:path";
11615
+ import { dirname as dirname3, join as join7 } from "node:path";
11593
11616
  var SERVICE = "edhvault-mcp";
11594
11617
  var ACCOUNT = "access-code";
11595
11618
  async function osKeychain() {
@@ -11624,7 +11647,7 @@ function fileKeychain(dir) {
11624
11647
  return {
11625
11648
  get: () => existsSync5(file3) ? readFileSync7(file3, "utf8").trim() : null,
11626
11649
  set: (value) => {
11627
- mkdirSync5(dirname2(file3), { recursive: true, mode: 448 });
11650
+ mkdirSync5(dirname3(file3), { recursive: true, mode: 448 });
11628
11651
  writeFileSync4(file3, "", { mode: 384 });
11629
11652
  try {
11630
11653
  lockToOwner(file3);
@@ -41255,6 +41278,26 @@ function buildCardComboResults(index, oracleId, deckOracleIds, cardOf, detail) {
41255
41278
  // src/tools/registry.ts
41256
41279
  init_slug();
41257
41280
 
41281
+ // ../src/lib/edhrec/cardStats.ts
41282
+ var TRENDING_MIN = 3;
41283
+ function isTrending(trend) {
41284
+ return trend !== void 0 && trend >= TRENDING_MIN;
41285
+ }
41286
+ function formatLift(lift) {
41287
+ return `${lift.toFixed(1)}\xD7`;
41288
+ }
41289
+
41290
+ // ../src/lib/commanders/inclusionDenominator.ts
41291
+ function commanderInclusionDenominator(detail) {
41292
+ let denom = detail.deckCount ?? 0;
41293
+ for (const cat of detail.categories) {
41294
+ for (const card of cat.cards) {
41295
+ if (card.inclusion > denom) denom = card.inclusion;
41296
+ }
41297
+ }
41298
+ return denom;
41299
+ }
41300
+
41258
41301
  // ../src/lib/printingTrend.ts
41259
41302
  var SLOT2 = { "7d": 0, "30d": 2, "1d": 4 };
41260
41303
  function printingTrendWindows(file3, set2, collectorNumber, foil, priceNow) {
@@ -52416,7 +52459,146 @@ var cardTool = {
52416
52459
  });
52417
52460
  }
52418
52461
  };
52419
- var TOOLS = [listDecks, getDeck, collectionLookup, cardSearch, cardTool, deckCombos2, planOdds];
52462
+ var EDHREC_CREDIT = "Commander data from EDHREC (edhrec.com).";
52463
+ var MAX_SECTION_CARDS = { summary: 10, standard: 30, full: Infinity };
52464
+ var FEW_DECKS = 500;
52465
+ var pct2 = (n) => n > 0 && n < 0.01 ? `${(Math.round(n * 1e3) / 10).toFixed(1)}%` : `${Math.round(n * 100)}%`;
52466
+ var signedPct = (n) => `${n >= 0 ? "+" : ""}${Math.round(n * 100)}%`;
52467
+ var fold = (s) => s.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
52468
+ function candidateSlugs(names) {
52469
+ if (names.length === 1) {
52470
+ const n = names[0];
52471
+ return [.../* @__PURE__ */ new Set([toEdhrecSlug(n), toEdhrecSlug(n, { joined: true })])];
52472
+ }
52473
+ const [a, b] = names;
52474
+ return [...new Set([`${a} // ${b}`, `${b} // ${a}`].map((n) => toEdhrecSlug(n, { joined: true })))];
52475
+ }
52476
+ var commanderTool = {
52477
+ name: "get_commander",
52478
+ description: "A commander's EDHREC page, as EDHVault shows it: how many decks, its rank overall and this week, the bracket estimate, and each section (New Cards, Top Cards, High Lift, Creatures, Lands, ...) with every card's inclusion, synergy, lift and trending score. `cedh` gives the cEDH decks' cut. With an access code, each card says how many the user owns. Partners: give both names. Needs no access code.",
52479
+ input: {
52480
+ name: external_exports.string().min(1).describe("The commander's name. For partners, the first one."),
52481
+ partner: external_exports.string().optional().describe("The second commander of a pair (partner, background, friends forever, ...)."),
52482
+ section: external_exports.string().optional().describe('Only this section, for example "High Lift", "New Cards", "Lands".'),
52483
+ cedh: external_exports.boolean().optional().describe("The cEDH decks' numbers instead of all decks'."),
52484
+ detail: external_exports.enum(DETAILS).optional().describe("summary (default: 10 cards per section), standard (30), or full (every card)."),
52485
+ refresh: refreshInput
52486
+ },
52487
+ async run(args, ctx) {
52488
+ const x = ctx.extras;
52489
+ if (!x) throw new ToolProblem("The commander data isn't available in this setup.");
52490
+ const catalog = await tryCatalog(ctx);
52491
+ const asked = [String(args.name), ...typeof args.partner === "string" && args.partner.trim() ? [args.partner] : []];
52492
+ const names = asked.map((n) => (catalog ? resolveCardName(catalog.index, n)?.name : void 0) ?? n);
52493
+ const index = await x.commandersIndex();
52494
+ const bySlug = new Map(index.commanders.map((c) => [c.slug, c]));
52495
+ const slugs = candidateSlugs(names);
52496
+ let summary = slugs.map((s) => bySlug.get(s)).find(Boolean);
52497
+ if (!summary) {
52498
+ const want = /* @__PURE__ */ new Set([fold(names.join(" // ")), ...names.length === 2 ? [fold(`${names[1]} // ${names[0]}`)] : []]);
52499
+ summary = index.commanders.find((c) => want.has(fold(c.name)) || names.length === 1 && fold(c.name.split(" // ")[0]) === fold(names[0]));
52500
+ }
52501
+ const who = names.join(" + ");
52502
+ if (!summary) {
52503
+ const stub = index.stubs?.find((s) => slugs.includes(s.slug));
52504
+ if (stub) {
52505
+ return json2({
52506
+ commander: stub.name,
52507
+ decks: stub.deckCount,
52508
+ note: `EDHREC lists ${stub.deckCount} deck${stub.deckCount === 1 ? "" : "s"} for this commander: too few for a page of card data.`,
52509
+ links: { edhrec: edhrecCommanderUrl(stub.slug) },
52510
+ dataAsOf: index.builtAt,
52511
+ credit: EDHREC_CREDIT
52512
+ });
52513
+ }
52514
+ const words = fold(asked.join(" ")).split(" ").filter((w) => w.length > 2);
52515
+ const hits = (n) => words.filter((w) => fold(n).split(" ").includes(w)).length;
52516
+ const best = Math.max(0, ...index.commanders.map((c) => hits(c.name)));
52517
+ const near = best === 0 ? [] : index.commanders.filter((c) => hits(c.name) === best).slice(0, 5).map((c) => c.name);
52518
+ throw new ToolProblem(
52519
+ `EDHREC has no page for ${who}.${near.length ? ` Close: ${near.join("; ")}.` : names.length === 2 ? " EDHREC may not track this pair." : ""}`
52520
+ );
52521
+ }
52522
+ const detail = detailOf(args);
52523
+ const page = await x.commanderDetail(summary.slug);
52524
+ const wantCedh = args.cedh === true;
52525
+ const cut = wantCedh ? page.cedh : { deckCount: page.deckCount, categories: page.categories };
52526
+ if (!cut) throw new ToolProblem(`EDHREC has no cEDH numbers for ${summary.name}: too few cEDH decks. Ask without cedh for all decks.`);
52527
+ const denom = commanderInclusionDenominator(cut);
52528
+ const sections = cut.categories;
52529
+ let shown = sections;
52530
+ if (typeof args.section === "string" && args.section.trim()) {
52531
+ const want = fold(args.section).replace(/ /g, "");
52532
+ shown = sections.filter((s) => fold(s.label).replace(/ /g, "") === want || s.tag === want);
52533
+ if (!shown.length) throw new ToolProblem(`No "${args.section}" section. Sections: ${sections.map((s) => s.label).join(", ")}.`);
52534
+ }
52535
+ const missing = [];
52536
+ let owned = null;
52537
+ if (catalog) {
52538
+ try {
52539
+ const own2 = await ownership(ctx, catalog, args.refresh === true);
52540
+ owned = new Map([...own2.owned].map(([oid, r]) => [oid, r.stacks.reduce((n, s) => n + s.quantity, 0)]));
52541
+ } catch (e) {
52542
+ if (!(e instanceof LibraryError)) throw e;
52543
+ if (e.kind !== "not-connected") missing.push(`what you own (${e.message})`);
52544
+ }
52545
+ }
52546
+ const ownedOf = (name) => {
52547
+ if (!owned || !catalog) return void 0;
52548
+ const card = resolveCardName(catalog.index, name);
52549
+ return card ? owned.get(card.oracleId) ?? 0 : void 0;
52550
+ };
52551
+ const max = MAX_SECTION_CARDS[detail];
52552
+ const ranked = [...index.commanders].sort((a, b) => b.deckCount - a.deckCount);
52553
+ const rank = ranked.findIndex((c) => c.slug === summary.slug) + 1;
52554
+ const out = shown.map((s) => {
52555
+ const cards = s.cards.filter((c) => c.slug !== summary.slug);
52556
+ const rows = cards.slice(0, max).map((c) => {
52557
+ const have = ownedOf(c.name);
52558
+ return {
52559
+ name: c.name,
52560
+ inclusion: pct2(c.inclusion / denom),
52561
+ decks: c.inclusion,
52562
+ synergy: signedPct(c.synergy),
52563
+ ...c.lift != null ? { lift: formatLift(c.lift) } : {},
52564
+ ...isTrending(c.trend) ? { trending: c.trend } : {},
52565
+ ...have !== void 0 ? { owned: have } : {}
52566
+ };
52567
+ });
52568
+ const ownedHere = owned ? cards.filter((c) => (ownedOf(c.name) ?? 0) > 0).length : void 0;
52569
+ return {
52570
+ section: s.label,
52571
+ ...cards.length > rows.length ? { showing: rows.length, of: cards.length } : { cards: cards.length },
52572
+ ...ownedHere !== void 0 ? { youOwn: `${ownedHere} of ${cards.length}` } : {},
52573
+ rows
52574
+ };
52575
+ });
52576
+ const stale = x.stale().filter((f) => f.startsWith("commanders/"));
52577
+ return json2({
52578
+ commander: summary.name,
52579
+ colors: summary.colors,
52580
+ decks: wantCedh ? cut.deckCount : page.deckCount,
52581
+ ...wantCedh ? { cedhCut: `the ${cut.deckCount} cEDH decks of ${page.deckCount}` } : {},
52582
+ rank: `${rank} of ${index.commanders.length} by decks`,
52583
+ ...summary.week ? { thisWeek: { rank: summary.week.rank, decks: summary.week.decks } } : {},
52584
+ ...isTrending(summary.trend) ? { trending: summary.trend } : {},
52585
+ ...summary.bracket ? { bracketEstimate: summary.bracket, bracketNote: "EDHVault's estimate, from how many Game Changers this commander's decks run on average." } : {},
52586
+ ...!wantCedh && page.cedh ? { cedhDecks: page.cedh.deckCount } : {},
52587
+ ...page.deckCount < FEW_DECKS ? { fewDecks: `Only ${page.deckCount} decks: the percentages move a lot from week to week.` } : {},
52588
+ about: "inclusion: share of this commander's decks that run the card. synergy: how many points more often this commander's decks run it than other decks that could. lift: how many times more often than its overall play rate predicts. trending: EDHREC's fire score (3 and up).",
52589
+ sections: out,
52590
+ links: {
52591
+ edhrec: edhrecCommanderUrl(summary.slug),
52592
+ edhvault: `https://edhvault.com/commander/${summary.slug}`
52593
+ },
52594
+ dataAsOf: page.builtAt ?? index.builtAt,
52595
+ ...missing.length ? { couldntLoad: missing } : {},
52596
+ ...stale.length ? { olderCopy: stale } : {},
52597
+ credit: EDHREC_CREDIT
52598
+ });
52599
+ }
52600
+ };
52601
+ var TOOLS = [listDecks, getDeck, collectionLookup, cardSearch, cardTool, commanderTool, deckCombos2, planOdds];
52420
52602
 
52421
52603
  // src/server.ts
52422
52604
  async function serve(version2, ctx) {
@@ -52446,7 +52628,7 @@ var say = (m) => process.stderr.write(`${m}
52446
52628
  var transport = {
52447
52629
  fetchImpl: ((url2, init) => fetch(`${ORIGIN}${url2}`, {
52448
52630
  ...init,
52449
- headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.4"}` }
52631
+ headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.5"}` }
52450
52632
  }))
52451
52633
  };
52452
52634
  async function store(dir) {
@@ -52462,7 +52644,7 @@ async function secretFromEnv() {
52462
52644
  async function main() {
52463
52645
  const args = process.argv.slice(2);
52464
52646
  if (args.includes("--version")) {
52465
- say("0.2.4");
52647
+ say("0.2.5");
52466
52648
  return;
52467
52649
  }
52468
52650
  const dir = configDir();
@@ -52484,7 +52666,7 @@ async function main() {
52484
52666
  return;
52485
52667
  }
52486
52668
  const extras = extrasLoader({ dir, origin: ORIGIN });
52487
- await serve("0.2.4", {
52669
+ await serve("0.2.5", {
52488
52670
  library: new Library({ secret: await secretFromEnv() ?? loadSecret(secrets), dir, transport }),
52489
52671
  catalog: catalogLoader({ dir, origin: ORIGIN, prices: extras.prices }),
52490
52672
  combos: comboLoader({ dir, origin: ORIGIN }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edhvault-mcp",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Read your own EDHVault decks and collection from a local AI tool. Read-only.",
5
5
  "type": "module",
6
6
  "bin": {