evidence-mcp-dev 1.0.15 → 1.0.17

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 (2) hide show
  1. package/dist/index.js +53 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5248,7 +5248,7 @@ async function verifyClaim(claim, id, cfg, decide, read2 = readPaper) {
5248
5248
  const paper = await read2(id);
5249
5249
  out.id = paper.id;
5250
5250
  if ("error" in paper) return { ...out, error: paper.error };
5251
- if (!cfg || !decide) return { ...out, error: "no verify model configured (FH_VERIFY_URL)" };
5251
+ if (!cfg || !decide) return { ...out, error: "no decision model configured: set FH_VERIFY_PROVIDER and its API key in .env" };
5252
5252
  out.basis = paper.basis;
5253
5253
  out.glyphs_unresolved = countUnresolved(paper.text);
5254
5254
  if (paper.basis === "title") return { ...out, verdict: "fail", reason: NOTHING_TO_VERIFY };
@@ -5586,14 +5586,24 @@ function normalizeQuery5(q) {
5586
5586
  if (yr) out.years = `${yr.min === "1000" ? "" : yr.min}-${yr.max}`;
5587
5587
  return out;
5588
5588
  }
5589
- var searchKey5 = (q) => createHash8("sha1").update(JSON.stringify(["cites", q.id, q.types ?? [], q.years ?? "", q.sort, q.max_results])).digest("hex").slice(0, 16);
5589
+ var searchKey5 = (q) => createHash8("sha1").update(JSON.stringify(["cites2", q.id, q.types ?? [], q.years ?? "", q.sort, q.max_results])).digest("hex").slice(0, 16);
5590
5590
  var live4 = (url) => fetchText(url, { "User-Agent": "evidence-mcp", Accept: "application/json" });
5591
5591
  var OA = "https://api.openalex.org";
5592
5592
  var mailto = () => openalexParams();
5593
- function citingUrl(work, q, page) {
5593
+ var COMMENT_TYPES = ["comment", "letter", "editorial"];
5594
+ var wantsComments = (q) => !!q.types?.some((t) => COMMENT_TYPES.includes(t));
5595
+ function citingUrl(work, q, page, perPage = PAGE, slack = 1) {
5594
5596
  const yr = yearRange(q.years);
5595
- const years = yr && !("error" in yr) ? `,publication_year:${yr.min === "1000" ? "" : yr.min}-${yr.max}` : "";
5596
- return `${OA}/works?filter=cites:${work},has_pmid:true${years}&sort=${q.sort === "cited" ? "cited_by_count:desc" : "publication_date:desc"}&per-page=${PAGE}&page=${page}&select=ids&${mailto()}`;
5597
+ const years = yr && !("error" in yr) ? `,publication_year:${yr.min === "1000" ? "" : Number(yr.min) - slack}-${Number(yr.max) + slack}` : "";
5598
+ return `${OA}/works?filter=cites:${work},has_pmid:true${years}&sort=${q.sort === "cited" ? "cited_by_count:desc" : "publication_date:desc"}&per-page=${perPage}&page=${page}&select=ids&${mailto()}`;
5599
+ }
5600
+ function parseCommentIn(xml) {
5601
+ const out = [];
5602
+ for (const m of xml.matchAll(/<CommentsCorrections\b[^>]*RefType="CommentIn"[^>]*>([\s\S]*?)<\/CommentsCorrections>/g)) {
5603
+ const p = /<PMID\b[^>]*>(\d+)<\/PMID>/.exec(m[1])?.[1];
5604
+ if (p && !out.includes(p)) out.push(p);
5605
+ }
5606
+ return out;
5597
5607
  }
5598
5608
  function parseCiting(json2) {
5599
5609
  const d = JSON.parse(json2);
@@ -5615,36 +5625,51 @@ async function citingArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liv
5615
5625
  } catch {
5616
5626
  }
5617
5627
  }
5618
- let work;
5628
+ let work, pmid;
5619
5629
  try {
5620
- const w = JSON.parse(await fetchImpl(`${OA}/works/${q.id}?select=id&${mailto()}`));
5630
+ const w = JSON.parse(await fetchImpl(`${OA}/works/${q.id}?select=id,ids&${mailto()}`));
5621
5631
  work = String(w?.id ?? "").split("/").pop() ?? "";
5622
5632
  if (!work) return { ok: false, error: `openalex: ${q.id} not found` };
5633
+ pmid = q.id.startsWith("pmid:") ? q.id.slice(5) : String(w?.ids?.pmid ?? "").split("/").pop() || null;
5623
5634
  } catch (e) {
5624
5635
  const m = e instanceof Error ? e.message : String(e);
5625
5636
  return /\b404\b/.test(m) ? { ok: false, error: `${q.id} not in OpenAlex`, input: true } : { ok: false, error: `openalex: ${m}` };
5626
5637
  }
5627
- const rows = [];
5628
- let total = 0, matched = 0;
5638
+ const yr = yearRange(q.years);
5639
+ const inYears = (r) => !yr || "error" in yr || !!r[3] && r[3] >= yr.min && r[3] <= yr.max;
5640
+ const newestFirst = (rows2) => q.sort === "newest" ? rows2.sort((a, b) => (b[3] ?? "").localeCompare(a[3] ?? "")) : rows2;
5641
+ let rows, count, commentsOn;
5629
5642
  try {
5643
+ let comments = [];
5644
+ if (wantsComments(q) && pmid) {
5645
+ const ids = parseCommentIn(await fetchImpl(efetchUrl(pmid)));
5646
+ if (ids.length) comments = newestFirst(parseEsummary(await fetchImpl(esummaryUrl(ids)), ids, libraryDir));
5647
+ }
5648
+ const seen2 = new Set(comments.map((r) => r[0]));
5649
+ const cited = [];
5650
+ let total = 0, matched = 0;
5630
5651
  for (let page = 1; page <= MAX_PAGES; page++) {
5631
5652
  const { total: n, pmids } = parseCiting(await fetchImpl(citingUrl(work, q, page)));
5632
5653
  total = n;
5633
5654
  if (!pmids.length) break;
5634
- const need = q.types ? pmids : pmids.slice(0, q.max_results - rows.length);
5655
+ const need = pmids.filter((p) => !seen2.has(p));
5635
5656
  const got = need.length ? parseEsummary(await fetchImpl(esummaryUrl(need)), need, libraryDir) : [];
5636
5657
  for (const r of got) {
5637
- if (q.types && !typeMatch(r, q.types)) continue;
5658
+ if (!inYears(r) || q.types && !typeMatch(r, q.types)) continue;
5638
5659
  matched++;
5639
- if (rows.length < q.max_results) rows.push(r);
5660
+ cited.push(r);
5640
5661
  }
5641
- if (!q.types && rows.length >= q.max_results) break;
5662
+ if (!q.types && comments.length + cited.length >= q.max_results) break;
5642
5663
  if (page * PAGE >= n) break;
5643
5664
  }
5665
+ if (!q.types && q.years) total = parseCiting(await fetchImpl(citingUrl(work, q, 1, 1, 0))).total;
5666
+ rows = [...comments, ...newestFirst(cited)].slice(0, q.max_results);
5667
+ count = q.types ? comments.length + matched : total;
5668
+ commentsOn = comments.slice(0, rows.length).map((r) => r[0]);
5644
5669
  } catch (e) {
5645
5670
  return { ok: false, error: `citations: ${e instanceof Error ? e.message : String(e)}` };
5646
5671
  }
5647
- const result = { source: "openalex+pubmed", query: q, total: q.types ? matched : total, columns: COLUMNS3, rows, searched: today() };
5672
+ const result = { source: "openalex+pubmed", query: q, total: count, ...commentsOn.length ? { comments_on: commentsOn } : {}, columns: COLUMNS3, rows, searched: today() };
5648
5673
  try {
5649
5674
  mkdirSync12(dirname9(file3), { recursive: true });
5650
5675
  writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
@@ -5904,7 +5929,7 @@ Tools
5904
5929
  - fh_verify_claim(claim, id) \u2014 does this one source state this one finding? A decision model judges the stored text and returns a verdict.
5905
5930
  - fh_pubmed_fetch_articles(pmids) \u2014 title, first author, year, publication types, retracted and level for up to 200 PMIDs at once; faster and far smaller than asking PubMed, known papers from disk, the rest in one request and stored. For abstract or full text: fh_library_read.
5906
5931
  - fh_pubmed_search_articles(query, max_results?, sort?, years?) \u2014 search PubMed in its own syntax: the total and rows in columns order (PMID, title, first author, year, journal, publication types, PMCID, library level); faster and far smaller than asking PubMed. Cached a week.
5907
- ${citationsEnabled() ? "- fh_pubmed_citing_articles(id, types?, years?, sort?, max_results?) \u2014 the papers that cite a paper (pmid: or doi:), as rows in fh_pubmed_search_articles' columns; types filters by publication type (meta-analysis, randomized controlled trial, review), years by publication year; sort newest | cited. For a trial's follow-ups, newer meta-analyses that include it, and comments on it. Cached a week.\n" : ""}- fh_clinicaltrials_search_studies(query | intervention | condition, status?, sort?, max_results?) \u2014 search ClinicalTrials.gov: the total and rows in columns order (NCT ID, title, status, phase, enrollment, dates, primary outcome, conditions, interventions, has_results). Cached a week.
5932
+ ${citationsEnabled() ? "- fh_pubmed_citing_articles(id, types?, years?, sort?, max_results?) \u2014 the papers that cite a paper (pmid: or doi:), as rows in fh_pubmed_search_articles' columns: follow-ups of a trial, later meta-analyses that include it, guidelines (sort: cited), comments on it (types comment, letter, editorial: PubMed's comments on the paper first, listed in comments_on). At most 100 rows, no paging: narrow with types or years. Cached a week.\n" : ""}- fh_clinicaltrials_search_studies(query | intervention | condition, status?, sort?, max_results?) \u2014 search ClinicalTrials.gov: the total and rows in columns order (NCT ID, title, status, phase, enrollment, dates, primary outcome, conditions, interventions, has_results). Cached a week.
5908
5933
  - fh_dailymed_search_labels(drug_name, labeler?, max_results?) \u2014 find FDA drug labels by generic or brand name: the total and rows in columns order (set ID, title, labeler, published, version, level), newest first; labeler narrows to one company. Use it rather than DailyMed's search page, which shows no set IDs as Markdown. Cached a week.
5909
5934
  ${webSearchConfigured() ? "- fh_web_search(query, max_results?) \u2014 search the web; use it instead of the built-in web search. Links (title, URL, date, author) with a short passage from each page, not the page text, so a fraction of the context; read a result with fh_fetch_url. site: in the query restricts it to a site, as with any search engine. For more results, search again with other words. Cached locally for a week.\n" : ""}- fh_clinicaltrials_get_study_record(nct) \u2014 one trial as a review needs it (status, design, enrollment, dates, outcomes, eligibility, result publications, summary), from the stored record; added first when missing.
5910
5935
  - fh_clinicaltrials_get_study_results(nct, max_chars?) \u2014 a trial's posted results as Markdown, capped; the outcome titles listed for fh_library_read.
@@ -5956,7 +5981,7 @@ function noticeTag(m) {
5956
5981
  ].filter(Boolean);
5957
5982
  return parts.length ? " " + parts.join(" ") : "";
5958
5983
  }
5959
- var modelFailure = (error, cfg) => error.startsWith("no verify model configured") || !!cfg && error.startsWith(`${cfg.model}:`);
5984
+ var modelFailure = (error, cfg) => error.startsWith("no decision model configured") || !!cfg && error.startsWith(`${cfg.model}:`);
5960
5985
  function registerTools(server2) {
5961
5986
  async function completeFulltext(paths, meta, requested) {
5962
5987
  const paper = { title: meta.title, pmid: meta.pmid, pmcid: meta.pmcid, doi: meta.doi, headLine: readHeadLine(paths) };
@@ -6492,12 +6517,17 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
6492
6517
  );
6493
6518
  if (citationsEnabled()) server2.tool(
6494
6519
  "fh_pubmed_citing_articles",
6495
- `The papers that cite a paper: OpenAlex finds them, PubMed gives the rows \u2014 the total and up to ${MAX_RESULTS4} rows as arrays in columns order, as fh_pubmed_search_articles: PMID, title, first author, year, journal, publication types, PMCID, library level. For a trial's follow-ups and long-term results, newer meta-analyses that include it, and comments, letters and re-analyses of it. types narrows to publication types ("meta-analysis", "randomized controlled trial", "review", "comment"); years to publication years; sort newest (default) or cited (most cited first). Cached ${searchCacheDays()} days.`,
6520
+ `The papers that cite a paper, as rows in fh_pubmed_search_articles' columns: PMID, title, first author, year, journal, publication types, PMCID, library level. Use it for a trial's follow-ups, later meta-analyses that include it, guidelines (sort: cited) and comments on it.
6521
+ - types: PubMed publication types, any of them; a paper without one (many plain articles, some guidelines) never matches.
6522
+ - Comments: with comment, letter or editorial in types, the comments PubMed links to the paper come first, of any year and type, and comments_on lists their PMIDs. The other rows only cite the paper and are mostly about something else.
6523
+ - years and sort newest go by the year column.
6524
+ - At most ${MAX_RESULTS4} rows, no paging: for more, narrow with types or years, or sort: cited. total counts every match.
6525
+ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
6496
6526
  {
6497
6527
  id: z.string().describe('The cited paper: "pmid:18378520" or "doi:10.1056/NEJMoa0801317".'),
6498
- types: z.array(z.string()).optional().describe('Publication types, any of them: ["meta-analysis", "systematic review"].'),
6499
- years: z.string().optional().describe('Publication years of the citing papers: "2020-2026", "2022-", "-2019" or "2022".'),
6500
- sort: z.enum(["newest", "cited"]).default("newest").describe("newest (publication date, latest first) or cited (most cited first)."),
6528
+ types: z.array(z.string()).optional().describe('Publication types, any of them: "meta-analysis", "systematic review", "randomized controlled trial", "review", "guideline", "comment", "letter", "editorial".'),
6529
+ years: z.string().optional().describe('Publication years of the citing papers, as in the year column: "2020-2026", "2022-", "-2019" or "2022". Not applied to the comments PubMed links.'),
6530
+ sort: z.enum(["newest", "cited"]).default("newest").describe("newest (latest year first) or cited (most cited first)."),
6501
6531
  max_results: z.number().int().min(1).max(MAX_RESULTS4).default(20).describe("Rows to return (1\u2013100).")
6502
6532
  },
6503
6533
  async (args) => {
@@ -6510,8 +6540,9 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
6510
6540
  }
6511
6541
  bump("search", r.cached);
6512
6542
  const q = r.result.query;
6513
- log("search", "citing", `ok ${r.cached ? "cached" : secs} rows=${r.result.rows.length} total=${r.result.total}${q.types ? ` types=${q.types.join(",")}` : ""}${q.years ? ` years=${q.years}` : ""}${q.sort !== "newest" ? ` sort=${q.sort}` : ""} | ${q.id}`);
6514
- return { content: [{ type: "text", text: searchAnswer(r.result) }] };
6543
+ log("search", "citing", `ok ${r.cached ? "cached" : secs} rows=${r.result.rows.length} total=${r.result.total}${r.result.comments_on ? ` comments_on=${r.result.comments_on.length}` : ""}${q.types ? ` types=${q.types.join(",")}` : ""}${q.years ? ` years=${q.years}` : ""}${q.sort !== "newest" ? ` sort=${q.sort}` : ""} | ${q.id}`);
6544
+ const { total, comments_on, columns: columns2, rows } = r.result;
6545
+ return { content: [{ type: "text", text: compact2({ total, comments_on, columns: columns2, rows }) }] };
6515
6546
  }
6516
6547
  );
6517
6548
  server2.tool(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {