evidence-mcp-dev 1.0.23 → 1.0.25

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 +56 -73
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4529,13 +4529,13 @@ var FIELDS2 = ["relevance", "population", "design", "n", "outcome", "finding", "
4529
4529
  var SCHEMA = {
4530
4530
  type: "object",
4531
4531
  properties: {
4532
- relevance: { type: "string", enum: ["direct", "indirect", "background", "off-topic"], description: "direct: the intervention for the topic's goal; indirect: the intervention for another outcome, or a related drug; background: mechanism, epidemiology; off-topic: not about the topic" },
4532
+ relevance: { type: "string", enum: ["direct", "indirect", "background", "off-topic"], description: "direct: the topic's intervention itself studied in humans, any outcome, with or without comparators; indirect: a broader category it belongs to, a related intervention, or it pooled with others without its own result; background: animal, in vitro, mechanism, epidemiology; off-topic: not about the topic" },
4533
4533
  population: { type: "string", enum: ["humans", "animals", "in vitro", "none"] },
4534
4534
  design: { type: "string", description: "study design, e.g. meta-analysis, systematic review, RCT, cohort, case-control, case report, review, animal study, in vitro" },
4535
4535
  n: { type: ["integer", "null"], description: "participants, if the abstract states it" },
4536
4536
  outcome: { type: "string", enum: ["hard", "surrogate", "none"], description: "hard: death, incidence, clinical events; surrogate: biomarker, imaging" },
4537
- finding: { type: "string", enum: ["benefit", "no effect", "harm", "mixed", "none"] },
4538
- aspect: { type: "string", enum: ["efficacy", "safety", "mechanism", "dosing", "interaction", "other"] },
4537
+ finding: { type: "string", enum: ["benefit", "no effect", "harm", "mixed", "none"], description: "the intervention's effect; harm: caused by the intervention, not by the effect it achieved" },
4538
+ aspect: { type: "string", enum: ["efficacy", "safety", "mechanism", "dosing", "interaction", "other"], description: "efficacy: any benefit outcome, null results too; safety: adverse effects" },
4539
4539
  reason: { type: "string", description: "one sentence: what the paper adds to the topic" }
4540
4540
  },
4541
4541
  required: [...FIELDS2],
@@ -4551,6 +4551,11 @@ var ScreenError = class extends Error {
4551
4551
  }
4552
4552
  status;
4553
4553
  };
4554
+ var Refusal = class extends Error {
4555
+ constructor() {
4556
+ super("refusal");
4557
+ }
4558
+ };
4554
4559
  var PLAIN = { key: "FH_EVMAP_SCREEN_API_KEY", model: "FH_EVMAP_SCREEN_MODEL", url: "FH_EVMAP_SCREEN_URL" };
4555
4560
  function hint(status, message, v = PLAIN) {
4556
4561
  if (status === 401 || status === 403 || /api key|api_key|x-api-key|unauthori[sz]ed|permission/i.test(message)) return `the API key is missing, wrong or has no access to the model \u2014 ${v.key} in the server's .env`;
@@ -4584,7 +4589,7 @@ function askFor(c) {
4584
4589
  try {
4585
4590
  return await ask(text4);
4586
4591
  } catch (e) {
4587
- throw new Error(describe2(e, where(c), c.vars));
4592
+ throw e instanceof Refusal ? e : new Error(describe2(e, where(c), c.vars));
4588
4593
  }
4589
4594
  };
4590
4595
  }
@@ -4597,7 +4602,7 @@ function anthropicAsk(apiKey2, model, baseURL) {
4597
4602
  output_config: { effort: "low", format: { type: "json_schema", schema: SCHEMA } },
4598
4603
  messages: [{ role: "user", content: text4 }]
4599
4604
  });
4600
- if (r.stop_reason === "refusal") throw new Error("refusal");
4605
+ if (r.stop_reason === "refusal") throw new Refusal();
4601
4606
  if (r.stop_reason === "max_tokens") throw new Error("max_tokens: the answer was cut off");
4602
4607
  const block = r.content.find((b) => b.type === "text");
4603
4608
  if (!block) throw new Error("no answer");
@@ -4627,7 +4632,7 @@ function openaiAsk(baseUrl, apiKey2, model, fetchImpl = fetch) {
4627
4632
  const choice = body?.choices?.[0];
4628
4633
  if (choice?.finish_reason === "length") throw new Error("max_tokens: the answer was cut off");
4629
4634
  const content = choice?.message?.content;
4630
- if (typeof content !== "string") throw new Error(choice?.message?.refusal ? "refusal" : "no answer");
4635
+ if (typeof content !== "string") throw choice?.message?.refusal ? new Refusal() : new Error("no answer");
4631
4636
  return parseAnswer(content);
4632
4637
  }
4633
4638
  };
@@ -4640,6 +4645,7 @@ function parseAnswer(text4) {
4640
4645
  throw new Error(`the answer is not JSON: ${text4.slice(0, 80)}`);
4641
4646
  }
4642
4647
  if (!a || typeof a !== "object" || !SCHEMA.properties.relevance.enum.includes(a.relevance)) throw new Error(`the answer has no valid relevance: ${text4.slice(0, 80)}`);
4648
+ if (typeof a.reason === "string") a.reason = a.reason.replace(/[\s{}[\]"]+$/, "");
4643
4649
  return a;
4644
4650
  }
4645
4651
  async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel, note = () => {
@@ -4654,7 +4660,8 @@ async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel,
4654
4660
  const file3 = join9(dir, `${pmid}.json`);
4655
4661
  if (existsSync10(file3)) {
4656
4662
  try {
4657
- out[i] = { pmid, screened: JSON.parse(readFileSync8(file3, "utf8")), cached: true };
4663
+ const c = JSON.parse(readFileSync8(file3, "utf8"));
4664
+ out[i] = c?.refused === true ? { pmid, refused: true, cached: true } : { pmid, screened: c, cached: true };
4658
4665
  continue;
4659
4666
  } catch {
4660
4667
  }
@@ -4672,7 +4679,11 @@ async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel,
4672
4679
  writeAtomic(file3, JSON.stringify(s) + "\n");
4673
4680
  out[i] = { pmid, screened: s, cached: false };
4674
4681
  } catch (e) {
4675
- out[i] = { pmid, error: e instanceof Error ? e.message : String(e), cached: false };
4682
+ if (e instanceof Refusal) {
4683
+ mkdirSync8(dirname4(file3), { recursive: true });
4684
+ writeAtomic(file3, '{"refused":true}\n');
4685
+ out[i] = { pmid, refused: true, cached: false };
4686
+ } else out[i] = { pmid, error: e instanceof Error ? e.message : String(e), cached: false };
4676
4687
  }
4677
4688
  note(out[i], Date.now() - t);
4678
4689
  }
@@ -4692,6 +4703,7 @@ function score(s, types, queries, citesPerYear = 0, inReviews = 0) {
4692
4703
  }
4693
4704
  function screenLine(r, ms, model) {
4694
4705
  const secs = `${(ms / 1e3).toFixed(1)}s`;
4706
+ if (r.refused) return `refused screen ${model} ${secs}`;
4695
4707
  if (!r.screened) return `failed screen ${model} ${secs}: ${r.error}`;
4696
4708
  const f = r.screened;
4697
4709
  return `screened ${f.relevance} \xB7 ${f.population} \xB7 ${f.design} \xB7 n=${f.n ?? "-"} \xB7 ${f.outcome} \xB7 ${f.finding} \xB7 ${f.aspect} \xB7 ${model} ${secs} \xB7 ${f.reason}`;
@@ -4923,7 +4935,7 @@ var RANK_MODELS = { anthropic: "claude-opus-5-5", openai: "gpt-5.5", google: "ge
4923
4935
  var RANK_TIMEOUT_MS = 18e4;
4924
4936
  function rankPrompt(topic, rows, picks) {
4925
4937
  const list5 = rows.map((x, i) => `${i + 1}. ${x.title ?? "(no title)"} (${x.year ?? "-"}; ${x.design || "-"}; n=${x.n ?? "-"}; ${x.relevance}; ${x.aspect}; ${x.signals})`).join("\n");
4926
- return `Below are ${rows.length} candidate articles on the topic "${topic}". Pick the ${picks} that matter most \u2014 the key trials and meta-analyses for each important question, including safety and the null results. Answer with their numbers, most important first.
4938
+ return `Below are ${rows.length} candidate articles on the topic "${topic}". Pick the ${picks} that matter most \u2014 the key trials and meta-analyses for each important question, including safety and the null results; only articles that study the topic's intervention itself. Answer with their numbers, most important first.
4927
4939
 
4928
4940
  ${list5}`;
4929
4941
  }
@@ -5199,7 +5211,7 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
5199
5211
  }
5200
5212
  scored = kept.map(scoreOf);
5201
5213
  }
5202
- const screenedCsv = [["pmid", "kept", "error", ...FIELDS2].join(","), ...scored.map(({ p, f, sc }) => [p.pmid, sc === null ? "" : sc > 0 ? "yes" : "no", by.get(p.pmid)?.error ?? "", ...FIELDS2.map((k) => f?.[k] ?? "")].map(csvCell).join(","))].join("\n") + "\n";
5214
+ const screenedCsv = [["pmid", "kept", "error", ...FIELDS2].join(","), ...scored.map(({ p, f, sc }) => [p.pmid, sc === null ? "" : sc > 0 ? "yes" : "no", by.get(p.pmid)?.error ?? (by.get(p.pmid)?.refused ? "refused" : ""), ...FIELDS2.map((k) => f?.[k] ?? "")].map(csvCell).join(","))].join("\n") + "\n";
5203
5215
  let ranked = scored.filter(({ sc }) => sc !== 0).sort((a, b) => (b.sc ?? -1) - (a.sc ?? -1));
5204
5216
  const pick = /* @__PURE__ */ new Map();
5205
5217
  let rankRun = { off: true };
@@ -5221,7 +5233,8 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
5221
5233
  const lines = ranked.map(({ p, f, sc }) => row3(p, sc ?? "", pick.get(p.pmid) ?? "", signals(p), f));
5222
5234
  const count = (k) => results2.filter((r) => r.screened?.relevance === k).length;
5223
5235
  const failures = results2.filter((r) => r.error);
5224
- const screenRun = { screened: results2.filter((r) => r.screened).length, not_screened: failures.length, ...failures.length ? { first_error: failures[0].error } : {}, excluded: count("off-topic"), relevance: { direct: count("direct"), indirect: count("indirect"), background: count("background") }, cached: results2.filter((r) => r.cached).length, citations: { counted: cites.size, failed: counted.failed }, citation_searching: { reviews: K, identified: fromReviews, failed: refsFailed }, ranking: rankRun, seconds: Math.round((Date.now() - t) / 1e3) };
5236
+ const refused = results2.filter((r) => r.refused).length;
5237
+ const screenRun = { screened: results2.filter((r) => r.screened).length, not_screened: failures.length, refused, ...failures.length ? { first_error: failures[0].error } : {}, excluded: count("off-topic"), relevance: { direct: count("direct"), indirect: count("indirect"), background: count("background") }, cached: results2.filter((r) => r.cached).length, citations: { counted: cites.size, failed: counted.failed }, citation_searching: { reviews: K, identified: fromReviews, failed: refsFailed }, ranking: rankRun, seconds: Math.round((Date.now() - t) / 1e3) };
5225
5238
  const hash = cacheKey(model, screening, topic);
5226
5239
  const state = "screened";
5227
5240
  const finished = (/* @__PURE__ */ new Date()).toISOString();
@@ -5245,7 +5258,7 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
5245
5258
  const sUp = db.prepare("UPDATE articles SET relevance = ?, population = ?, design = ?, n = ?, outcome = ?, finding = ?, aspect = ?, reason = ?, error = ? WHERE pmid = ?");
5246
5259
  for (const r of results2) {
5247
5260
  const f = r.screened;
5248
- sUp.run(f?.relevance ?? null, f?.population ?? null, f?.design ?? null, typeof f?.n === "number" ? f.n : null, f?.outcome ?? null, f?.finding ?? null, f?.aspect ?? null, f?.reason ?? null, r.error ?? null, r.pmid);
5261
+ sUp.run(f?.relevance ?? null, f?.population ?? null, f?.design ?? null, typeof f?.n === "number" ? f.n : null, f?.outcome ?? null, f?.finding ?? null, f?.aspect ?? null, f?.reason ?? null, r.error ?? (r.refused ? "refused" : null), r.pmid);
5249
5262
  }
5250
5263
  db.exec("UPDATE articles SET score = NULL, pick = NULL");
5251
5264
  const rUp = db.prepare("UPDATE articles SET score = ?, pick = ? WHERE pmid = ?");
@@ -5267,9 +5280,10 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
5267
5280
  db.close();
5268
5281
  const partial = failures.length ? { screening_errors: failures.length, first_error: failures[0].error, note: `${failures.length} of ${results2.length} papers could not be screened; they stay in the map, unscored, at the end. Call again to retry only those: screened papers answer from the cache.` } : {};
5269
5282
  const rankFailed = typeof rankRun.error === "string" ? { ranking_error: `the map is in score order: the re-ranking failed (${rankRun.error})` } : {};
5283
+ const citesFailed = counted.failed || refsFailed ? { citations_error: `citation counts failed for ${counted.failed} of ${kept.length} articles, reference lists for ${refsFailed} of ${reviewIds.length} reviews${counted.error ? ` (${counted.error})` : ""}: the order is weaker. Call again later with the evid and the same queries: searches and screening answer from the cache.` } : {};
5270
5284
  const failedQueries = runs.filter((r) => r.error).map((r) => ({ query: r.query, error: r.error }));
5271
5285
  const emptyQueries = runs.filter((r) => !r.error && r.total === 0).map((r) => r.query);
5272
- return { ok: true, evid: o.evid, included: lines.length, ...failedQueries.length ? { failed_queries: failedQueries } : {}, ...emptyQueries.length ? { empty_queries: emptyQueries } : {}, ...partial, ...rankFailed };
5286
+ return { ok: true, evid: o.evid, included: lines.length, ...failedQueries.length ? { failed_queries: failedQueries } : {}, ...emptyQueries.length ? { empty_queries: emptyQueries } : {}, ...partial, ...rankFailed, ...citesFailed };
5273
5287
  }
5274
5288
  var MAX_ROWS = 500;
5275
5289
  function getMap(lib, evid, opts = {}) {
@@ -6965,62 +6979,31 @@ var pkg = (() => {
6965
6979
  return { name: "evidence-mcp", version: "0.0.0" };
6966
6980
  }
6967
6981
  })();
6968
- var INSTRUCTIONS = `evidence-mcp keeps a local library of scientific articles, FDA drug labels, clinical trial records and web pages, so you can check what a source actually says, and searches ClinicalTrials.gov. The server downloads each record, converts it to Markdown and stores it on disk. Every tool returns a small JSON answer; the document itself never enters your context \u2014 except fh_fetch_url, which is the standard fetch tool with a cache. One ID per call.
6982
+ var INSTRUCTIONS = `evidence-mcp keeps a local library of scientific articles, FDA drug labels, clinical trial records and web pages, so you can check what a source actually says. Each record is downloaded once, stored as Markdown and read in small pieces: answers are small JSON, the document never enters your context \u2014 except fh_fetch_url, the standard fetch tool with a cache.
6969
6983
 
6970
- IDs \u2014 always "type:value"
6971
- - pmid:30955454 \u2014 an article by PubMed ID. Bare digits are taken as a PMID.
6972
- - doi:10.\u2026 \u2014 an article by DOI. A DOI PubMed indexes is stored under its PMID; any other gets its record from Crossref.
6973
- - dailymed:<set ID> \u2014 an FDA prescribing-information label, current version. The set ID comes from fh_dailymed_search_labels, or is the "setid=" value in the label's DailyMed URL.
6974
- - nct:05173896 \u2014 a ClinicalTrials.gov trial record, current version. NCT05173896 is accepted too.
6984
+ IDs \u2014 "type:value", one per call (fh_pubmed_fetch_articles: up to 200 PMIDs)
6985
+ - pmid:30955454 \u2014 an article; bare digits count as a PMID.
6986
+ - doi:10.\u2026 \u2014 an article; a DOI PubMed indexes is stored under its PMID, any other comes from Crossref.
6987
+ - dailymed:<set ID> \u2014 an FDA label, current version; the set ID from fh_dailymed_search_labels or the label URL's "setid=".
6988
+ - nct:05173896 \u2014 a ClinicalTrials.gov record, current version; NCT05173896 is accepted.
6989
+ A URL is no ID: send the ID of a PubMed, doi.org, ClinicalTrials.gov or DailyMed URL; any other page: fh_fetch_url.
6975
6990
 
6976
6991
  Tools
6977
- - fh_info() \u2014 this server's package and version, then the whole library: entry counts by type and level, the retrieval sources, browsers, the decision model, the configuration, this server's cache hits and misses since it started (cache).
6978
- - fh_library_add(id) \u2014 download and store one record; returns its status. A stored full text is returned without any download; an abstract-level record retries only the sources that failed transiently; a record older than 30 days gets its correction notices re-read.
6979
- - fh_library_status(id) \u2014 the status of one record without downloading; level "missing" when it is not stored.
6980
- - fh_library_read(id, section?, query?, max_chars?, max_hits?, abstract_only?) \u2014 one small piece of a stored document: its outline, one section, or the passages matching a query. abstract_only: true when the abstract is enough \u2014 answered at once, no full-text download.
6981
- - 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.
6982
- - 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 articles from disk, the rest in one request and stored. For abstract or full text: fh_library_read.
6983
- - 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.
6984
- ${citationsEnabled() ? "- fh_pubmed_citing_articles(id, types?, years?, sort?, max_results?) \u2014 the articles that cite an article (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 article first, listed in comments_on). At most 100 rows, no paging: narrow with types or years. Cached a week.\n" : ""}${evidEnabled() ? "- fh_evid_create(metadata), fh_evid_find(query), fh_evid_list_objects(evid), fh_evid_put(evid, name, content), fh_evid_get(evid, name, section?, query?, lines?, max_chars?, max_hits?, previous?) \u2014 an EVID (evid:<16 hex digits>) is a store that outlives the session: metadata fixed at creation, objects (.json, .csv, .txt, .md) any later session or agent given the EVID reads back. Nothing can be deleted; a put keeps the replaced object as its previous version.\n" : ""}${evidenceMapEnabled() ? "- fh_create_evidence_map(topic | evid, queries, screening?) \u2014 builds the evidence map for a topic: the PubMed articles that matter, most important first.\n- fh_get_evidence_map(evid, top?) \u2014 reads it.\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.
6985
- - 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.
6986
- ${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.
6987
- - 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.
6988
- - fh_fetch_url(url, max_length?, start_index?, raw?, title_only?) \u2014 a web page as Markdown, same call and same answer as the standard fetch tool ("Contents of <url>:" and the page, cut at max_length with a note on how to continue). Prefer it for every URL: a cached page answers from disk, a walled or script-rendered page runs through the browser and unlocker stages in one call. PDFs as Markdown; XML, JSON and other text as is. title_only returns the title line alone \u2014 enough to verify a link, at a few tokens.
6989
-
6990
- Hints
6991
- - fh_library_read and fh_verify_claim store a missing record themselves; the fh_library_read answer then carries added: true. No fh_library_add necessary first.
6992
- - Many articles to look over (a search, an evidence map): abstract_only: true for each, then without it only the articles that need the full text.
6993
- - citable false \u2014 the article is retracted (a retraction notice, or PubMed's publication type), or holds nothing to read: no abstract and no full text. comment says which; corrections lists the notices as {type, pmid, source}.
6994
- - level \u2014 what is stored: "full_text", "abstract" or "title" (not even an abstract; citable false). "abstract": searched, no full text found (the log says why); or fulltext "not tried": stored from PubMed alone; the next read without abstract_only, verify or add searches for the full text.
6995
- - error "pmid not found", "doi not found", "ctgov: not a study record", "dailymed: not an SPL document" \u2014 no service knows the ID. Remembered for a day (FH_RETRY_AFTER_DAYS): the same call answers from disk with the date it was checked; after that the service is asked again. "invalid id" \u2014 the ID itself is malformed; the same call gives the same answer. A URL is no library ID: it is refused with what to send instead \u2014 the record's ID for a PubMed, doi.org, ClinicalTrials.gov or DailyMed URL, else fh_fetch_url for the web page.
6996
- - Calls may run in parallel: fh_library_add, fh_library_read and fh_verify_claim. Two calls on the same missing record share one add.
6997
- - fh_fetch_url takes any URL that is not an article, label or trial record; those have IDs, and fh_library_add, fh_library_read and fh_verify_claim work on the stored document. A second pass over the same review reads every page from disk; a failed fetch is remembered for a day.
6998
- - To verify that a web page exists and what it is: fh_fetch_url(url, title_only: true). The answer is "Contents of <url>:" and the page's title line \u2014 a few tokens \u2014 or the fetch error; the page itself is stored in full, so a later fh_fetch_url of the same URL reads from disk.
6999
-
7000
- Verifying a claim
7001
- - fh_verify_claim judges one claim against one stored document. A finding backed by three articles takes three calls with the same claim.
7002
- - It expects the finding as a complete sentence: who or what, the intervention, the outcome, the number. Citation markers and commentary around the finding are not part of what a document states.
7003
- - It can only confirm what this one document states. A finding about two interventions from two articles is two claims, each against its own article. A summary of several trials ("trials used 60\u2013200 mg") is stated by none of them; the dose this one trial used is.
7004
- - It returns error for a claim under four words, a sentence fragment, or a claim still containing citations. A short finding with its setting (in vitro, cell line, dose) is accepted; filler words do not help.
7005
- - verdict "supported" \u2014 the document states the claim. score is the model's probability.
7006
- - verdict "not_supported" \u2014 the stored full text does not state the claim as worded; fh_library_read with a query shows what the document does say. Or, with basis "title", nothing is stored to read: reason says so, score is null.
7007
- - verdict "unverifiable" \u2014 only the abstract is stored and it does not state the claim; the full text may (reason says so). A retry gives the same answer until a full text is stored.
7008
- - glyphs_unresolved above 0 \u2014 the PDF font lost symbols (minus, \xB1, \u2264); a fail on a number may be the font. fh_library_read shows the passage.
7009
- - superseded true \u2014 a published correction replaced the figure the claim uses; the status's corrections holds the notice.
7010
- - Verdicts are kept for 30 days: the same claim against the same stored text answers from disk, no model call. An article that gains its full text is judged afresh.
7011
-
7012
- Reading a document
7013
- - fh_library_read with only the ID returns the outline: every heading with its word count, and whether the full text or only the abstract is stored.
7014
- - section \u2014 a heading from the outline, matched case-insensitively as a substring; the text is capped at max_chars (default 6000). A heading that occurs several times is listed as "Participants [3/12]" and is addressed that way.
7015
- - query \u2014 returns the passages holding every term: up to max_hits (default 5), each at most 1000 characters around the matches, with its section, best first. It works best with two or three distinctive terms the document itself would use (a measure and a unit, an outcome and a group, a compound name), not a claim sentence. Case, accents, hyphens, plurals and -ed/-ing forms are matched.
7016
- - partial true \u2014 no passage holds every term; missing_terms are the words the document never uses. The same query without them finds the passage if there is one.
7017
- - Numbers are often in tables; a matching table row comes with its header row.
7018
- - section and query together search inside that section only.
7019
- - section "Abstract" on a full text without one returns the stored abstract. section "Declarations" returns funding, conflicts of interest, acknowledgements and ethics statements, assembled when the document has no section of that name, else the statements of the PubMed or Crossref record.
7020
-
7021
- Status fields: pmid, pmcid, setid, nctid, publications, year, publication_types, retracted, corrections, citable, comment, has_abstract, level, fulltext, version, retrieved_by, glyphs_unresolved, error. fulltext: "not tried" (no source tried yet) or "stored" (abstract_only read, full text exists). Funding and conflicts of interest: fh_library_read section "Declarations". Answers carry only what the call did not send: no echo of the ID, claim or query; a field that is null or an empty list is left out. fh_verify_claim always has verdict, score (null: no judgement) and basis.
6992
+ - Library: fh_library_add, fh_library_status, fh_library_read (outline, one section, or the passages for a query), fh_verify_claim (does this one source state this one finding?).
6993
+ - Search: fh_pubmed_search_articles, fh_pubmed_fetch_articles${citationsEnabled() ? ", fh_pubmed_citing_articles" : ""}, fh_clinicaltrials_search_studies, fh_dailymed_search_labels${webSearchConfigured() ? ", fh_web_search (instead of the built-in web search)" : ""}.
6994
+ - Trials: fh_clinicaltrials_get_study_record, fh_clinicaltrials_get_study_results.
6995
+ - Web: fh_fetch_url, for every URL that is not an article, label or trial record.
6996
+ ${evidEnabled() ? "- EVID: fh_evid_create, fh_evid_find, fh_evid_list_objects, fh_evid_put, fh_evid_get \u2014 a store that outlives the session.\n" : ""}${evidenceMapEnabled() ? "- Evidence map: fh_create_evidence_map, fh_get_evidence_map.\n" : ""}- fh_info: this server's version and the library.
7022
6997
 
7023
- Where records come from: PubMed for the record and abstract; the full text from PubMed Central, Europe PMC, publishers' text-mining links, Unpaywall, OpenAlex, CORE, and a proxy URL template from the configuration. Every action is appended as one line to <library>/logs/evidence.log.`;
6998
+ Rules
6999
+ - fh_library_read and fh_verify_claim store a missing record themselves (added: true); no fh_library_add first.
7000
+ - Many articles to look over: fh_library_read with abstract_only: true for each, then without it only where the full text is needed.
7001
+ - level: "full_text", "abstract" or "title". fulltext "not tried": stored from PubMed alone; the next read without abstract_only, verify or add searches for the full text.
7002
+ - citable false: retracted, or nothing to read; comment says which, corrections lists the notices.
7003
+ - "pmid not found" and the like: no service knows the ID; remembered for a day. "invalid id": the ID is malformed.
7004
+ - fh_library_add, fh_library_read and fh_verify_claim may run in parallel; calls on the same missing record share one add.
7005
+ - Answers leave out null fields and empty lists and echo nothing you sent.
7006
+ - Every action is one line in <library>/logs/evidence.log.`;
7024
7007
  var idSchema = z.string().describe('ID as "type:value": an article "pmid:30955454" (bare digits count as pmid) or "doi:10.5812/asjsm.110753" (an article PubMed does not index; a DOI PubMed indexes is taken as its PMID), a drug label "dailymed:<set ID>" (the set ID from fh_dailymed_search_labels, or the "setid=" value of its DailyMed URL), or a trial record "nct:05173896" (the eight digits; nct:NCT05173896 and a bare NCT05173896 are accepted).');
7025
7008
  var levelWord = (m) => m.level === "abstract" && !m.has_abstract ? "title" : m.level;
7026
7009
  var json = (s) => ({ content: [{ type: "text", text: statusAnswer(s) }] });
@@ -7151,7 +7134,7 @@ function registerTools(server2) {
7151
7134
  }
7152
7135
  server2.tool(
7153
7136
  "fh_library_add",
7154
- "Download and store one record \u2014 an article (pmid:, doi:), a drug label (dailymed:<set ID>) or a trial record (nct:<8 digits>) \u2014 and return its status JSON. An article gets its record, abstract and correction notices from PubMed (Crossref for a DOI PubMed does not index), then the full text from the configured sources; a label or trial record is stored as a full text. A stored full text is returned without any download; an abstract-level record retries only sources that failed transiently; a record older than 30 days gets its notices re-read.",
7137
+ "Download and store one record \u2014 an article (pmid:, doi:), a drug label (dailymed:<set ID>) or a trial record (nct:<8 digits>) \u2014 and return its status JSON (fields: fh_library_status). An article gets its record, abstract and correction notices from PubMed (Crossref for a DOI PubMed does not index), then the full text from the configured sources; a label or trial record is stored as a full text. A stored full text is returned without any download; an abstract-level record retries only sources that failed transiently; a record older than 30 days gets its notices re-read.",
7155
7138
  { id: idSchema },
7156
7139
  ({ id }) => addEntry(id)
7157
7140
  );
@@ -7318,7 +7301,7 @@ function registerTools(server2) {
7318
7301
  }
7319
7302
  server2.tool(
7320
7303
  "fh_library_status",
7321
- 'Read-only status of the library entry for one ID \u2014 an article, a drug label or a trial record: the same status JSON as fh_library_add, or level "missing" when there is no entry. Never fetches.',
7304
+ 'Read-only status of the library entry for one ID \u2014 an article, a drug label or a trial record: the same status JSON as fh_library_add, or level "missing" when there is no entry. Never fetches. Fields: pmid, pmcid, setid, nctid, publications, year, publication_types, retracted, corrections ({type, pmid, source}), citable, comment, has_abstract, level (full_text | abstract | title), fulltext ("not tried": no source tried yet; "stored": the full text exists, an abstract_only read did not use it), version, retrieved_by, glyphs_unresolved (symbols the PDF font lost), error.',
7322
7305
  { id: idSchema },
7323
7306
  async ({ id }) => {
7324
7307
  const parsed = parseId(id);
@@ -7340,7 +7323,7 @@ function registerTools(server2) {
7340
7323
  );
7341
7324
  server2.tool(
7342
7325
  "fh_library_read",
7343
- `One piece of a stored document's Markdown, never the whole. No section/query: the outline (headings with word counts; full text or abstract only). section: that heading's own text (case-insensitive substring; a repeated heading as "Participants [3/12]"), capped at max_chars, its subsections listed. query: passages holding every term, each a window of at most 1000 chars with its section, best first, at most max_hits (more: how many further passages match); partial: true with missing_terms when no passage holds them all. section and query together: inside that section. A missing article is added first (added: true). abstract_only: true reads only the abstract, at once \u2014 use it whenever the abstract is enough (screening, design, size, main finding); without it, an article whose full text was never searched for gets a search for the full text first (seconds, up to a minute, once).`,
7326
+ `One piece of a stored document's Markdown, never the whole. No section/query: the outline (headings with word counts; full text or abstract only). section: that heading's own text (case-insensitive substring; a repeated heading as "Participants [3/12]"), capped at max_chars, its subsections listed. query: passages holding every term, each a window of at most 1000 chars with its section, best first, at most max_hits (more: how many further passages match); partial: true with missing_terms when no passage holds them all. section and query together: inside that section. Case, accents, hyphens, plurals and -ed/-ing forms match; a matching table row comes with its header row. section "Abstract" on a full text without one: the stored abstract; "Declarations": funding, conflicts of interest, acknowledgements, ethics. A missing article is added first (added: true). abstract_only: true reads only the abstract, at once \u2014 use it whenever the abstract is enough (screening, design, size, main finding); without it, an article whose full text was never searched for gets a search for the full text first (seconds, up to a minute, once).`,
7344
7327
  {
7345
7328
  id: idSchema,
7346
7329
  section: z.string().optional().describe("Heading from the outline (case-insensitive substring)."),
@@ -7449,7 +7432,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
7449
7432
  );
7450
7433
  server2.tool(
7451
7434
  "fh_verify_claim",
7452
- `Does one source state one finding of a review? claim: the finding as a complete statement (subject, intervention, outcome, number), without citations or the review's framing, and only what this source reports. id: one source the review cites for it \u2014 article, drug label (dailymed:\u2026) or trial record (nct:\u2026); added first when missing. fulltext "not tried": a search for the full text first (seconds, up to a minute, once). The server reads the stored text and asks a decision model; nothing enters your context. verdict: supported (score is the probability) | not_supported (the full text does not state it; or only the title is stored \u2014 reason says so) | unverifiable (only the abstract is stored and does not state it \u2014 reason says so) | error (claim refused: under four words, a fragment, carrying citations; add failed; no model; model failure). basis: full_text | abstract | title. glyphs_unresolved: symbols the PDF font lost; above 0 a failed number may be the font. superseded: true when a stored correction replaced the claim's figure.`,
7435
+ `Does one source state one finding of a review? claim: the finding as a complete statement (subject, intervention, outcome, number), without citations or the review's framing, and only what this source reports. id: one source the review cites for it \u2014 article, drug label (dailymed:\u2026) or trial record (nct:\u2026); added first when missing. fulltext "not tried": a search for the full text first (seconds, up to a minute, once). The server reads the stored text and asks a decision model; nothing enters your context. One claim, one source: a finding backed by three articles is three calls; a summary of several trials is stated by none of them. verdict: supported | not_supported (the full text does not state it \u2014 fh_library_read with a query shows what it says; or only the title is stored \u2014 reason says so) | unverifiable (only the abstract is stored and does not state it \u2014 reason says so; the same until a full text is stored) | error (claim refused: under four words, a fragment, carrying citations; add failed; no model; model failure). basis: full_text | abstract | title. glyphs_unresolved: symbols the PDF font lost; above 0 a failed number may be the font. superseded: true when a stored correction replaced the claim's figure. score: the probability that the source states the claim, with every judged verdict; null: no judgement. The same claim on the same stored text answers from disk for 30 days.`,
7453
7436
  {
7454
7437
  claim: z.string().describe("One finding as a complete statement (subject, intervention, outcome, number), built from the review's words, without its citations and framing."),
7455
7438
  id: idSchema
@@ -7477,7 +7460,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
7477
7460
  );
7478
7461
  server2.tool(
7479
7462
  "fh_info",
7480
- "The server and the whole library as JSON: this server's package name and version (which build is loaded), its log file; evidence directory (evidence_dir) and host; entry count and size on disk; per type (pmid, doi, dailymed, nct) the entries by level (full_text, abstract, title) and retractions; counts of retracted and not-citable entries and of errata, expressions of concern and updates; the retrieval sources in run order and which are off (tiers); the multi-stage download (download): the Playwright servers with the version they must run, the Chrome stages, whether an unlocker is configured; the configuration and where each value came from \u2014 environment, .env or default, never the value (config); the decision model behind fh_verify_claim and whether it answers right now (verify); the unlockers and whether each answers right now (unlockers); our own stage hosts \u2014 fetch proxy, Playwright servers, Chrome \u2014 and whether each is reachable right now (stages); this server's cache hits and misses for fh_verify_claim and fh_fetch_url since it started (cache).",
7463
+ "The server and the whole library as JSON: this server's package name and version (which build is loaded), its log file; evidence directory (evidence_dir) and host; entry count and size on disk; per type (pmid, doi, dailymed, nct, url \u2014 pages stored by fh_fetch_url) the entries by level (full_text, abstract, title), retractions and fulltext_not_tried (articles stored from PubMed alone); counts of retracted and not-citable entries and of errata, expressions of concern and updates; the retrieval sources in run order and which are off (tiers); the multi-stage download (download): the Playwright servers with the version they must run, the Chrome stages, whether an unlocker is configured; the configuration and where each value came from \u2014 environment, .env or default, never the value (config); the decision model behind fh_verify_claim and whether it answers right now (verify); the unlockers and whether each answers right now (unlockers); our own stage hosts \u2014 fetch proxy, Playwright servers, Chrome \u2014 and whether each is reachable right now (stages); this server's cache hits and misses for fh_verify_claim and fh_fetch_url since it started (cache).",
7481
7464
  {},
7482
7465
  async () => {
7483
7466
  const info = libraryInfo(FH_EVIDENCE_DIR, HOST);
@@ -7503,7 +7486,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
7503
7486
  );
7504
7487
  server2.tool(
7505
7488
  "fh_fetch_url",
7506
- `Fetch a web page as Markdown: the standard fetch tool, cached and hardened. Use it for any URL instead of a plain fetch or a browser. A page fetched in the last ${settings().refresh_after_days} days is answered from disk in milliseconds; a page a plain fetch cannot get (403, rate limit, bot wall, script-rendered) is fetched through the configured browsers and unlockers in this one call. PDFs come back as Markdown; XML, JSON and other text as is. To verify a link, title_only returns just its title line. A PubMed, ClinicalTrials.gov, DailyMed or doi.org URL is answered from the library's record of it.`,
7489
+ `Fetch a web page as Markdown: the standard fetch tool, cached and hardened. Use it for any URL instead of a plain fetch or a browser. A page fetched in the last ${settings().refresh_after_days} days is answered from disk in milliseconds; a page a plain fetch cannot get (403, rate limit, bot wall, script-rendered) is fetched through the configured browsers and unlockers in this one call. PDFs come back as Markdown; XML, JSON and other text as is. To verify a link, title_only returns just its title line. A PubMed, ClinicalTrials.gov, DailyMed or doi.org URL is answered from the library's record of it. A failed fetch is remembered for ${settings().retry_after_days} d.`,
7507
7490
  {
7508
7491
  url: z.string().describe("URL to fetch"),
7509
7492
  // Optional, not .default(5000): the log tells a model that set none from one that asked for 5000.
@@ -7725,7 +7708,7 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7725
7708
  log("evid", evid, `create topic=${topic.trim()}`);
7726
7709
  }
7727
7710
  const r = await doResearch(FH_EVIDENCE_DIR, evid, queries, screening);
7728
- log("evmap", evid, r.ok ? `created queries=${queries.length} articles=${r.included}${r.failed_queries ? ` failed_queries=${r.failed_queries.length}` : ""}${r.empty_queries ? ` empty_queries=${r.empty_queries.length}` : ""}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
7711
+ log("evmap", evid, r.ok ? `created queries=${queries.length} articles=${r.included}${r.failed_queries ? ` failed_queries=${r.failed_queries.length}` : ""}${r.empty_queries ? ` empty_queries=${r.empty_queries.length}` : ""}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}${r.citations_error ? " citations_failed" : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
7729
7712
  const { ok, ...rest } = r;
7730
7713
  return { content: [{ type: "text", text: compact2(rest) }], ...ok ? {} : { isError: true } };
7731
7714
  }
@@ -7746,7 +7729,7 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7746
7729
  );
7747
7730
  server2.tool(
7748
7731
  "fh_clinicaltrials_search_studies",
7749
- `Search ClinicalTrials.gov by free text, intervention or condition; status ongoing | completed | all; sort relevance | newest | largest | completion. Returns the total and up to ${MAX_RESULTS} rows as arrays in columns order: NCT ID, title, status, phase, enrollment ("~100" estimated), start, primary completion, primary outcome, conditions, interventions, has_results. Link: https://clinicaltrials.gov/study/<NCT ID>. Cached ${searchCacheDays()} days. One trial in detail: fh_clinicaltrials_get_study_record.`,
7732
+ `Search ClinicalTrials.gov by free text, intervention or condition \u2014 at least one of them; status ongoing | completed | all; sort relevance | newest | largest | completion. Returns the total and up to ${MAX_RESULTS} rows as arrays in columns order: NCT ID, title, status, phase, enrollment ("~100" estimated), start, primary completion, primary outcome, conditions, interventions, has_results. Link: https://clinicaltrials.gov/study/<NCT ID>. Cached ${searchCacheDays()} days. One trial in detail: fh_clinicaltrials_get_study_record.`,
7750
7733
  {
7751
7734
  query: z.string().optional().describe("Free-text search across all fields (title, conditions, interventions, summary, \u2026); AND / OR / NOT allowed."),
7752
7735
  intervention: z.string().optional().describe('Intervention or treatment, e.g. "tadalafil", "cognitive behavioral therapy".'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {