evidence-mcp-dev 1.0.14 → 1.0.16
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.
- package/dist/index.js +58 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3250,6 +3250,7 @@ var VARIABLES = [
|
|
|
3250
3250
|
"FH_REFRESH_AFTER_DAYS",
|
|
3251
3251
|
"FH_SEARCH_CACHE_DAYS",
|
|
3252
3252
|
"FH_NCBI_API_KEY",
|
|
3253
|
+
"FH_WEB_SEARCH_ENABLED",
|
|
3253
3254
|
"FH_WEB_SEARCH_EXA_API_KEY",
|
|
3254
3255
|
"FH_WEB_SEARCH_SERPER_API_KEY",
|
|
3255
3256
|
"FH_WEB_SEARCH_BRAVE_API_KEY",
|
|
@@ -3262,7 +3263,9 @@ var VARIABLES = [
|
|
|
3262
3263
|
"FH_BRIGHTDATA_API_KEY",
|
|
3263
3264
|
"FH_BRIGHTDATA_ZONE"
|
|
3264
3265
|
];
|
|
3265
|
-
var
|
|
3266
|
+
var on = (v) => /^(true|1|yes|on)$/i.test(v?.trim() ?? "");
|
|
3267
|
+
var hidden = (v, env) => v.startsWith("FH_WEB_SEARCH_") && !on(env.FH_WEB_SEARCH_ENABLED) || v === "FH_CITATIONS_ENABLED" && !on(env.FH_CITATIONS_ENABLED);
|
|
3268
|
+
var sources = (env = process.env) => Object.fromEntries(VARIABLES.filter((v) => !hidden(v, env)).map((v) => [v, sourceOf(v, env)]));
|
|
3266
3269
|
function settings(env = process.env) {
|
|
3267
3270
|
return {
|
|
3268
3271
|
retry_after_days: num("FH_RETRY_AFTER_DAYS", 1, env),
|
|
@@ -3878,7 +3881,9 @@ function cleanSnippet(t) {
|
|
|
3878
3881
|
return cut.slice(0, Math.max(cut.lastIndexOf(" "), SNIPPET_CHARS - 40)).replace(/[,;:\s]+$/, "") + " \u2026";
|
|
3879
3882
|
}
|
|
3880
3883
|
var SEARCH_PROVIDERS = ["exa", "serper", "brave"];
|
|
3884
|
+
var webSearchEnabled = (env = process.env) => /^(true|1|yes|on)$/i.test(env.FH_WEB_SEARCH_ENABLED?.trim() ?? "");
|
|
3881
3885
|
function webSearchConfig(env = process.env) {
|
|
3886
|
+
if (!webSearchEnabled(env)) return [];
|
|
3882
3887
|
return SEARCH_PROVIDERS.flatMap((provider) => {
|
|
3883
3888
|
const key2 = env[`FH_WEB_SEARCH_${provider.toUpperCase()}_API_KEY`]?.trim();
|
|
3884
3889
|
return key2 ? [{ provider, key: key2 }] : [];
|
|
@@ -4079,7 +4084,7 @@ function libraryInfo(libraryDir, host3, tiers = resolveTiers()) {
|
|
|
4079
4084
|
config: { ...settings(), problems: [...tiers.problems, ...verifyProblems()], sources: sources() },
|
|
4080
4085
|
download: downloadInfo(),
|
|
4081
4086
|
verify: verifyInfo(),
|
|
4082
|
-
web_search: webSearchConfig().map((c) => c.provider),
|
|
4087
|
+
...webSearchConfigured() ? { web_search: webSearchConfig().map((c) => c.provider) } : {},
|
|
4083
4088
|
unlockers: unlockers().map((provider) => ({ provider })),
|
|
4084
4089
|
stages: ownStages(),
|
|
4085
4090
|
entries: 0,
|
|
@@ -5581,14 +5586,24 @@ function normalizeQuery5(q) {
|
|
|
5581
5586
|
if (yr) out.years = `${yr.min === "1000" ? "" : yr.min}-${yr.max}`;
|
|
5582
5587
|
return out;
|
|
5583
5588
|
}
|
|
5584
|
-
var searchKey5 = (q) => createHash8("sha1").update(JSON.stringify(["
|
|
5589
|
+
var searchKey5 = (q) => createHash8("sha1").update(JSON.stringify(["cites2", q.id, q.types ?? [], q.years ?? "", q.sort, q.max_results])).digest("hex").slice(0, 16);
|
|
5585
5590
|
var live4 = (url) => fetchText(url, { "User-Agent": "evidence-mcp", Accept: "application/json" });
|
|
5586
5591
|
var OA = "https://api.openalex.org";
|
|
5587
5592
|
var mailto = () => openalexParams();
|
|
5588
|
-
|
|
5593
|
+
var COMMENT_TYPES = ["comment", "letter", "editorial"];
|
|
5594
|
+
var wantsComments = (q) => !!q.types?.some((t) => COMMENT_TYPES.includes(t));
|
|
5595
|
+
function citingUrl(work, q, page, perPage = PAGE, slack = 1) {
|
|
5589
5596
|
const yr = yearRange(q.years);
|
|
5590
|
-
const years = yr && !("error" in yr) ? `,publication_year:${yr.min === "1000" ? "" : yr.min}-${yr.max}` : "";
|
|
5591
|
-
return `${OA}/works?filter=cites:${work},has_pmid:true${years}&sort=${q.sort === "cited" ? "cited_by_count:desc" : "publication_date:desc"}&per-page=${
|
|
5597
|
+
const years = yr && !("error" in yr) ? `,publication_year:${yr.min === "1000" ? "" : Number(yr.min) - slack}-${Number(yr.max) + slack}` : "";
|
|
5598
|
+
return `${OA}/works?filter=cites:${work},has_pmid:true${years}&sort=${q.sort === "cited" ? "cited_by_count:desc" : "publication_date:desc"}&per-page=${perPage}&page=${page}&select=ids&${mailto()}`;
|
|
5599
|
+
}
|
|
5600
|
+
function parseCommentIn(xml) {
|
|
5601
|
+
const out = [];
|
|
5602
|
+
for (const m of xml.matchAll(/<CommentsCorrections\b[^>]*RefType="CommentIn"[^>]*>([\s\S]*?)<\/CommentsCorrections>/g)) {
|
|
5603
|
+
const p = /<PMID\b[^>]*>(\d+)<\/PMID>/.exec(m[1])?.[1];
|
|
5604
|
+
if (p && !out.includes(p)) out.push(p);
|
|
5605
|
+
}
|
|
5606
|
+
return out;
|
|
5592
5607
|
}
|
|
5593
5608
|
function parseCiting(json2) {
|
|
5594
5609
|
const d = JSON.parse(json2);
|
|
@@ -5610,36 +5625,51 @@ async function citingArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liv
|
|
|
5610
5625
|
} catch {
|
|
5611
5626
|
}
|
|
5612
5627
|
}
|
|
5613
|
-
let work;
|
|
5628
|
+
let work, pmid;
|
|
5614
5629
|
try {
|
|
5615
|
-
const w = JSON.parse(await fetchImpl(`${OA}/works/${q.id}?select=id&${mailto()}`));
|
|
5630
|
+
const w = JSON.parse(await fetchImpl(`${OA}/works/${q.id}?select=id,ids&${mailto()}`));
|
|
5616
5631
|
work = String(w?.id ?? "").split("/").pop() ?? "";
|
|
5617
5632
|
if (!work) return { ok: false, error: `openalex: ${q.id} not found` };
|
|
5633
|
+
pmid = q.id.startsWith("pmid:") ? q.id.slice(5) : String(w?.ids?.pmid ?? "").split("/").pop() || null;
|
|
5618
5634
|
} catch (e) {
|
|
5619
5635
|
const m = e instanceof Error ? e.message : String(e);
|
|
5620
5636
|
return /\b404\b/.test(m) ? { ok: false, error: `${q.id} not in OpenAlex`, input: true } : { ok: false, error: `openalex: ${m}` };
|
|
5621
5637
|
}
|
|
5622
|
-
const
|
|
5623
|
-
|
|
5638
|
+
const yr = yearRange(q.years);
|
|
5639
|
+
const inYears = (r) => !yr || "error" in yr || !!r[3] && r[3] >= yr.min && r[3] <= yr.max;
|
|
5640
|
+
const newestFirst = (rows2) => q.sort === "newest" ? rows2.sort((a, b) => (b[3] ?? "").localeCompare(a[3] ?? "")) : rows2;
|
|
5641
|
+
let rows, count, commentsOn;
|
|
5624
5642
|
try {
|
|
5643
|
+
let comments = [];
|
|
5644
|
+
if (wantsComments(q) && pmid) {
|
|
5645
|
+
const ids = parseCommentIn(await fetchImpl(efetchUrl(pmid)));
|
|
5646
|
+
if (ids.length) comments = newestFirst(parseEsummary(await fetchImpl(esummaryUrl(ids)), ids, libraryDir));
|
|
5647
|
+
}
|
|
5648
|
+
const seen2 = new Set(comments.map((r) => r[0]));
|
|
5649
|
+
const cited = [];
|
|
5650
|
+
let total = 0, matched = 0;
|
|
5625
5651
|
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
5626
5652
|
const { total: n, pmids } = parseCiting(await fetchImpl(citingUrl(work, q, page)));
|
|
5627
5653
|
total = n;
|
|
5628
5654
|
if (!pmids.length) break;
|
|
5629
|
-
const need =
|
|
5655
|
+
const need = pmids.filter((p) => !seen2.has(p));
|
|
5630
5656
|
const got = need.length ? parseEsummary(await fetchImpl(esummaryUrl(need)), need, libraryDir) : [];
|
|
5631
5657
|
for (const r of got) {
|
|
5632
|
-
if (q.types && !typeMatch(r, q.types)) continue;
|
|
5658
|
+
if (!inYears(r) || q.types && !typeMatch(r, q.types)) continue;
|
|
5633
5659
|
matched++;
|
|
5634
|
-
|
|
5660
|
+
cited.push(r);
|
|
5635
5661
|
}
|
|
5636
|
-
if (!q.types &&
|
|
5662
|
+
if (!q.types && comments.length + cited.length >= q.max_results) break;
|
|
5637
5663
|
if (page * PAGE >= n) break;
|
|
5638
5664
|
}
|
|
5665
|
+
if (!q.types && q.years) total = parseCiting(await fetchImpl(citingUrl(work, q, 1, 1, 0))).total;
|
|
5666
|
+
rows = [...comments, ...newestFirst(cited)].slice(0, q.max_results);
|
|
5667
|
+
count = q.types ? comments.length + matched : total;
|
|
5668
|
+
commentsOn = comments.slice(0, rows.length).map((r) => r[0]);
|
|
5639
5669
|
} catch (e) {
|
|
5640
5670
|
return { ok: false, error: `citations: ${e instanceof Error ? e.message : String(e)}` };
|
|
5641
5671
|
}
|
|
5642
|
-
const result = { source: "openalex+pubmed", query: q, total:
|
|
5672
|
+
const result = { source: "openalex+pubmed", query: q, total: count, ...commentsOn.length ? { comments_on: commentsOn } : {}, columns: COLUMNS3, rows, searched: today() };
|
|
5643
5673
|
try {
|
|
5644
5674
|
mkdirSync12(dirname9(file3), { recursive: true });
|
|
5645
5675
|
writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
|
|
@@ -5899,7 +5929,7 @@ Tools
|
|
|
5899
5929
|
- fh_verify_claim(claim, id) \u2014 does this one source state this one finding? A decision model judges the stored text and returns a verdict.
|
|
5900
5930
|
- fh_pubmed_fetch_articles(pmids) \u2014 title, first author, year, publication types, retracted and level for up to 200 PMIDs at once; faster and far smaller than asking PubMed, known papers from disk, the rest in one request and stored. For abstract or full text: fh_library_read.
|
|
5901
5931
|
- fh_pubmed_search_articles(query, max_results?, sort?, years?) \u2014 search PubMed in its own syntax: the total and rows in columns order (PMID, title, first author, year, journal, publication types, PMCID, library level); faster and far smaller than asking PubMed. Cached a week.
|
|
5902
|
-
${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
|
|
5932
|
+
${citationsEnabled() ? "- fh_pubmed_citing_articles(id, types?, years?, sort?, max_results?) \u2014 the papers that cite a paper (pmid: or doi:), as rows in fh_pubmed_search_articles' columns: follow-ups of a trial, later meta-analyses that include it, guidelines (sort: cited), comments on it (types comment, letter, editorial: PubMed's comments on the paper first, listed in comments_on). At most 100 rows, no paging: narrow with types or years. Cached a week.\n" : ""}- fh_clinicaltrials_search_studies(query | intervention | condition, status?, sort?, max_results?) \u2014 search ClinicalTrials.gov: the total and rows in columns order (NCT ID, title, status, phase, enrollment, dates, primary outcome, conditions, interventions, has_results). Cached a week.
|
|
5903
5933
|
- fh_dailymed_search_labels(drug_name, labeler?, max_results?) \u2014 find FDA drug labels by generic or brand name: the total and rows in columns order (set ID, title, labeler, published, version, level), newest first; labeler narrows to one company. Use it rather than DailyMed's search page, which shows no set IDs as Markdown. Cached a week.
|
|
5904
5934
|
${webSearchConfigured() ? "- fh_web_search(query, max_results?) \u2014 search the web; use it instead of the built-in web search. Links (title, URL, date, author) with a short passage from each page, not the page text, so a fraction of the context; read a result with fh_fetch_url. site: in the query restricts it to a site, as with any search engine. For more results, search again with other words. Cached locally for a week.\n" : ""}- fh_clinicaltrials_get_study_record(nct) \u2014 one trial as a review needs it (status, design, enrollment, dates, outcomes, eligibility, result publications, summary), from the stored record; added first when missing.
|
|
5905
5935
|
- fh_clinicaltrials_get_study_results(nct, max_chars?) \u2014 a trial's posted results as Markdown, capped; the outcome titles listed for fh_library_read.
|
|
@@ -6487,12 +6517,17 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6487
6517
|
);
|
|
6488
6518
|
if (citationsEnabled()) server2.tool(
|
|
6489
6519
|
"fh_pubmed_citing_articles",
|
|
6490
|
-
`The papers that cite a paper
|
|
6520
|
+
`The papers that cite a paper, as rows in fh_pubmed_search_articles' columns: PMID, title, first author, year, journal, publication types, PMCID, library level. Use it for a trial's follow-ups, later meta-analyses that include it, guidelines (sort: cited) and comments on it.
|
|
6521
|
+
- types: PubMed publication types, any of them; a paper without one (many plain articles, some guidelines) never matches.
|
|
6522
|
+
- Comments: with comment, letter or editorial in types, the comments PubMed links to the paper come first, of any year and type, and comments_on lists their PMIDs. The other rows only cite the paper and are mostly about something else.
|
|
6523
|
+
- years and sort newest go by the year column.
|
|
6524
|
+
- At most ${MAX_RESULTS4} rows, no paging: for more, narrow with types or years, or sort: cited. total counts every match.
|
|
6525
|
+
Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
|
|
6491
6526
|
{
|
|
6492
6527
|
id: z.string().describe('The cited paper: "pmid:18378520" or "doi:10.1056/NEJMoa0801317".'),
|
|
6493
|
-
types: z.array(z.string()).optional().describe('Publication types, any of them:
|
|
6494
|
-
years: z.string().optional().describe('Publication years of the citing papers: "2020-2026", "2022-", "-2019" or "2022".'),
|
|
6495
|
-
sort: z.enum(["newest", "cited"]).default("newest").describe("newest (
|
|
6528
|
+
types: z.array(z.string()).optional().describe('Publication types, any of them: "meta-analysis", "systematic review", "randomized controlled trial", "review", "guideline", "comment", "letter", "editorial".'),
|
|
6529
|
+
years: z.string().optional().describe('Publication years of the citing papers, as in the year column: "2020-2026", "2022-", "-2019" or "2022". Not applied to the comments PubMed links.'),
|
|
6530
|
+
sort: z.enum(["newest", "cited"]).default("newest").describe("newest (latest year first) or cited (most cited first)."),
|
|
6496
6531
|
max_results: z.number().int().min(1).max(MAX_RESULTS4).default(20).describe("Rows to return (1\u2013100).")
|
|
6497
6532
|
},
|
|
6498
6533
|
async (args) => {
|
|
@@ -6505,8 +6540,9 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6505
6540
|
}
|
|
6506
6541
|
bump("search", r.cached);
|
|
6507
6542
|
const q = r.result.query;
|
|
6508
|
-
log("search", "citing", `ok ${r.cached ? "cached" : secs} rows=${r.result.rows.length} total=${r.result.total}${q.types ? ` types=${q.types.join(",")}` : ""}${q.years ? ` years=${q.years}` : ""}${q.sort !== "newest" ? ` sort=${q.sort}` : ""} | ${q.id}`);
|
|
6509
|
-
|
|
6543
|
+
log("search", "citing", `ok ${r.cached ? "cached" : secs} rows=${r.result.rows.length} total=${r.result.total}${r.result.comments_on ? ` comments_on=${r.result.comments_on.length}` : ""}${q.types ? ` types=${q.types.join(",")}` : ""}${q.years ? ` years=${q.years}` : ""}${q.sort !== "newest" ? ` sort=${q.sort}` : ""} | ${q.id}`);
|
|
6544
|
+
const { total, comments_on, columns: columns2, rows } = r.result;
|
|
6545
|
+
return { content: [{ type: "text", text: compact2({ total, comments_on, columns: columns2, rows }) }] };
|
|
6510
6546
|
}
|
|
6511
6547
|
);
|
|
6512
6548
|
server2.tool(
|