evidence-mcp-dev 1.0.18 → 1.0.20

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 +51 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6126,6 +6126,11 @@ function getObject(lib, evid, name, opts = {}, env = process.env) {
6126
6126
  const text4 = readFileSync15(file3, "utf8");
6127
6127
  const type = typeOf(name);
6128
6128
  const maxChars = opts.max_chars ?? DEFAULT_MAX_CHARS;
6129
+ if (opts.lines !== void 0) {
6130
+ if (opts.section !== void 0 || opts.query !== void 0) return fail("lines: alone, not with section or query");
6131
+ if (type === "json") return fail("lines: .md, .txt and .csv objects; a .json object is read whole");
6132
+ return byLines(type, text4, opts.lines, maxChars);
6133
+ }
6129
6134
  if (opts.section !== void 0) {
6130
6135
  if (type !== "md") return fail(`section: .md objects only; ${name} is .${type}`);
6131
6136
  if (opts.query === void 0) {
@@ -6147,7 +6152,7 @@ function getObject(lib, evid, name, opts = {}, env = process.env) {
6147
6152
  return { ok: true, ...r };
6148
6153
  }
6149
6154
  if (text4.length <= maxChars) return { ok: true, content: text4 };
6150
- return { ok: true, too_large: `${text4.length} chars, above max_chars ${maxChars}: the outline instead; read with section or query, or a larger max_chars`, outline: outlineOf(type, text4) };
6155
+ return { ok: true, too_large: `${text4.length} chars, above max_chars ${maxChars}: the outline instead; read with lines (e.g. "1-50"${type === "csv" ? ", data rows" : ""}), section or query, or a larger max_chars`, outline: outlineOf(type, text4) };
6151
6156
  }
6152
6157
  function outlineOf(type, text4) {
6153
6158
  if (type === "md") {
@@ -6164,6 +6169,38 @@ function outlineOf(type, text4) {
6164
6169
  }
6165
6170
  return { lines: text4.split("\n").length, words: (text4.match(/\S+/g) ?? []).length };
6166
6171
  }
6172
+ function parseLines(spec) {
6173
+ const m = /^\s*(\d+)\s*(?:(-)\s*(\d*))?\s*$/.exec(spec);
6174
+ if (!m) return null;
6175
+ const from = Number(m[1]);
6176
+ const to = m[2] ? m[3] ? Number(m[3]) : null : from;
6177
+ return from >= 1 && (to === null || to >= from) ? { from, to } : null;
6178
+ }
6179
+ function byLines(type, text4, spec, maxChars) {
6180
+ const range = parseLines(spec);
6181
+ if (!range) return fail(`lines: "${spec}" \u2014 give "a-b", "a" or "a-" (1-based)`);
6182
+ let columns2;
6183
+ let items;
6184
+ if (type === "csv") {
6185
+ const r = parseCsv(text4);
6186
+ if (!r.ok) return fail(r.error);
6187
+ [columns2] = r.rows;
6188
+ const physical = text4.replace(/\r?\n$/, "").split(/\r?\n/);
6189
+ items = physical.length === r.rows.length ? physical.slice(1) : r.rows.slice(1).map((row3) => row3.map((c) => /[",\n\r]/.test(c) ? `"${c.replace(/"/g, '""')}"` : c).join(","));
6190
+ } else items = text4.replace(/\n$/, "").split("\n");
6191
+ const total = items.length;
6192
+ if (range.from > total) return fail(`lines: from ${range.from}, but there are ${total}${type === "csv" ? " data rows" : " lines"}`);
6193
+ const want = items.slice(range.from - 1, range.to === null ? total : Math.min(range.to, total));
6194
+ const out = [];
6195
+ let used = 0;
6196
+ for (const l of want) {
6197
+ if (out.length && used + l.length + 1 > maxChars) break;
6198
+ out.push(l);
6199
+ used += l.length + 1;
6200
+ }
6201
+ const last = range.from + out.length - 1;
6202
+ return { ok: true, ...columns2 ? { columns: columns2.join(",") } : {}, [type === "csv" ? "rows" : "text"]: out.join("\n"), first: range.from, last, total, ...last < (range.to === null ? total : Math.min(range.to, total)) ? { cut: `at max_chars ${maxChars}; continue with lines "${last + 1}-"` } : {} };
6203
+ }
6167
6204
  function csvQuery(text4, query, maxHits) {
6168
6205
  const r = parseCsv(text4);
6169
6206
  if (!r.ok) return { error: r.error };
@@ -6514,11 +6551,11 @@ Tools
6514
6551
  - 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).
6515
6552
  - 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.
6516
6553
  - fh_library_status(id) \u2014 the status of one record without downloading; level "missing" when it is not stored.
6517
- - 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 milliseconds instead of a full-text search of up to a minute per paper.
6554
+ - 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.
6518
6555
  - 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.
6519
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.
6520
6557
  - 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.
6521
- ${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?, 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.
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.
6522
6559
  - 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.
6523
6560
  ${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.
6524
6561
  - 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.
@@ -6526,9 +6563,9 @@ ${webSearchConfigured() ? "- fh_web_search(query, max_results?) \u2014 search th
6526
6563
 
6527
6564
  Hints
6528
6565
  - 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.
6529
- - Many papers to look over (a search, the literature research's lit-papers.csv): fh_library_read with abstract_only: true for each \u2014 fast, no downloads. Then read without it only the papers that need the full text; that first read searches every full-text source.
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.
6530
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}.
6531
- - level \u2014 what is stored: "full_text", "abstract" (no full text could be found; the log names each source tried and why it failed) or "title" (not even an abstract; citable false).
6568
+ - 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.
6532
6569
  - 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.
6533
6570
  - 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.
6534
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.
@@ -6555,10 +6592,10 @@ Reading a document
6555
6592
  - section and query together search inside that section only.
6556
6593
  - 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.
6557
6594
 
6558
- Status fields: pmid, pmcid, setid, nctid, publications, year, publication_types, retracted, corrections, citable, comment, has_abstract, level, version, retrieved_by, glyphs_unresolved, error. 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.
6595
+ 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.
6559
6596
 
6560
6597
  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.`;
6561
- 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 its DailyMed page URL), or a trial record "nct:05173896" (the eight digits; nct:NCT05173896 and a bare NCT05173896 are accepted).');
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).');
6562
6599
  var levelWord = (m) => m.level === "abstract" && !m.has_abstract ? "title" : m.level;
6563
6600
  var json = (s) => ({ content: [{ type: "text", text: statusAnswer(s) }] });
6564
6601
  function noticeTag(m) {
@@ -6875,14 +6912,14 @@ function registerTools(server2) {
6875
6912
  );
6876
6913
  server2.tool(
6877
6914
  "fh_library_read",
6878
- `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 the abstract alone and answers in milliseconds \u2014 set it whenever the abstract is enough (what a paper studied, its design, population, size, main finding; screening a list of papers): without it, a paper not yet stored or never searched for its full text is first looked up at every full-text source, which can take up to a minute per paper.`,
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).`,
6879
6916
  {
6880
6917
  id: idSchema,
6881
6918
  section: z.string().optional().describe("Heading from the outline (case-insensitive substring)."),
6882
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."),
6883
6920
  max_chars: z.number().int().positive().optional().describe("Cap for section text (default 6000); passages are capped at 1000 chars each regardless."),
6884
6921
  max_hits: z.number().int().positive().optional().describe("Cap for query passages (default 5)."),
6885
- abstract_only: z.boolean().optional().describe("true: read the PubMed abstract only, never the full text, and never start a full-text download \u2014 the answer comes back in milliseconds instead of up to a minute. A missing paper (pmid:) is stored from PubMed alone. Prefer it whenever the abstract answers the question: what a paper is about, its design, population, size, main result, or deciding whether it is worth reading in depth. Leave it out for details only the full text holds (methods, tables, subgroup and safety numbers) and for checking a claim. The answer's fulltext says whether a full text is stored or was never searched for; a later read without abstract_only fetches it.")
6922
+ 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.')
6886
6923
  },
6887
6924
  async ({ id, section: section2, query, max_chars, max_hits, abstract_only }) => {
6888
6925
  const parsed = parseId(id);
@@ -6984,7 +7021,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
6984
7021
  );
6985
7022
  server2.tool(
6986
7023
  "fh_verify_claim",
6987
- "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. 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.",
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.`,
6988
7025
  {
6989
7026
  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."),
6990
7027
  id: idSchema
@@ -7220,7 +7257,7 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7220
7257
  );
7221
7258
  server2.tool(
7222
7259
  "fh_evid_get",
7223
- `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. previous: true reads the version before the last put. name metadata.json: the metadata.`,
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.`,
7224
7261
  {
7225
7262
  evid: z.string().describe("The EVID."),
7226
7263
  name: z.string().describe(`The object's name, e.g. "lit-papers.csv".`),
@@ -7228,11 +7265,12 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
7228
7265
  query: z.string().optional().describe("Two or three distinctive terms."),
7229
7266
  max_chars: z.number().int().positive().optional().describe(`Cap for the object or section text (default ${DEFAULT_MAX_CHARS}).`),
7230
7267
  max_hits: z.number().int().positive().optional().describe("With query: passages (default 5) or csv rows (default 50)."),
7231
- previous: z.boolean().optional().describe("true: the previous version.")
7268
+ previous: z.boolean().optional().describe("true: the previous version."),
7269
+ lines: z.string().optional().describe('"a-b", "a" or "a-" (1-based): .md/.txt lines; .csv data rows, header as columns. Answer: first, last, total; cut when max_chars is reached.')
7232
7270
  },
7233
7271
  async ({ evid, name, ...opts }) => {
7234
7272
  const r = getObject(FH_EVIDENCE_DIR, evid, name, opts);
7235
- log("evid", evid, r.ok ? `get ${name}${opts.previous ? " previous" : ""}${opts.section ? ` section=${opts.section}` : ""}${opts.query ? ` query=${opts.query}` : ""}${"too_large" in r ? " outline" : ""}` : `get error ${r.error}`);
7273
+ log("evid", evid, r.ok ? `get ${name}${opts.previous ? " previous" : ""}${opts.section ? ` section=${opts.section}` : ""}${opts.query ? ` query=${opts.query}` : ""}${opts.lines ? ` lines=${opts.lines}` : ""}${"too_large" in r ? " outline" : ""}` : `get error ${r.error}`);
7236
7274
  return answer(r);
7237
7275
  }
7238
7276
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {