evidence-mcp-dev 1.0.11 → 1.0.13
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 +152 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -150,6 +150,10 @@ function timeoutOr(ms, signal) {
|
|
|
150
150
|
// src/contact.ts
|
|
151
151
|
var DEFAULT = "hello@forever-healthy.org";
|
|
152
152
|
var contactEmail = (env = process.env) => str("FH_CONTACT_EMAIL", env) || DEFAULT;
|
|
153
|
+
var openalexParams = (env = process.env) => {
|
|
154
|
+
const key2 = env.FH_OPENALEX_API_KEY?.trim();
|
|
155
|
+
return `mailto=${encodeURIComponent(contactEmail(env))}${key2 ? `&api_key=${encodeURIComponent(key2)}` : ""}`;
|
|
156
|
+
};
|
|
153
157
|
|
|
154
158
|
// src/fetchproxy.ts
|
|
155
159
|
import { ProxyAgent } from "undici";
|
|
@@ -2638,8 +2642,8 @@ function walled(url, stage2, dir = FH_EVIDENCE_DIR) {
|
|
|
2638
2642
|
const h = host(url);
|
|
2639
2643
|
if (!h) return null;
|
|
2640
2644
|
const all = read(dir, h);
|
|
2641
|
-
const
|
|
2642
|
-
return
|
|
2645
|
+
const live5 = (r) => r && (r.streak >= WALL_STREAK || RULE.test(r.reason)) && daysSince(r.date) < settings().retry_after_days ? r : null;
|
|
2646
|
+
return live5(all[stage2] ?? all[legacy(stage2)]) ?? live5(all[pathKey(url, stage2)]);
|
|
2643
2647
|
}
|
|
2644
2648
|
function recordStage(url, stage2, ok, reason = "", dir = FH_EVIDENCE_DIR) {
|
|
2645
2649
|
const h = host(url);
|
|
@@ -3024,7 +3028,7 @@ function europepmcCandidates(r, pmcid) {
|
|
|
3024
3028
|
var openalex = {
|
|
3025
3029
|
name: "openalex",
|
|
3026
3030
|
applies: (p) => p.pmid || p.doi ? true : "no pmid or doi",
|
|
3027
|
-
lookup: (p) => fetchText(`https://api.openalex.org/works/${encodeURIComponent(p.pmid ? `pmid:${p.pmid}` : `doi:${p.doi}`)}
|
|
3031
|
+
lookup: (p) => fetchText(`https://api.openalex.org/works/${encodeURIComponent(p.pmid ? `pmid:${p.pmid}` : `doi:${p.doi}`)}?${openalexParams()}`, { "User-Agent": LIBRARY_UA }),
|
|
3028
3032
|
async run(p, ctx) {
|
|
3029
3033
|
let data;
|
|
3030
3034
|
try {
|
|
@@ -3251,6 +3255,8 @@ var VARIABLES = [
|
|
|
3251
3255
|
"FH_WEB_SEARCH_BRAVE_API_KEY",
|
|
3252
3256
|
"FH_WEB_SEARCH_SNIPPETS",
|
|
3253
3257
|
"FH_WEB_SEARCH_TIMEOUT_SECS",
|
|
3258
|
+
"FH_CITATIONS_ENABLED",
|
|
3259
|
+
"FH_OPENALEX_API_KEY",
|
|
3254
3260
|
"FH_ZENROWS_API_KEY",
|
|
3255
3261
|
"FH_ZYTE_API_KEY",
|
|
3256
3262
|
"FH_BRIGHTDATA_API_KEY",
|
|
@@ -3623,7 +3629,7 @@ function publish() {
|
|
|
3623
3629
|
}
|
|
3624
3630
|
|
|
3625
3631
|
// src/tools.ts
|
|
3626
|
-
import { existsSync as
|
|
3632
|
+
import { existsSync as existsSync17, readFileSync as readFileSync15 } from "fs";
|
|
3627
3633
|
import { z } from "zod";
|
|
3628
3634
|
|
|
3629
3635
|
// src/cascade.ts
|
|
@@ -3828,7 +3834,7 @@ function parseRows(json2) {
|
|
|
3828
3834
|
var liveFetch = (url) => fetchText(url, { "User-Agent": LIBRARY_UA, Accept: "application/json" });
|
|
3829
3835
|
async function searchTrials(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liveFetch) {
|
|
3830
3836
|
const q = normalizeQuery(raw);
|
|
3831
|
-
if ("error" in q) return { ok: false, error: q.error };
|
|
3837
|
+
if ("error" in q) return { ok: false, error: q.error, input: true };
|
|
3832
3838
|
const file3 = searchFile(libraryDir, searchKey(q));
|
|
3833
3839
|
if (existsSync7(file3)) {
|
|
3834
3840
|
try {
|
|
@@ -4023,7 +4029,7 @@ function mergeRows(lists) {
|
|
|
4023
4029
|
async function webSearch(raw, libraryDir = FH_EVIDENCE_DIR, post2 = live, cfgs = webSearchConfig(), onEvent) {
|
|
4024
4030
|
if (!cfgs.length) return { ok: false, error: "web search not configured" };
|
|
4025
4031
|
const q = normalizeQuery2(raw);
|
|
4026
|
-
if ("error" in q) return { ok: false, error: q.error };
|
|
4032
|
+
if ("error" in q) return { ok: false, error: q.error, input: true };
|
|
4027
4033
|
const answers = await Promise.allSettled(cfgs.map((c) => oneProvider(q, c, libraryDir, post2, onEvent)));
|
|
4028
4034
|
const providers = {};
|
|
4029
4035
|
const lists = [];
|
|
@@ -4514,7 +4520,7 @@ function fromInvertedIndex(index) {
|
|
|
4514
4520
|
}
|
|
4515
4521
|
async function openAlexAbstract(doi) {
|
|
4516
4522
|
try {
|
|
4517
|
-
const j = JSON.parse(await fetchText(`https://api.openalex.org/works/https://doi.org/${encodeURIComponent(doi)}
|
|
4523
|
+
const j = JSON.parse(await fetchText(`https://api.openalex.org/works/https://doi.org/${encodeURIComponent(doi)}?${openalexParams()}&select=abstract_inverted_index`, { "User-Agent": LIBRARY_UA }));
|
|
4518
4524
|
return fromInvertedIndex(j.abstract_inverted_index);
|
|
4519
4525
|
} catch {
|
|
4520
4526
|
return "";
|
|
@@ -5433,7 +5439,7 @@ function levelOf(id, libraryDir) {
|
|
|
5433
5439
|
var live2 = (url) => fetchText(url, { "User-Agent": "evidence-mcp", Accept: "application/json" });
|
|
5434
5440
|
async function searchArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = live2) {
|
|
5435
5441
|
const q = normalizeQuery3(raw);
|
|
5436
|
-
if ("error" in q) return { ok: false, error: q.error };
|
|
5442
|
+
if ("error" in q) return { ok: false, error: q.error, input: true };
|
|
5437
5443
|
const file3 = searchFile(libraryDir, searchKey3(q));
|
|
5438
5444
|
if (existsSync13(file3)) {
|
|
5439
5445
|
try {
|
|
@@ -5519,7 +5525,7 @@ function parseSearch(json2, libraryDir) {
|
|
|
5519
5525
|
var live3 = (url) => fetchText(url, { "User-Agent": LIBRARY_UA, Accept: "application/json" });
|
|
5520
5526
|
async function searchLabels(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = live3) {
|
|
5521
5527
|
const q = normalizeQuery4(raw);
|
|
5522
|
-
if ("error" in q) return { ok: false, error: q.error };
|
|
5528
|
+
if ("error" in q) return { ok: false, error: q.error, input: true };
|
|
5523
5529
|
const file3 = searchFile(libraryDir, searchKey4(q));
|
|
5524
5530
|
if (existsSync14(file3)) {
|
|
5525
5531
|
try {
|
|
@@ -5547,6 +5553,101 @@ async function searchLabels(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = live3
|
|
|
5547
5553
|
return { ok: true, result, cached: false };
|
|
5548
5554
|
}
|
|
5549
5555
|
|
|
5556
|
+
// src/citations.ts
|
|
5557
|
+
import { createHash as createHash8 } from "crypto";
|
|
5558
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync12, readFileSync as readFileSync13 } from "fs";
|
|
5559
|
+
import { dirname as dirname9 } from "path";
|
|
5560
|
+
var MAX_RESULTS4 = 100;
|
|
5561
|
+
var DEFAULT_RESULTS4 = 20;
|
|
5562
|
+
var PAGE = 200;
|
|
5563
|
+
var MAX_PAGES = 50;
|
|
5564
|
+
var citationsEnabled = (env = process.env) => /^(true|1|yes|on)$/i.test(env.FH_CITATIONS_ENABLED?.trim() ?? "");
|
|
5565
|
+
var ALIAS = { rct: "randomized controlled trial", "systematic-review": "systematic review" };
|
|
5566
|
+
var norm2 = (t) => {
|
|
5567
|
+
const s = t.toLowerCase().replace(/[-_\s]+/g, " ").trim();
|
|
5568
|
+
return ALIAS[s.replace(/ /g, "-")] ?? ALIAS[s] ?? s;
|
|
5569
|
+
};
|
|
5570
|
+
function normalizeQuery5(q) {
|
|
5571
|
+
const p = parseId(q.id ?? "");
|
|
5572
|
+
if (p.error || !p.id) return { error: p.error ?? "invalid id" };
|
|
5573
|
+
if (p.type !== "pmid" && p.type !== "doi") return { error: `citations need a paper's pmid: or doi:, not ${p.type}:` };
|
|
5574
|
+
const sort = q.sort ?? "newest";
|
|
5575
|
+
if (!["newest", "cited"].includes(sort)) return { error: `sort must be newest or cited, not "${String(q.sort)}"` };
|
|
5576
|
+
const yr = yearRange(q.years);
|
|
5577
|
+
if (yr && "error" in yr) return yr;
|
|
5578
|
+
const out = { id: `${p.type}:${p.id}`, sort, max_results: Math.min(MAX_RESULTS4, Math.max(1, Math.floor(q.max_results ?? DEFAULT_RESULTS4))) };
|
|
5579
|
+
const types = [...new Set((q.types ?? []).map(norm2).filter(Boolean))].sort();
|
|
5580
|
+
if (types.length) out.types = types;
|
|
5581
|
+
if (yr) out.years = `${yr.min === "1000" ? "" : yr.min}-${yr.max}`;
|
|
5582
|
+
return out;
|
|
5583
|
+
}
|
|
5584
|
+
var searchKey5 = (q) => createHash8("sha1").update(JSON.stringify(["cites", q.id, q.types ?? [], q.years ?? "", q.sort, q.max_results])).digest("hex").slice(0, 16);
|
|
5585
|
+
var live4 = (url) => fetchText(url, { "User-Agent": "evidence-mcp", Accept: "application/json" });
|
|
5586
|
+
var OA = "https://api.openalex.org";
|
|
5587
|
+
var mailto = () => openalexParams();
|
|
5588
|
+
function citingUrl(work, q, page) {
|
|
5589
|
+
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=${PAGE}&page=${page}&select=ids&${mailto()}`;
|
|
5592
|
+
}
|
|
5593
|
+
function parseCiting(json2) {
|
|
5594
|
+
const d = JSON.parse(json2);
|
|
5595
|
+
const pmids = (Array.isArray(d?.results) ? d.results : []).map((r) => String(r?.ids?.pmid ?? "").split("/").pop() ?? "").filter((s) => /^\d+$/.test(s));
|
|
5596
|
+
return { total: Number(d?.meta?.count ?? 0) || 0, pmids };
|
|
5597
|
+
}
|
|
5598
|
+
var typeMatch = (row3, types) => {
|
|
5599
|
+
const have = (row3[5] ?? "").split(";").map(norm2);
|
|
5600
|
+
return types.some((t) => have.some((h) => h.includes(t)));
|
|
5601
|
+
};
|
|
5602
|
+
async function citingArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = live4) {
|
|
5603
|
+
const q = normalizeQuery5(raw);
|
|
5604
|
+
if ("error" in q) return { ok: false, error: q.error, input: true };
|
|
5605
|
+
const file3 = searchFile(libraryDir, searchKey5(q));
|
|
5606
|
+
if (existsSync15(file3)) {
|
|
5607
|
+
try {
|
|
5608
|
+
const r = JSON.parse(readFileSync13(file3, "utf8"));
|
|
5609
|
+
if (daysSince(r.searched) < searchCacheDays()) return { ok: true, result: r, cached: true };
|
|
5610
|
+
} catch {
|
|
5611
|
+
}
|
|
5612
|
+
}
|
|
5613
|
+
let work;
|
|
5614
|
+
try {
|
|
5615
|
+
const w = JSON.parse(await fetchImpl(`${OA}/works/${q.id}?select=id&${mailto()}`));
|
|
5616
|
+
work = String(w?.id ?? "").split("/").pop() ?? "";
|
|
5617
|
+
if (!work) return { ok: false, error: `openalex: ${q.id} not found` };
|
|
5618
|
+
} catch (e) {
|
|
5619
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
5620
|
+
return /\b404\b/.test(m) ? { ok: false, error: `${q.id} not in OpenAlex`, input: true } : { ok: false, error: `openalex: ${m}` };
|
|
5621
|
+
}
|
|
5622
|
+
const rows = [];
|
|
5623
|
+
let total = 0, matched = 0;
|
|
5624
|
+
try {
|
|
5625
|
+
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
5626
|
+
const { total: n, pmids } = parseCiting(await fetchImpl(citingUrl(work, q, page)));
|
|
5627
|
+
total = n;
|
|
5628
|
+
if (!pmids.length) break;
|
|
5629
|
+
const need = q.types ? pmids : pmids.slice(0, q.max_results - rows.length);
|
|
5630
|
+
const got = need.length ? parseEsummary(await fetchImpl(esummaryUrl(need)), need, libraryDir) : [];
|
|
5631
|
+
for (const r of got) {
|
|
5632
|
+
if (q.types && !typeMatch(r, q.types)) continue;
|
|
5633
|
+
matched++;
|
|
5634
|
+
if (rows.length < q.max_results) rows.push(r);
|
|
5635
|
+
}
|
|
5636
|
+
if (!q.types && rows.length >= q.max_results) break;
|
|
5637
|
+
if (page * PAGE >= n) break;
|
|
5638
|
+
}
|
|
5639
|
+
} catch (e) {
|
|
5640
|
+
return { ok: false, error: `citations: ${e instanceof Error ? e.message : String(e)}` };
|
|
5641
|
+
}
|
|
5642
|
+
const result = { source: "openalex+pubmed", query: q, total: q.types ? matched : total, columns: COLUMNS3, rows, searched: today() };
|
|
5643
|
+
try {
|
|
5644
|
+
mkdirSync12(dirname9(file3), { recursive: true });
|
|
5645
|
+
writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
|
|
5646
|
+
} catch {
|
|
5647
|
+
}
|
|
5648
|
+
return { ok: true, result, cached: false };
|
|
5649
|
+
}
|
|
5650
|
+
|
|
5550
5651
|
// src/trialrecord.ts
|
|
5551
5652
|
var list4 = (a) => Array.isArray(a) ? a : [];
|
|
5552
5653
|
var para2 = (s, max = Infinity) => {
|
|
@@ -5664,13 +5765,13 @@ function resultsText(nct, md, maxChars) {
|
|
|
5664
5765
|
}
|
|
5665
5766
|
|
|
5666
5767
|
// src/missing.ts
|
|
5667
|
-
import { existsSync as
|
|
5768
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync13, readFileSync as readFileSync14 } from "fs";
|
|
5668
5769
|
import { join as join12 } from "path";
|
|
5669
5770
|
var missingFile = (p) => join12(p.entryDir, `${p.entry}-missing.md`);
|
|
5670
5771
|
function readMissing(p) {
|
|
5671
5772
|
const f = missingFile(p);
|
|
5672
|
-
if (!
|
|
5673
|
-
const md =
|
|
5773
|
+
if (!existsSync16(f)) return null;
|
|
5774
|
+
const md = readFileSync14(f, "utf8");
|
|
5674
5775
|
const get4 = (k) => /^$/.test(k) ? "" : (new RegExp(`^${k}:[ \\t]*(.*)$`, "m").exec(md)?.[1] ?? "").trim();
|
|
5675
5776
|
const checked = get4("checked"), reason = get4("reason");
|
|
5676
5777
|
return checked ? { checked, reason: reason || "not found" } : null;
|
|
@@ -5681,7 +5782,7 @@ function freshMissing(p, retryDays) {
|
|
|
5681
5782
|
}
|
|
5682
5783
|
function rememberMissing(p, reason) {
|
|
5683
5784
|
const m = { checked: now(), reason };
|
|
5684
|
-
|
|
5785
|
+
mkdirSync13(p.entryDir, { recursive: true });
|
|
5685
5786
|
writeAtomic(missingFile(p), `checked: ${m.checked}
|
|
5686
5787
|
reason: ${m.reason}
|
|
5687
5788
|
`);
|
|
@@ -5777,7 +5878,7 @@ async function fetchArticles(ids, libraryDir = FH_EVIDENCE_DIR, converter = "evi
|
|
|
5777
5878
|
// src/tools.ts
|
|
5778
5879
|
var pkg = (() => {
|
|
5779
5880
|
try {
|
|
5780
|
-
return JSON.parse(
|
|
5881
|
+
return JSON.parse(readFileSync15(new URL("../package.json", import.meta.url), "utf8"));
|
|
5781
5882
|
} catch {
|
|
5782
5883
|
return { name: "evidence-mcp", version: "0.0.0" };
|
|
5783
5884
|
}
|
|
@@ -5798,7 +5899,7 @@ Tools
|
|
|
5798
5899
|
- 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.
|
|
5799
5900
|
- 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.
|
|
5800
5901
|
- 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.
|
|
5801
|
-
- 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.
|
|
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; types filters by publication type (meta-analysis, randomized controlled trial, review), years by publication year; sort newest | cited. For a trial's follow-ups, newer meta-analyses that include it, and comments on it. Cached a week.\n" : ""}- fh_clinicaltrials_search_studies(query | intervention | condition, status?, sort?, max_results?) \u2014 search ClinicalTrials.gov: the total and rows in columns order (NCT ID, title, status, phase, enrollment, dates, primary outcome, conditions, interventions, has_results). Cached a week.
|
|
5802
5903
|
- 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.
|
|
5803
5904
|
${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.
|
|
5804
5905
|
- 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.
|
|
@@ -6173,8 +6274,8 @@ function registerTools(server2) {
|
|
|
6173
6274
|
}
|
|
6174
6275
|
added = true;
|
|
6175
6276
|
}
|
|
6176
|
-
const full =
|
|
6177
|
-
const md =
|
|
6277
|
+
const full = existsSync17(paths.fulltextMd);
|
|
6278
|
+
const md = readFileSync15(full ? paths.fulltextMd : paths.md, "utf8");
|
|
6178
6279
|
const text4 = full ? "full_text" : "abstract";
|
|
6179
6280
|
const base = added ? { requested: parsed.requested, entry: paths.entry, text: text4, added: true } : { requested: parsed.requested, entry: paths.entry, text: text4 };
|
|
6180
6281
|
const headings2 = () => outline(md, text4).sections;
|
|
@@ -6194,8 +6295,8 @@ function registerTools(server2) {
|
|
|
6194
6295
|
const cap = max_chars ?? 6e3;
|
|
6195
6296
|
let sec = readSection(md, section2, cap);
|
|
6196
6297
|
let via = "";
|
|
6197
|
-
if (!sec && /abstract/i.test(section2) && full &&
|
|
6198
|
-
sec = readSection(
|
|
6298
|
+
if (!sec && /abstract/i.test(section2) && full && existsSync17(paths.md)) {
|
|
6299
|
+
sec = readSection(readFileSync15(paths.md, "utf8"), "abstract", cap);
|
|
6199
6300
|
via = " (from the abstract file)";
|
|
6200
6301
|
}
|
|
6201
6302
|
if (!sec && /declaration/i.test(section2)) {
|
|
@@ -6324,8 +6425,8 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
|
|
|
6324
6425
|
return { content: [{ type: "text", text: `Failed to fetch ${url}: ${added.error}` }], isError: true };
|
|
6325
6426
|
}
|
|
6326
6427
|
}
|
|
6327
|
-
const file3 = pid.type === "pmid" ? paths.md :
|
|
6328
|
-
const md =
|
|
6428
|
+
const file3 = pid.type === "pmid" ? paths.md : existsSync17(paths.fulltextMd) ? paths.fulltextMd : paths.md;
|
|
6429
|
+
const md = existsSync17(file3) ? readFileSync15(file3, "utf8") : "";
|
|
6329
6430
|
const text4 = title_only ? `Contents of ${url}:
|
|
6330
6431
|
${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "", max_length, start_index);
|
|
6331
6432
|
bump("fetch", had);
|
|
@@ -6375,7 +6476,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6375
6476
|
const r = await searchArticles(args, FH_EVIDENCE_DIR);
|
|
6376
6477
|
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6377
6478
|
if (!r.ok) {
|
|
6378
|
-
log("search", "pubmed",
|
|
6479
|
+
log("search", "pubmed", `${r.input ? "error" : `failed ${secs}`} ${r.error} | ${args.query}`);
|
|
6379
6480
|
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6380
6481
|
}
|
|
6381
6482
|
bump("search", r.cached);
|
|
@@ -6384,6 +6485,30 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6384
6485
|
return { content: [{ type: "text", text: searchAnswer(r.result) }] };
|
|
6385
6486
|
}
|
|
6386
6487
|
);
|
|
6488
|
+
if (citationsEnabled()) server2.tool(
|
|
6489
|
+
"fh_pubmed_citing_articles",
|
|
6490
|
+
`The papers that cite a paper: OpenAlex finds them, PubMed gives the rows \u2014 the total and up to ${MAX_RESULTS4} rows as arrays in columns order, as fh_pubmed_search_articles: PMID, title, first author, year, journal, publication types, PMCID, library level. For a trial's follow-ups and long-term results, newer meta-analyses that include it, and comments, letters and re-analyses of it. types narrows to publication types ("meta-analysis", "randomized controlled trial", "review", "comment"); years to publication years; sort newest (default) or cited (most cited first). Cached ${searchCacheDays()} days.`,
|
|
6491
|
+
{
|
|
6492
|
+
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: ["meta-analysis", "systematic review"].'),
|
|
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 (publication date, latest first) or cited (most cited first)."),
|
|
6496
|
+
max_results: z.number().int().min(1).max(MAX_RESULTS4).default(20).describe("Rows to return (1\u2013100).")
|
|
6497
|
+
},
|
|
6498
|
+
async (args) => {
|
|
6499
|
+
const t0 = Date.now();
|
|
6500
|
+
const r = await citingArticles(args, FH_EVIDENCE_DIR);
|
|
6501
|
+
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6502
|
+
if (!r.ok) {
|
|
6503
|
+
log("search", "cites", `${r.input ? "error" : `failed ${secs}`} ${r.error} | ${args.id}`);
|
|
6504
|
+
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6505
|
+
}
|
|
6506
|
+
bump("search", r.cached);
|
|
6507
|
+
const q = r.result.query;
|
|
6508
|
+
log("search", "cites", `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
|
+
return { content: [{ type: "text", text: searchAnswer(r.result) }] };
|
|
6510
|
+
}
|
|
6511
|
+
);
|
|
6387
6512
|
server2.tool(
|
|
6388
6513
|
"fh_clinicaltrials_search_studies",
|
|
6389
6514
|
`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.`,
|
|
@@ -6400,7 +6525,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6400
6525
|
const r = await searchTrials(args, FH_EVIDENCE_DIR);
|
|
6401
6526
|
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6402
6527
|
if (!r.ok) {
|
|
6403
|
-
log("search", "nct",
|
|
6528
|
+
log("search", "nct", `${r.input ? "error" : `failed ${secs}`} ${r.error}${((t) => t ? ` | ${t}` : "")([args.query, args.intervention, args.condition].map((v) => v?.trim()).filter(Boolean).join(" "))}`);
|
|
6404
6529
|
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6405
6530
|
}
|
|
6406
6531
|
bump("search", r.cached);
|
|
@@ -6421,7 +6546,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6421
6546
|
const r = await webSearch(args, FH_EVIDENCE_DIR, void 0, void 0, (line) => log("search", "web", `${line} | ${args.query}`));
|
|
6422
6547
|
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6423
6548
|
if (!r.ok) {
|
|
6424
|
-
log("search", "web",
|
|
6549
|
+
log("search", "web", `${r.input ? "error" : `failed ${secs}`} ${r.error} | ${args.query}`);
|
|
6425
6550
|
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6426
6551
|
}
|
|
6427
6552
|
bump("search", r.cached);
|
|
@@ -6444,7 +6569,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6444
6569
|
const r = await searchLabels(args, FH_EVIDENCE_DIR);
|
|
6445
6570
|
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6446
6571
|
if (!r.ok) {
|
|
6447
|
-
log("search", "dailymed",
|
|
6572
|
+
log("search", "dailymed", `${r.input ? "error" : `failed ${secs}`} ${r.error}${args.drug_name?.trim() ? ` | ${args.drug_name.trim()}` : ""}`);
|
|
6448
6573
|
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6449
6574
|
}
|
|
6450
6575
|
bump("search", r.cached);
|
|
@@ -6478,7 +6603,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6478
6603
|
return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
|
|
6479
6604
|
}
|
|
6480
6605
|
const raw = e.paths.fulltextRaw("json");
|
|
6481
|
-
const r =
|
|
6606
|
+
const r = existsSync17(raw) ? recordSummary(readFileSync15(raw, "utf8")) : null;
|
|
6482
6607
|
if (!r) {
|
|
6483
6608
|
log("trials", e.requested, "record error: no stored record");
|
|
6484
6609
|
return { content: [{ type: "text", text: compact2({ error: "no stored record" }) }], isError: true };
|
|
@@ -6497,7 +6622,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6497
6622
|
log("trials", nct, `results error: ${e.error}`);
|
|
6498
6623
|
return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
|
|
6499
6624
|
}
|
|
6500
|
-
const md =
|
|
6625
|
+
const md = existsSync17(e.paths.fulltextMd) ? readFileSync15(e.paths.fulltextMd, "utf8") : "";
|
|
6501
6626
|
const r = resultsText(e.requested.replace(/^nct:/, "NCT"), md, max_chars);
|
|
6502
6627
|
log("trials", e.requested, `results ${r.has_results ? `${r.outcomes.length} outcomes${r.truncated ? " truncated" : ""}` : "none"}`);
|
|
6503
6628
|
return { content: [{ type: "text", text: leanJson(r) }] };
|