evidence-mcp-dev 1.0.20 → 1.0.21

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 +60 -53
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3217,6 +3217,7 @@ var VARIABLES = [
3217
3217
  "FH_EVIDENCE_DIR",
3218
3218
  "FH_LOG_KEEP_DAYS",
3219
3219
  "FH_ENV",
3220
+ "FH_SOURCES",
3220
3221
  "FH_TIERS",
3221
3222
  "FH_CONTACT_EMAIL",
3222
3223
  "FH_ELSEVIER_API_KEY",
@@ -3303,7 +3304,8 @@ function resolveTiers(env = process.env) {
3303
3304
  for (const t of BUILTIN) available.set(t.name, t.make({ tokens: tokens2, api_key: str("FH_CORE_API_KEY", env) || void 0 }));
3304
3305
  const proxyUrl = str("FH_PROXY_URL", env);
3305
3306
  if (proxyUrl) available.set("proxy", urlTier("proxy", proxyUrl, proxyHeaders(str("FH_PROXY_HEADERS", env))));
3306
- const listed = str("FH_TIERS", env);
3307
+ const key2 = str("FH_SOURCES", env) || !str("FH_TIERS", env) ? "FH_SOURCES" : "FH_TIERS";
3308
+ const listed = str(key2, env);
3307
3309
  const order2 = listed ? listed.split(",").map((s) => s.trim()).filter(Boolean) : [...available.keys()];
3308
3310
  const tiers = [], seen2 = /* @__PURE__ */ new Set();
3309
3311
  for (const name of order2) {
@@ -3311,11 +3313,11 @@ function resolveTiers(env = process.env) {
3311
3313
  seen2.add(name);
3312
3314
  const t = available.get(name);
3313
3315
  if (t) tiers.push(t);
3314
- else if (name === "proxy") problems.push('FH_TIERS: "proxy" listed, but FH_PROXY_URL is unset');
3315
- else problems.push(`FH_TIERS: unknown tier "${name}" (built-in: ${BUILTIN.map((t2) => t2.name).join(", ")}; proxy when FH_PROXY_URL is set)`);
3316
+ else if (name === "proxy") problems.push(`${key2}: "proxy" listed, but FH_PROXY_URL is unset`);
3317
+ else problems.push(`${key2}: unknown source "${name}" (built-in: ${BUILTIN.map((t2) => t2.name).join(", ")}; proxy when FH_PROXY_URL is set)`);
3316
3318
  }
3317
3319
  const all = [...tiers.map((t) => ({ name: t.name, enabled: true })), ...[...available.keys()].filter((n) => !seen2.has(n)).map((name) => ({ name, enabled: false }))];
3318
- return { tiers, all, source: sourceOf("FH_TIERS", env), problems };
3320
+ return { tiers, all, source: sourceOf(key2, env), problems };
3319
3321
  }
3320
3322
 
3321
3323
  // src/verify/google.ts
@@ -5264,7 +5266,7 @@ async function verifyClaim(claim, id, cfg, decide, read2 = readPaper) {
5264
5266
  if (!cfg || !decide) return { ...out, error: "no decision model configured: set FH_VERIFY_PROVIDER and its API key in .env" };
5265
5267
  out.basis = paper.basis;
5266
5268
  out.glyphs_unresolved = countUnresolved(paper.text);
5267
- if (paper.basis === "title") return { ...out, verdict: "fail", reason: NOTHING_TO_VERIFY };
5269
+ if (paper.basis === "title") return { ...out, verdict: "not_supported", reason: NOTHING_TO_VERIFY };
5268
5270
  const ws = windows(paper.text, cfg.window_chars);
5269
5271
  out.windows = ws.length;
5270
5272
  try {
@@ -5282,8 +5284,8 @@ async function verifyClaim(claim, id, cfg, decide, read2 = readPaper) {
5282
5284
  } catch (e) {
5283
5285
  return { ...out, error: e instanceof Error ? e.message : String(e) };
5284
5286
  }
5285
- if (out.score >= cfg.threshold) return { ...out, verdict: "pass" };
5286
- return paper.basis === "full_text" ? { ...out, verdict: "fail" } : { ...out, verdict: "unverifiable", reason: "only the abstract is stored and it does not state the claim; the full text may" };
5287
+ if (out.score >= cfg.threshold) return { ...out, verdict: "supported" };
5288
+ return paper.basis === "full_text" ? { ...out, verdict: "not_supported" } : { ...out, verdict: "unverifiable", reason: "only the abstract is stored and it does not state the claim; the full text may" };
5287
5289
  }
5288
5290
 
5289
5291
  // src/verify/cache.ts
@@ -5302,7 +5304,11 @@ var verdictFile = (libraryDir, key2) => join11(libraryDir, "verify", key2.slice(
5302
5304
  function readVerdict(file3) {
5303
5305
  if (!existsSync12(file3)) return null;
5304
5306
  try {
5305
- return JSON.parse(readFileSync10(file3, "utf8"));
5307
+ const c = JSON.parse(readFileSync10(file3, "utf8"));
5308
+ const old = c.verdict;
5309
+ if (old === "pass") c.verdict = "supported";
5310
+ else if (old === "fail") c.verdict = "not_supported";
5311
+ return c;
5306
5312
  } catch {
5307
5313
  return null;
5308
5314
  }
@@ -6257,7 +6263,7 @@ var SCHEMA = {
6257
6263
  required: [...FIELDS2],
6258
6264
  additionalProperties: false
6259
6265
  };
6260
- var fill = (prompt, topic, paper) => prompt.split("{{topic}}").join(topic).split("{{paper}}").join(paper);
6266
+ var fill = (prompt, topic, paper) => prompt.split("{{topic}}").join(topic).split("{{article}}").join(paper);
6261
6267
  var cacheKey2 = (model, prompt, topic) => createHash10("sha256").update(JSON.stringify([model, fill(prompt, topic, "")])).digest("hex").slice(0, 16);
6262
6268
  var ScreenError = class extends Error {
6263
6269
  constructor(message, status) {
@@ -6409,7 +6415,7 @@ var literatureEnabled = (env = process.env) => /^(true|1|yes|on)$/i.test(env.FH_
6409
6415
  var maxQueries = (env = process.env) => num("FH_LITERATURE_MAX_QUERIES", 10, env, (n) => n >= 1 && Number.isInteger(n));
6410
6416
  var maxResultsPerQuery = (env = process.env) => num("FH_LITERATURE_MAX_RESULTS_PER_QUERY", 200, env, (n) => n >= 1 && n <= 1e3 && Number.isInteger(n));
6411
6417
  var COLUMNS6 = ["pmid", "title", "first_author", "year", "journal", "types", "score", "signals", "relevance", "population", "design", "n", "outcome", "finding", "aspect", "reason"];
6412
- var SLOTS = ["{{topic}}", "{{paper}}"];
6418
+ var SLOTS = ["{{topic}}", "{{article}}"];
6413
6419
  var SETTINGS = "FH_LITERATURE_SCREEN_PROVIDER, FH_LITERATURE_SCREEN_API_KEY, FH_LITERATURE_SCREEN_MODEL, FH_LITERATURE_SCREEN_URL";
6414
6420
  var live5 = (lib) => ({
6415
6421
  search: async (query, max) => {
@@ -6425,7 +6431,7 @@ var live5 = (lib) => ({
6425
6431
  const f = entryPaths(lib, "pmid", pmid).md;
6426
6432
  return existsSync19(f) ? readFileSync17(f, "utf8") : null;
6427
6433
  },
6428
- log: (id, message) => log("literature", id, message)
6434
+ log: (id, message) => log("lit", id, message)
6429
6435
  });
6430
6436
  function csvCell(v) {
6431
6437
  const s = v == null ? "" : String(v);
@@ -6484,7 +6490,8 @@ async function doResearch(lib, evid, queries, screening, env = process.env, now2
6484
6490
  const row3 = (p, sc, sig, f) => [p.pmid, p.title, p.first_author, p.year, p.journal, p.types, sc, sig, ...FIELDS2.map((k) => f?.[k] ?? "")].map(csvCell).join(",");
6485
6491
  const signals = (p) => `in ${p.queries.length} of ${n} queries`;
6486
6492
  const queriesJson = JSON.stringify({ date: started, max_results_per_query: perQuery, queries: runs.map((r, i) => ({ ...r, unique: r.error ? 0 : unique(i) })) }, null, 2) + "\n";
6487
- const base = { started, queries: n, failed_queries: runs.filter((r) => r.error).length, found: ids.length, retracted: retracted.size, not_found: notFound, model: screener.model, endpoint: screener.where };
6493
+ const identified = runs.reduce((a, r) => a + r.kept, 0);
6494
+ const base = { started, queries: n, failed_queries: runs.filter((r) => r.error).length, identified, duplicates: identified - ids.length, removed_retracted: retracted.size, not_found: notFound, model: screener.model, endpoint: screener.where };
6488
6495
  const t = Date.now();
6489
6496
  const model = screener.model;
6490
6497
  const text4 = (pmid) => {
@@ -6500,7 +6507,7 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
6500
6507
  if (probe2 && results2[0].error) {
6501
6508
  const error = results2[0].error;
6502
6509
  for (const [name, content] of [["lit-queries.json", queriesJson], ["lit-run.json", JSON.stringify({ ...base, finished: (/* @__PURE__ */ new Date()).toISOString(), state: "failed", error }, null, 2) + "\n"]]) putObject(lib, o.evid, name, content, env);
6503
- return { ok: false, failed: true, error: `screening failed on the first paper (pmid:${probe2}): ${error}. The searches ran: ${kept.length} papers found and stored in the library with their abstracts; nothing was screened, no lit-papers.csv. lit-queries.json and lit-run.json are in the EVID; call again once the cause is fixed (the searches answer from the cache).` };
6510
+ return { ok: false, failed: true, error: `screening failed on the first paper (pmid:${probe2}): ${error}. The searches ran: ${kept.length} papers found and stored in the library with their abstracts; nothing was screened, no lit-map.csv. lit-queries.json and lit-run.json are in the EVID; call again once the cause is fixed (the searches answer from the cache).` };
6504
6511
  }
6505
6512
  results2.push(...await screenAll(lib, order2.filter((pmid) => pmid !== probe2), screening, topic, text4, screener.ask, model, screenParallel(env), note));
6506
6513
  const by = new Map(results2.map((r) => [r.pmid, r]));
@@ -6513,22 +6520,22 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
6513
6520
  const lines = ranked.map(({ p, f, sc }) => row3(p, sc ?? "", signals(p), f));
6514
6521
  const count = (k) => results2.filter((r) => r.screened?.relevance === k).length;
6515
6522
  const failures = results2.filter((r) => r.error);
6516
- const screenRun = { seconds: Math.round((Date.now() - t) / 1e3), screened: results2.filter((r) => r.screened).length, cached: results2.filter((r) => r.cached).length, errors: failures.length, ...failures.length ? { first_error: failures[0].error } : {}, direct: count("direct"), indirect: count("indirect"), background: count("background"), off_topic: count("off-topic") };
6523
+ 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, seconds: Math.round((Date.now() - t) / 1e3) };
6517
6524
  const csv = [COLUMNS6.join(","), ...lines].join("\n") + "\n";
6518
6525
  const state = "screened";
6519
6526
  const puts = [
6520
6527
  ["lit-screening.md", screening],
6521
6528
  ["lit-queries.json", queriesJson],
6522
- ["lit-papers.csv", csv],
6529
+ ["lit-map.csv", csv],
6523
6530
  ["lit-screened.csv", screenedCsv],
6524
- ["lit-run.json", JSON.stringify({ ...base, finished: (/* @__PURE__ */ new Date()).toISOString(), state, ...screenRun, papers: lines.length }, null, 2) + "\n"]
6531
+ ["lit-run.json", JSON.stringify({ ...base, finished: (/* @__PURE__ */ new Date()).toISOString(), state, ...screenRun, included: lines.length }, null, 2) + "\n"]
6525
6532
  ];
6526
6533
  for (const [name, content] of puts) {
6527
6534
  const r = putObject(lib, o.evid, name, content, env);
6528
6535
  if (!r.ok) return r;
6529
6536
  }
6530
- 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 lit-papers.csv, unscored, at the end (errors in lit-screened.csv). Call again to retry only those: screened papers answer from the cache.` } : {};
6531
- return { ok: true, evid: o.evid, state, papers: lines.length, objects: puts.map(([name]) => name), ...partial };
6537
+ 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 lit-map.csv, unscored, at the end (errors in lit-screened.csv). Call again to retry only those: screened papers answer from the cache.` } : {};
6538
+ return { ok: true, evid: o.evid, state, included: lines.length, objects: puts.map(([name]) => name), ...partial };
6532
6539
  }
6533
6540
 
6534
6541
  // src/tools.ts
@@ -6539,11 +6546,11 @@ var pkg = (() => {
6539
6546
  return { name: "evidence-mcp", version: "0.0.0" };
6540
6547
  }
6541
6548
  })();
6542
- var INSTRUCTIONS = `evidence-mcp keeps a local library of scientific papers, 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.
6549
+ 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.
6543
6550
 
6544
6551
  IDs \u2014 always "type:value"
6545
- - pmid:30955454 \u2014 a paper by PubMed ID. Bare digits are taken as a PMID.
6546
- - doi:10.\u2026 \u2014 a paper by DOI. A DOI PubMed indexes is stored under its PMID; any other gets its record from Crossref.
6552
+ - pmid:30955454 \u2014 an article by PubMed ID. Bare digits are taken as a PMID.
6553
+ - doi:10.\u2026 \u2014 an article by DOI. A DOI PubMed indexes is stored under its PMID; any other gets its record from Crossref.
6547
6554
  - 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.
6548
6555
  - nct:05173896 \u2014 a ClinicalTrials.gov trial record, current version. NCT05173896 is accepted too.
6549
6556
 
@@ -6553,9 +6560,9 @@ Tools
6553
6560
  - fh_library_status(id) \u2014 the status of one record without downloading; level "missing" when it is not stored.
6554
6561
  - 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.
6555
6562
  - 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.
6556
- - 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.
6563
+ - 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.
6557
6564
  - 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.
6558
- ${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" : ""}${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" : ""}${literatureEnabled() ? "- fh_literature_do_research(evid, queries, screening) \u2014 the literature research for an EVID: you bring the PubMed queries and the screening prompt; the result appears in the EVID as lit-papers.csv (fh_evid_get).\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.
6565
+ ${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" : ""}${literatureEnabled() ? "- fh_literature_map_evidence(evid, queries, screening) \u2014 the evidence map for an EVID: you bring the PubMed queries and the screening prompt; the result, one ranked row per article with its design, population, outcome and finding, appears in the EVID as lit-map.csv (fh_evid_get).\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.
6559
6566
  - 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.
6560
6567
  ${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.
6561
6568
  - 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.
@@ -6563,25 +6570,25 @@ ${webSearchConfigured() ? "- fh_web_search(query, max_results?) \u2014 search th
6563
6570
 
6564
6571
  Hints
6565
6572
  - 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.
6566
- - Many papers to look over (a search, lit-papers.csv): abstract_only: true for each, then without it only the papers that need the full text.
6567
- - citable false \u2014 the paper 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}.
6573
+ - Many articles to look over (a search, lit-map.csv): abstract_only: true for each, then without it only the articles that need the full text.
6574
+ - 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}.
6568
6575
  - 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, searched at the next read without abstract_only, verify or add.
6569
6576
  - 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.
6570
6577
  - 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.
6571
- - fh_fetch_url takes any URL that is not a paper, 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.
6578
+ - 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.
6572
6579
  - 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.
6573
6580
 
6574
6581
  Verifying a claim
6575
- - fh_verify_claim judges one claim against one stored document. A finding backed by three papers takes three calls with the same claim.
6582
+ - fh_verify_claim judges one claim against one stored document. A finding backed by three articles takes three calls with the same claim.
6576
6583
  - 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.
6577
- - It can only confirm what this one document states. A finding about two interventions from two papers is two claims, each against its own paper. A summary of several trials ("trials used 60\u2013200 mg") is stated by none of them; the dose this one trial used is.
6584
+ - 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.
6578
6585
  - 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.
6579
- - verdict "pass" \u2014 the document states the claim. score is the model's probability.
6580
- - verdict "fail" \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.
6586
+ - verdict "supported" \u2014 the document states the claim. score is the model's probability.
6587
+ - 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.
6581
6588
  - 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.
6582
6589
  - 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.
6583
6590
  - superseded true \u2014 a published correction replaced the figure the claim uses; the status's corrections holds the notice.
6584
- - Verdicts are kept for 30 days: the same claim against the same stored text answers from disk, no model call. A paper that gains its full text is judged afresh.
6591
+ - 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.
6585
6592
 
6586
6593
  Reading a document
6587
6594
  - 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.
@@ -6595,7 +6602,7 @@ Reading a document
6595
6602
  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.
6596
6603
 
6597
6604
  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.`;
6598
- var idSchema = z.string().describe('ID as "type:value": a paper "pmid:30955454" (bare digits count as pmid) or "doi:10.5812/asjsm.110753" (a paper 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).');
6605
+ 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).');
6599
6606
  var levelWord = (m) => m.level === "abstract" && !m.has_abstract ? "title" : m.level;
6600
6607
  var json = (s) => ({ content: [{ type: "text", text: statusAnswer(s) }] });
6601
6608
  function noticeTag(m) {
@@ -6611,10 +6618,10 @@ function noticeTag(m) {
6611
6618
  var modelFailure = (error, cfg) => error.startsWith("no decision model configured") || !!cfg && error.startsWith(`${cfg.model}:`);
6612
6619
  function registerTools(server2) {
6613
6620
  async function completeFulltext(paths, meta, requested) {
6614
- const paper = { title: meta.title, pmid: meta.pmid, pmcid: meta.pmcid, doi: meta.doi, headLine: readHeadLine(paths) };
6621
+ const article = { title: meta.title, pmid: meta.pmid, pmcid: meta.pmcid, doi: meta.doi, headLine: readHeadLine(paths) };
6615
6622
  const tried = /* @__PURE__ */ new Set();
6616
6623
  let ran = false;
6617
- const { hit } = await fulltextCascade(paper, meta.attempts, (e) => {
6624
+ const { hit } = await fulltextCascade(article, meta.attempts, (e) => {
6618
6625
  if (e.ok === "alert") {
6619
6626
  log("add", requested, `!! ${e.message}`);
6620
6627
  return;
@@ -6723,7 +6730,7 @@ function registerTools(server2) {
6723
6730
  }
6724
6731
  server2.tool(
6725
6732
  "fh_library_add",
6726
- "Download and store one record \u2014 a paper (pmid:, doi:), a drug label (dailymed:<set ID>) or a trial record (nct:<8 digits>) \u2014 and return its status JSON. A paper 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.",
6733
+ "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.",
6727
6734
  { id: idSchema },
6728
6735
  ({ id }) => addEntry(id)
6729
6736
  );
@@ -6890,7 +6897,7 @@ function registerTools(server2) {
6890
6897
  }
6891
6898
  server2.tool(
6892
6899
  "fh_library_status",
6893
- 'Read-only status of the library entry for one ID \u2014 a paper, 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.',
6900
+ '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.',
6894
6901
  { id: idSchema },
6895
6902
  async ({ id }) => {
6896
6903
  const parsed = parseId(id);
@@ -6912,11 +6919,11 @@ function registerTools(server2) {
6912
6919
  );
6913
6920
  server2.tool(
6914
6921
  "fh_library_read",
6915
- `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 paper 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, a paper not yet searched for its full text is searched first (seconds, up to a minute, once).`,
6922
+ `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 not yet searched for its full text is searched first (seconds, up to a minute, once).`,
6916
6923
  {
6917
6924
  id: idSchema,
6918
6925
  section: z.string().optional().describe("Heading from the outline (case-insensitive substring)."),
6919
- query: z.string().optional().describe("Two or three distinctive terms the paper itself would use \u2014 a measure and a unit, an outcome and a group, a compound name \u2014 not the claim. Passages holding all of them are returned, else the best partial matches. With section: inside that section."),
6926
+ query: z.string().optional().describe("Two or three distinctive terms the article itself would use \u2014 a measure and a unit, an outcome and a group, a compound name \u2014 not the claim. Passages holding all of them are returned, else the best partial matches. With section: inside that section."),
6920
6927
  max_chars: z.number().int().positive().optional().describe("Cap for section text (default 6000); passages are capped at 1000 chars each regardless."),
6921
6928
  max_hits: z.number().int().positive().optional().describe("Cap for query passages (default 5)."),
6922
6929
  abstract_only: z.boolean().optional().describe('true: the abstract only, at once, no full-text download; section and query search the abstract. A missing pmid: is stored from PubMed alone; a missing doi: is added normally first; dailymed: and nct: ignore it. Use it whenever the abstract answers the question (topic, design, population, size, main result, worth reading?); not for details only the full text holds, nor for checking a claim. fulltext "stored" or "not tried": a read without the flag gets more.')
@@ -7021,7 +7028,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
7021
7028
  );
7022
7029
  server2.tool(
7023
7030
  "fh_verify_claim",
7024
- `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 paper, drug label (dailymed:\u2026) or trial record (nct:\u2026); added first when missing. fulltext "not tried": the full text is searched first (seconds, up to a minute, once). The server reads the stored text and asks a decision model; nothing enters your context. verdict: pass (score is the probability) | fail (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.`,
7031
+ `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": the full text is searched 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.`,
7025
7032
  {
7026
7033
  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."),
7027
7034
  id: idSchema
@@ -7138,7 +7145,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
7138
7145
  );
7139
7146
  server2.tool(
7140
7147
  "fh_pubmed_fetch_articles",
7141
- `Title, first author, year, publication types, retracted and library level for up to ${MAX_PMIDS} PubMed IDs in one call. Faster and far smaller than asking PubMed: known papers come from disk, the rest in one request, stored for every later call; rows as arrays in columns order, ~120 characters a paper. Level "not found": PubMed has no such record. For abstract or full text: fh_library_read.`,
7148
+ `Title, first author, year, publication types, retracted and library level for up to ${MAX_PMIDS} PubMed IDs in one call. Faster and far smaller than asking PubMed: known articles come from disk, the rest in one request, stored for every later call; rows as arrays in columns order, ~120 characters an article. Level "not found": PubMed has no such record. For abstract or full text: fh_library_read.`,
7142
7149
  { pmids: z.array(z.string()).min(1).max(MAX_PMIDS).describe('PubMed IDs, "30955454" or "pmid:30955454", up to 200.') },
7143
7150
  async ({ pmids }) => {
7144
7151
  const t0 = Date.now();
@@ -7152,7 +7159,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
7152
7159
  );
7153
7160
  server2.tool(
7154
7161
  "fh_pubmed_search_articles",
7155
- `Search PubMed with its own query syntax (AND / OR, field tags like [pt], [ti], [mesh]); sort relevance | newest; years "2020-2026". Faster and far smaller than asking PubMed: the total and up to ${MAX_RESULTS2} rows as arrays in columns order \u2014 PMID, title, first author, year, journal, publication types, PMCID when free full text exists, and the library level when the paper is already stored. The same search is answered from disk for ${searchCacheDays()} days. For a batch of PMIDs: fh_pubmed_fetch_articles; for abstract or full text: fh_library_read.`,
7162
+ `Search PubMed with its own query syntax (AND / OR, field tags like [pt], [ti], [mesh]); sort relevance | newest; years "2020-2026". Faster and far smaller than asking PubMed: the total and up to ${MAX_RESULTS2} rows as arrays in columns order \u2014 PMID, title, first author, year, journal, publication types, PMCID when free full text exists, and the library level when the article is already stored. The same search is answered from disk for ${searchCacheDays()} days. For a batch of PMIDs: fh_pubmed_fetch_articles; for abstract or full text: fh_library_read.`,
7156
7163
  {
7157
7164
  query: z.string().describe('PubMed query, full syntax: "tadalafil AND (systematic review[pt] OR meta-analysis[pt])".'),
7158
7165
  max_results: z.number().int().min(1).max(MAX_RESULTS2).default(20).describe("Rows to return (1\u2013100)."),
@@ -7175,16 +7182,16 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
7175
7182
  );
7176
7183
  if (citationsEnabled()) server2.tool(
7177
7184
  "fh_pubmed_citing_articles",
7178
- `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.
7179
- - types: PubMed publication types, any of them; a paper without one (many plain articles, some guidelines) never matches.
7180
- - 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.
7185
+ `The articles that cite an article, 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.
7186
+ - types: PubMed publication types, any of them; an article without one (many plain articles, some guidelines) never matches.
7187
+ - Comments: with comment, letter or editorial in types, the comments PubMed links to the article come first, of any year and type, and comments_on lists their PMIDs. The other rows only cite the article and are mostly about something else.
7181
7188
  - years and sort newest go by the year column.
7182
7189
  - At most ${MAX_RESULTS4} rows, no paging: for more, narrow with types or years, or sort: cited. total counts every match.
7183
7190
  Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7184
7191
  {
7185
- id: z.string().describe('The cited paper: "pmid:18378520" or "doi:10.1056/NEJMoa0801317".'),
7192
+ id: z.string().describe('The cited article: "pmid:18378520" or "doi:10.1056/NEJMoa0801317".'),
7186
7193
  types: z.array(z.string()).optional().describe('Publication types, any of them: "meta-analysis", "systematic review", "randomized controlled trial", "review", "guideline", "comment", "letter", "editorial".'),
7187
- 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.'),
7194
+ years: z.string().optional().describe('Publication years of the citing articles, as in the year column: "2020-2026", "2022-", "-2019" or "2022". Not applied to the comments PubMed links.'),
7188
7195
  sort: z.enum(["newest", "cited"]).default("newest").describe("newest (latest year first) or cited (most cited first)."),
7189
7196
  max_results: z.number().int().min(1).max(MAX_RESULTS4).default(20).describe("Rows to return (1\u2013100).")
7190
7197
  },
@@ -7246,7 +7253,7 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7246
7253
  "Store an object in an EVID. name: lowercase letters, digits, _ and -, then the extension, which sets the type: .json, .csv (RFC 4180, a header row), .txt, .md; at most 64 characters, no folders. An invalid name is refused with the valid form; content that does not parse as its type is refused. An existing object of that name is replaced and kept as its previous version (one only). Nothing can be deleted.",
7247
7254
  {
7248
7255
  evid: z.string().describe("The EVID."),
7249
- name: z.string().describe(`The object's name, e.g. "lit-papers.csv", "notes.md".`),
7256
+ name: z.string().describe(`The object's name, e.g. "lit-map.csv", "notes.md".`),
7250
7257
  content: z.string().describe("The whole object as text.")
7251
7258
  },
7252
7259
  async ({ evid, name, content }) => {
@@ -7257,10 +7264,10 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7257
7264
  );
7258
7265
  server2.tool(
7259
7266
  "fh_evid_get",
7260
- `Read an object of an EVID, whole or in pieces, as fh_library_read reads a document. No section/query: the object, when it fits max_chars (default ${DEFAULT_MAX_CHARS}); else its outline (.md: headings with word counts; .csv: columns and row count; .json: keys; .txt: lines and words). section (.md): that heading's own text, its subsections listed. query: .md/.txt the passages holding every term, best first; .csv the rows holding every term, with the columns. lines "a-b": .md/.txt those lines, .csv those data rows (lit-papers.csv is ranked: "1-50" the top 50). previous: true reads the version before the last put. name metadata.json: the metadata.`,
7267
+ `Read an object of an EVID, whole or in pieces, as fh_library_read reads a document. No section/query: the object, when it fits max_chars (default ${DEFAULT_MAX_CHARS}); else its outline (.md: headings with word counts; .csv: columns and row count; .json: keys; .txt: lines and words). section (.md): that heading's own text, its subsections listed. query: .md/.txt the passages holding every term, best first; .csv the rows holding every term, with the columns. lines "a-b": .md/.txt those lines, .csv those data rows (lit-map.csv is ranked: "1-50" the top 50). previous: true reads the version before the last put. name metadata.json: the metadata.`,
7261
7268
  {
7262
7269
  evid: z.string().describe("The EVID."),
7263
- name: z.string().describe(`The object's name, e.g. "lit-papers.csv".`),
7270
+ name: z.string().describe(`The object's name, e.g. "lit-map.csv".`),
7264
7271
  section: z.string().optional().describe(".md only: a heading, case-insensitive substring."),
7265
7272
  query: z.string().optional().describe("Two or three distinctive terms."),
7266
7273
  max_chars: z.number().int().positive().optional().describe(`Cap for the object or section text (default ${DEFAULT_MAX_CHARS}).`),
@@ -7276,16 +7283,16 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7276
7283
  );
7277
7284
  }
7278
7285
  if (literatureEnabled()) server2.tool(
7279
- "fh_literature_do_research",
7280
- `The literature research for an EVID: the server runs your PubMed queries (at most ${maxQueries()}), screens each abstract found with your screening prompt ({{topic}} from the EVID's metadata, {{paper}} each paper), and stores the result in the EVID as lit-papers.csv; read it with fh_evid_get. Also stored: lit-screening.md (your prompt), lit-queries.json (the queries), lit-run.json. The papers found are merged, retracted ones dropped, each stored in the library with its abstract; a model screens every abstract, off-topic papers are dropped, the rest ranked by score (evidence level, relevance, outcome, size, how many queries found it). Every screening answer, kept or not, in lit-screened.csv. Takes a minute or two.`,
7286
+ "fh_literature_map_evidence",
7287
+ `The evidence map for an EVID: the server runs your PubMed queries (at most ${maxQueries()}), screens each abstract found with your screening prompt ({{topic}} from the EVID's metadata, {{article}} each article), and stores the result in the EVID as lit-map.csv; read it with fh_evid_get. Also stored: lit-screening.md (your prompt), lit-queries.json (the queries), lit-run.json. The articles found are merged, retracted ones dropped, each stored in the library with its abstract; a model screens every abstract, off-topic articles are dropped, the rest ranked by score (evidence level, relevance, outcome, size, how many queries found it). Every screening answer, kept or not, in lit-screened.csv. Takes a minute or two.`,
7281
7288
  {
7282
7289
  evid: z.string().describe("The EVID."),
7283
7290
  queries: z.array(z.string()).min(1).describe("PubMed queries in PubMed's syntax."),
7284
- screening: z.string().describe("The prompt for the screening model, with {{topic}} (the server puts in the EVID's metadata topic) and {{paper}} (the server puts in each paper: PMID, title, year, publication types, abstract).")
7291
+ screening: z.string().describe("The prompt for the screening model, with {{topic}} (the server puts in the EVID's metadata topic) and {{article}} (the server puts in each article: PMID, title, year, publication types, abstract).")
7285
7292
  },
7286
7293
  async ({ evid, queries, screening }) => {
7287
7294
  const r = await doResearch(FH_EVIDENCE_DIR, evid, queries, screening);
7288
- log("literature", evid, r.ok ? `${r.state} queries=${queries.length} papers=${r.papers}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
7295
+ log("lit", evid, r.ok ? `${r.state} queries=${queries.length} articles=${r.included}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
7289
7296
  const { ok, ...rest } = r;
7290
7297
  return { content: [{ type: "text", text: compact2(rest) }], ...ok ? {} : { isError: true } };
7291
7298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {