evidence-mcp-dev 1.0.4 → 1.0.6
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 +191 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2638,8 +2638,8 @@ function walled(url, stage2, dir = FH_EVIDENCE_DIR) {
|
|
|
2638
2638
|
const h = host(url);
|
|
2639
2639
|
if (!h) return null;
|
|
2640
2640
|
const all = read(dir, h);
|
|
2641
|
-
const
|
|
2642
|
-
return
|
|
2641
|
+
const live3 = (r) => r && (r.streak >= WALL_STREAK || RULE.test(r.reason)) && daysSince(r.date) < settings().retry_after_days ? r : null;
|
|
2642
|
+
return live3(all[stage2] ?? all[legacy(stage2)]) ?? live3(all[pathKey(url, stage2)]);
|
|
2643
2643
|
}
|
|
2644
2644
|
function recordStage(url, stage2, ok, reason = "", dir = FH_EVIDENCE_DIR) {
|
|
2645
2645
|
const h = host(url);
|
|
@@ -3233,6 +3233,9 @@ var VARIABLES = [
|
|
|
3233
3233
|
"FH_VERIFY_OPENAI_MODEL",
|
|
3234
3234
|
"FH_VERIFY_OPENAI_URL",
|
|
3235
3235
|
"FH_VERIFY_OPENAI_API_KEY",
|
|
3236
|
+
"FH_VERIFY_LIQUID_MODEL",
|
|
3237
|
+
"FH_VERIFY_LIQUID_URL",
|
|
3238
|
+
"FH_VERIFY_LIQUID_API_KEY",
|
|
3236
3239
|
"FH_VERIFY_MODEL",
|
|
3237
3240
|
"FH_VERIFY_URL",
|
|
3238
3241
|
"FH_VERIFY_API_KEY",
|
|
@@ -3311,6 +3314,37 @@ function googleInput(state) {
|
|
|
3311
3314
|
return Object.entries(state).map(([k, v]) => ({ type: "text", text: JSON.stringify({ [k]: v }) + "\n" }));
|
|
3312
3315
|
}
|
|
3313
3316
|
|
|
3317
|
+
// src/verify/liquid.ts
|
|
3318
|
+
var hosted = (baseUrl) => {
|
|
3319
|
+
try {
|
|
3320
|
+
return new URL(baseUrl).hostname === "api.liquid.ai";
|
|
3321
|
+
} catch {
|
|
3322
|
+
return false;
|
|
3323
|
+
}
|
|
3324
|
+
};
|
|
3325
|
+
var liquid = {
|
|
3326
|
+
name: "liquid",
|
|
3327
|
+
// d1-ultra (2026-11-16, claims.json, 3 rounds): 22/22, true claims ≥ 0.95, false ≤ 0.05, 1.7 s median;
|
|
3328
|
+
// d1.1 22/22 too but with less margin (≥ 0.89, ≤ 0.12), 0.5 s
|
|
3329
|
+
defaultModel: "d1-ultra",
|
|
3330
|
+
hostedUrl: "https://api.liquid.ai",
|
|
3331
|
+
keyPrefixes: ["liquid_"],
|
|
3332
|
+
modelPrefix: "d1",
|
|
3333
|
+
matches: (host3) => host3 === "api.liquid.ai",
|
|
3334
|
+
// Characters per window for the model's tokens, with room for the statement and
|
|
3335
|
+
// the question. A paper's Markdown can run under 2.75 characters a token
|
|
3336
|
+
// (2026-11-16: a 90,000-character window of pmid:18843650 went over d1-ultra's
|
|
3337
|
+
// 32,768), so 75,000 for 32k (d1-ultra; local, for -b/-ub 32768) and 150,000
|
|
3338
|
+
// for d1.1's 65k — both under the 250 KB text limit.
|
|
3339
|
+
windowChars: (baseUrl, model) => !hosted(baseUrl) || /^d1-ultra/.test(model) ? 75e3 : 15e4,
|
|
3340
|
+
request: ({ base_url, api_key, model, state, questions }) => ({
|
|
3341
|
+
url: `${base_url}${hosted(base_url) ? "/decisions" : ""}/v1/systemone`,
|
|
3342
|
+
// the Liquid API under /decisions, llama.cpp at the root
|
|
3343
|
+
headers: { "content-type": "application/json", ...api_key ? { authorization: `Bearer ${api_key}` } : {} },
|
|
3344
|
+
body: JSON.stringify({ model, state, questions })
|
|
3345
|
+
})
|
|
3346
|
+
};
|
|
3347
|
+
|
|
3314
3348
|
// src/verify/openai.ts
|
|
3315
3349
|
var openai = {
|
|
3316
3350
|
name: "openai",
|
|
@@ -3367,7 +3401,7 @@ var perplexity = {
|
|
|
3367
3401
|
};
|
|
3368
3402
|
|
|
3369
3403
|
// src/verify/providers.ts
|
|
3370
|
-
var PROVIDERS = [google, openai, perplexity];
|
|
3404
|
+
var PROVIDERS = [google, openai, liquid, perplexity];
|
|
3371
3405
|
var PROVIDER_NAMES = PROVIDERS.map((p) => p.name);
|
|
3372
3406
|
var providerByName = (name) => PROVIDERS.find((p) => p.name === name) ?? null;
|
|
3373
3407
|
var providerForKey = (key2) => PROVIDERS.find((p) => p.keyPrefixes.some((k) => key2.startsWith(k))) ?? null;
|
|
@@ -3580,7 +3614,7 @@ function publish() {
|
|
|
3580
3614
|
}
|
|
3581
3615
|
|
|
3582
3616
|
// src/tools.ts
|
|
3583
|
-
import { existsSync as
|
|
3617
|
+
import { existsSync as existsSync15, readFileSync as readFileSync13 } from "fs";
|
|
3584
3618
|
import { z } from "zod";
|
|
3585
3619
|
|
|
3586
3620
|
// src/cascade.ts
|
|
@@ -4051,7 +4085,7 @@ function decider(cfg, fetchFn = fetch) {
|
|
|
4051
4085
|
await new Promise((res) => setTimeout(res, RETRY_MS));
|
|
4052
4086
|
continue;
|
|
4053
4087
|
}
|
|
4054
|
-
throw new Error(msg ? `${cfg.model}: ${msg}` : `${cfg.model}: HTTP ${r.status} without an answer`);
|
|
4088
|
+
throw new Error(msg ? msg.startsWith(`${cfg.model}: `) ? msg : `${cfg.model}: ${msg}` : `${cfg.model}: HTTP ${r.status} without an answer`);
|
|
4055
4089
|
}
|
|
4056
4090
|
};
|
|
4057
4091
|
}
|
|
@@ -4788,17 +4822,48 @@ function paperYearOnly(md) {
|
|
|
4788
4822
|
});
|
|
4789
4823
|
}
|
|
4790
4824
|
function windows(md, max) {
|
|
4825
|
+
const secs = cleanMarkdown(md).split(/\n(?=#)/);
|
|
4826
|
+
const whole = secs.join("\n");
|
|
4827
|
+
if (whole.length <= max) return [whole];
|
|
4828
|
+
const title = secs[0]?.startsWith("# ") ? secs[0] : "";
|
|
4829
|
+
const abstract = secs.find((x) => /^#+\s*(abstract|summary)\b/i.test(x)) ?? "";
|
|
4830
|
+
const head = [title, abstract].filter((x, i, all) => x && all.indexOf(x) === i).join("\n").slice(0, Math.floor(max / 4));
|
|
4831
|
+
const room = max - (head ? head.length + 1 : 0);
|
|
4832
|
+
const pieces = secs.flatMap((x) => x.length <= room ? [x] : splitSection(x, room));
|
|
4791
4833
|
const out = [];
|
|
4792
4834
|
let cur = "";
|
|
4793
|
-
for (const
|
|
4794
|
-
if (cur && cur.length +
|
|
4835
|
+
for (const x of pieces) {
|
|
4836
|
+
if (cur && cur.length + x.length + 1 > room) {
|
|
4795
4837
|
out.push(cur);
|
|
4796
4838
|
cur = "";
|
|
4797
4839
|
}
|
|
4798
|
-
cur += (cur ? "\n" : "") +
|
|
4840
|
+
cur += (cur ? "\n" : "") + x;
|
|
4799
4841
|
}
|
|
4800
4842
|
if (cur) out.push(cur);
|
|
4801
|
-
return out.
|
|
4843
|
+
return out.map((w, i) => i > 0 && head ? `${head}
|
|
4844
|
+
${w}` : w);
|
|
4845
|
+
}
|
|
4846
|
+
function splitSection(section2, room) {
|
|
4847
|
+
const paras = section2.split(/\n{2,}/).flatMap((p) => {
|
|
4848
|
+
if (p.length <= room) return [p];
|
|
4849
|
+
const slices = [];
|
|
4850
|
+
const step = room - Math.min(500, Math.floor(room / 4));
|
|
4851
|
+
for (let i = 0; i < p.length; i += step) slices.push(p.slice(i, i + room));
|
|
4852
|
+
return slices;
|
|
4853
|
+
});
|
|
4854
|
+
const out = [];
|
|
4855
|
+
let cur = [];
|
|
4856
|
+
const len = (ps) => ps.reduce((n, p) => n + p.length + 2, 0);
|
|
4857
|
+
for (const p of paras) {
|
|
4858
|
+
if (cur.length && len(cur) + p.length > room) {
|
|
4859
|
+
out.push(cur.join("\n\n"));
|
|
4860
|
+
const last = cur[cur.length - 1];
|
|
4861
|
+
cur = last.length <= room / 4 && last.length + p.length + 2 <= room ? [last] : [];
|
|
4862
|
+
}
|
|
4863
|
+
cur.push(p);
|
|
4864
|
+
}
|
|
4865
|
+
if (cur.length) out.push(cur.join("\n\n"));
|
|
4866
|
+
return out;
|
|
4802
4867
|
}
|
|
4803
4868
|
var MONTH = /^(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|June?|July?|Aug(ust)?|Sep(t(ember)?)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)\.?$/;
|
|
4804
4869
|
var namesAuthor = (group) => (group.match(/\b[A-Z][\p{L}'’-]+/gu) ?? []).some((w) => !MONTH.test(w));
|
|
@@ -5206,6 +5271,84 @@ async function searchArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liv
|
|
|
5206
5271
|
return { ok: true, result, cached: false };
|
|
5207
5272
|
}
|
|
5208
5273
|
|
|
5274
|
+
// src/dailymedsearch.ts
|
|
5275
|
+
import { createHash as createHash6 } from "crypto";
|
|
5276
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync11 } from "fs";
|
|
5277
|
+
import { dirname as dirname7 } from "path";
|
|
5278
|
+
var MAX_RESULTS3 = 100;
|
|
5279
|
+
var DEFAULT_RESULTS3 = 20;
|
|
5280
|
+
var COLUMNS3 = ["set_id", "title", "labeler", "published", "version", "level"];
|
|
5281
|
+
var API3 = "https://dailymed.nlm.nih.gov/dailymed/services/v2/spls.json";
|
|
5282
|
+
var MONTHS2 = { Jan: "01", Feb: "02", Mar: "03", Apr: "04", May: "05", Jun: "06", Jul: "07", Aug: "08", Sep: "09", Oct: "10", Nov: "11", Dec: "12" };
|
|
5283
|
+
function normalizeQuery3(q) {
|
|
5284
|
+
const drug_name = (q.drug_name ?? "").replace(/\s+/g, " ").trim();
|
|
5285
|
+
if (!drug_name) return { error: "empty drug_name" };
|
|
5286
|
+
const labeler = (q.labeler ?? "").replace(/\s+/g, " ").trim();
|
|
5287
|
+
const out = { drug_name, max_results: Math.min(MAX_RESULTS3, Math.max(1, Math.floor(q.max_results ?? DEFAULT_RESULTS3))) };
|
|
5288
|
+
if (labeler) out.labeler = labeler;
|
|
5289
|
+
return out;
|
|
5290
|
+
}
|
|
5291
|
+
var searchKey3 = (q) => createHash6("sha1").update(JSON.stringify(["dailymed", q.drug_name.toLowerCase(), (q.labeler ?? "").toLowerCase(), q.max_results])).digest("hex").slice(0, 16);
|
|
5292
|
+
function searchUrl2(q) {
|
|
5293
|
+
const u = new URL(API3);
|
|
5294
|
+
u.searchParams.set("drug_name", q.drug_name);
|
|
5295
|
+
if (q.labeler) u.searchParams.set("labeler", q.labeler);
|
|
5296
|
+
u.searchParams.set("pagesize", String(q.max_results));
|
|
5297
|
+
return u.toString();
|
|
5298
|
+
}
|
|
5299
|
+
var isoDate2 = (d) => {
|
|
5300
|
+
const m = /^([A-Z][a-z]{2}) (\d{1,2}), (\d{4})$/.exec(String(d ?? "").trim());
|
|
5301
|
+
return m && MONTHS2[m[1]] ? `${m[3]}-${MONTHS2[m[1]]}-${m[2].padStart(2, "0")}` : null;
|
|
5302
|
+
};
|
|
5303
|
+
function splitTitle(t) {
|
|
5304
|
+
const m = /^(.*?)\s*\[([^\]]+)\]\s*$/.exec(t.trim());
|
|
5305
|
+
return m ? [m[1], m[2]] : [t.trim(), null];
|
|
5306
|
+
}
|
|
5307
|
+
function levelOf2(setid, libraryDir) {
|
|
5308
|
+
const paths = entryPaths(libraryDir, "dailymed", setid);
|
|
5309
|
+
return entryExists(paths) ? String(readStatus(paths, emptyStatus(`dailymed:${setid}`, "dailymed", setid, libraryDir)).level) : null;
|
|
5310
|
+
}
|
|
5311
|
+
function parseSearch(json2, libraryDir) {
|
|
5312
|
+
const d = JSON.parse(json2);
|
|
5313
|
+
const rows = [];
|
|
5314
|
+
for (const x of d.data ?? []) {
|
|
5315
|
+
if (!x.setid) continue;
|
|
5316
|
+
const [title, labeler] = splitTitle(String(x.title ?? ""));
|
|
5317
|
+
rows.push([x.setid, title, labeler, isoDate2(x.published_date), typeof x.spl_version === "number" ? x.spl_version : null, levelOf2(x.setid, libraryDir)]);
|
|
5318
|
+
}
|
|
5319
|
+
return { total: Number(d.metadata?.total_elements ?? rows.length) || rows.length, rows };
|
|
5320
|
+
}
|
|
5321
|
+
var live2 = (url) => fetchText(url, { "User-Agent": LIBRARY_UA, Accept: "application/json" });
|
|
5322
|
+
async function searchLabels(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = live2) {
|
|
5323
|
+
const q = normalizeQuery3(raw);
|
|
5324
|
+
if ("error" in q) return { ok: false, error: q.error };
|
|
5325
|
+
const file3 = searchFile(libraryDir, searchKey3(q));
|
|
5326
|
+
if (existsSync13(file3)) {
|
|
5327
|
+
try {
|
|
5328
|
+
const r = JSON.parse(readFileSync11(file3, "utf8"));
|
|
5329
|
+
if (daysSince(r.searched) < searchCacheDays()) return { ok: true, result: { ...r, rows: r.rows.map((row3) => {
|
|
5330
|
+
const c = [...row3];
|
|
5331
|
+
c[5] = levelOf2(row3[0], libraryDir);
|
|
5332
|
+
return c;
|
|
5333
|
+
}) }, cached: true };
|
|
5334
|
+
} catch {
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
let parsed;
|
|
5338
|
+
try {
|
|
5339
|
+
parsed = parseSearch(await fetchImpl(searchUrl2(q)), libraryDir);
|
|
5340
|
+
} catch (e) {
|
|
5341
|
+
return { ok: false, error: `dailymed: ${e instanceof Error ? e.message : String(e)}` };
|
|
5342
|
+
}
|
|
5343
|
+
const result = { source: "dailymed", query: q, total: parsed.total, columns: COLUMNS3, rows: parsed.rows, searched: today() };
|
|
5344
|
+
try {
|
|
5345
|
+
mkdirSync10(dirname7(file3), { recursive: true });
|
|
5346
|
+
writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
|
|
5347
|
+
} catch {
|
|
5348
|
+
}
|
|
5349
|
+
return { ok: true, result, cached: false };
|
|
5350
|
+
}
|
|
5351
|
+
|
|
5209
5352
|
// src/trialrecord.ts
|
|
5210
5353
|
var list4 = (a) => Array.isArray(a) ? a : [];
|
|
5211
5354
|
var para2 = (s, max = Infinity) => {
|
|
@@ -5323,13 +5466,13 @@ function resultsText(nct, md, maxChars) {
|
|
|
5323
5466
|
}
|
|
5324
5467
|
|
|
5325
5468
|
// src/missing.ts
|
|
5326
|
-
import { existsSync as
|
|
5469
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync11, readFileSync as readFileSync12 } from "fs";
|
|
5327
5470
|
import { join as join12 } from "path";
|
|
5328
5471
|
var missingFile = (p) => join12(p.entryDir, `${p.entry}-missing.md`);
|
|
5329
5472
|
function readMissing(p) {
|
|
5330
5473
|
const f = missingFile(p);
|
|
5331
|
-
if (!
|
|
5332
|
-
const md =
|
|
5474
|
+
if (!existsSync14(f)) return null;
|
|
5475
|
+
const md = readFileSync12(f, "utf8");
|
|
5333
5476
|
const get4 = (k) => /^$/.test(k) ? "" : (new RegExp(`^${k}:[ \\t]*(.*)$`, "m").exec(md)?.[1] ?? "").trim();
|
|
5334
5477
|
const checked = get4("checked"), reason = get4("reason");
|
|
5335
5478
|
return checked ? { checked, reason: reason || "not found" } : null;
|
|
@@ -5340,7 +5483,7 @@ function freshMissing(p, retryDays) {
|
|
|
5340
5483
|
}
|
|
5341
5484
|
function rememberMissing(p, reason) {
|
|
5342
5485
|
const m = { checked: now(), reason };
|
|
5343
|
-
|
|
5486
|
+
mkdirSync11(p.entryDir, { recursive: true });
|
|
5344
5487
|
writeAtomic(missingFile(p), `checked: ${m.checked}
|
|
5345
5488
|
reason: ${m.reason}
|
|
5346
5489
|
`);
|
|
@@ -5350,7 +5493,7 @@ var missingNote = (m, retryDays) => `${m.reason} (checked ${m.checked.slice(0, 1
|
|
|
5350
5493
|
|
|
5351
5494
|
// src/pubmedbatch.ts
|
|
5352
5495
|
var MAX_PMIDS = 200;
|
|
5353
|
-
var
|
|
5496
|
+
var COLUMNS4 = ["pmid", "title", "first_author", "year", "publication_types", "retracted", "level"];
|
|
5354
5497
|
var EFETCH2 = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi";
|
|
5355
5498
|
function efetchBatchUrl(pmids) {
|
|
5356
5499
|
const u = new URL(EFETCH2);
|
|
@@ -5374,7 +5517,7 @@ function splitArticles(xml) {
|
|
|
5374
5517
|
}
|
|
5375
5518
|
var row2 = (pmid, s, level) => s ? [pmid, s.title ? s.title.replace(/\.$/, "") : s.title, s.first_author, s.year, reviewTypes(s.publication_types).join("; ") || null, s.retracted, level] : [pmid, null, null, null, null, null, level];
|
|
5376
5519
|
async function fetchArticles(ids, libraryDir = FH_EVIDENCE_DIR, converter = "evidence-mcp", fetchImpl = fetchText) {
|
|
5377
|
-
const result = { columns:
|
|
5520
|
+
const result = { columns: COLUMNS4, rows: [], new: 0, cached: 0, not_found: 0, invalid: 0, asked: 0 };
|
|
5378
5521
|
const order2 = [];
|
|
5379
5522
|
const invalid = /* @__PURE__ */ new Map();
|
|
5380
5523
|
for (const raw of ids.slice(0, MAX_PMIDS)) {
|
|
@@ -5436,7 +5579,7 @@ async function fetchArticles(ids, libraryDir = FH_EVIDENCE_DIR, converter = "evi
|
|
|
5436
5579
|
// src/tools.ts
|
|
5437
5580
|
var pkg = (() => {
|
|
5438
5581
|
try {
|
|
5439
|
-
return JSON.parse(
|
|
5582
|
+
return JSON.parse(readFileSync13(new URL("../package.json", import.meta.url), "utf8"));
|
|
5440
5583
|
} catch {
|
|
5441
5584
|
return { name: "evidence-mcp", version: "0.0.0" };
|
|
5442
5585
|
}
|
|
@@ -5446,7 +5589,7 @@ var INSTRUCTIONS = `evidence-mcp keeps a local library of scientific papers, FDA
|
|
|
5446
5589
|
IDs \u2014 always "type:value"
|
|
5447
5590
|
- pmid:30955454 \u2014 a paper by PubMed ID. Bare digits are taken as a PMID.
|
|
5448
5591
|
- doi:10.\u2026 \u2014 a paper by DOI. A DOI PubMed indexes is stored under its PMID; any other gets its record from Crossref.
|
|
5449
|
-
- dailymed:<set ID> \u2014 an FDA prescribing-information label, current version. The set ID is the "setid=" value in the label's DailyMed URL.
|
|
5592
|
+
- 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.
|
|
5450
5593
|
- nct:05173896 \u2014 a ClinicalTrials.gov trial record, current version. NCT05173896 is accepted too.
|
|
5451
5594
|
|
|
5452
5595
|
Tools
|
|
@@ -5458,6 +5601,7 @@ Tools
|
|
|
5458
5601
|
- 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.
|
|
5459
5602
|
- 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.
|
|
5460
5603
|
- 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.
|
|
5604
|
+
- 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.
|
|
5461
5605
|
- 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.
|
|
5462
5606
|
- 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.
|
|
5463
5607
|
- fh_fetch_url(url, max_length?, start_index?, raw?, title_only?) \u2014 a web page as Markdown, same call and same answer as the standard fetch tool ("Contents of <url>:" and the page, cut at max_length with a note on how to continue). Prefer it for every URL: a cached page answers from disk, a walled or script-rendered page runs through the browser and unlocker stages in one call. PDFs as Markdown; XML, JSON and other text as is. title_only returns the title line alone \u2014 enough to verify a link, at a few tokens.
|
|
@@ -5831,8 +5975,8 @@ function registerTools(server2) {
|
|
|
5831
5975
|
}
|
|
5832
5976
|
added = true;
|
|
5833
5977
|
}
|
|
5834
|
-
const full =
|
|
5835
|
-
const md =
|
|
5978
|
+
const full = existsSync15(paths.fulltextMd);
|
|
5979
|
+
const md = readFileSync13(full ? paths.fulltextMd : paths.md, "utf8");
|
|
5836
5980
|
const text4 = full ? "full_text" : "abstract";
|
|
5837
5981
|
const base = added ? { requested: parsed.requested, entry: paths.entry, text: text4, added: true } : { requested: parsed.requested, entry: paths.entry, text: text4 };
|
|
5838
5982
|
const headings2 = () => outline(md, text4).sections;
|
|
@@ -5852,8 +5996,8 @@ function registerTools(server2) {
|
|
|
5852
5996
|
const cap = max_chars ?? 6e3;
|
|
5853
5997
|
let sec = readSection(md, section2, cap);
|
|
5854
5998
|
let via = "";
|
|
5855
|
-
if (!sec && /abstract/i.test(section2) && full &&
|
|
5856
|
-
sec = readSection(
|
|
5999
|
+
if (!sec && /abstract/i.test(section2) && full && existsSync15(paths.md)) {
|
|
6000
|
+
sec = readSection(readFileSync13(paths.md, "utf8"), "abstract", cap);
|
|
5857
6001
|
via = " (from the abstract file)";
|
|
5858
6002
|
}
|
|
5859
6003
|
if (!sec && /declaration/i.test(section2)) {
|
|
@@ -5982,8 +6126,8 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
|
|
|
5982
6126
|
return { content: [{ type: "text", text: `Failed to fetch ${url}: ${added.error}` }], isError: true };
|
|
5983
6127
|
}
|
|
5984
6128
|
}
|
|
5985
|
-
const file3 = pid.type === "pmid" ? paths.md :
|
|
5986
|
-
const md =
|
|
6129
|
+
const file3 = pid.type === "pmid" ? paths.md : existsSync15(paths.fulltextMd) ? paths.fulltextMd : paths.md;
|
|
6130
|
+
const md = existsSync15(file3) ? readFileSync13(file3, "utf8") : "";
|
|
5987
6131
|
const text4 = title_only ? `Contents of ${url}:
|
|
5988
6132
|
${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "", max_length, start_index);
|
|
5989
6133
|
bump("fetch", had);
|
|
@@ -6067,6 +6211,28 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6067
6211
|
return { content: [{ type: "text", text: searchAnswer(r.result) }] };
|
|
6068
6212
|
}
|
|
6069
6213
|
);
|
|
6214
|
+
server2.tool(
|
|
6215
|
+
"fh_dailymed_search_labels",
|
|
6216
|
+
`Find FDA drug labels on DailyMed by drug name, generic or brand: the total and up to ${MAX_RESULTS3} rows as arrays in columns order \u2014 set ID, title (drug and form), labeler (the company), published date, version, and the library level when the label is already stored. Newest first. A generic name lists every maker's label; labeler narrows to one company ("Boehringer" for Micardis's maker), a brand name to its own labels. Pass the set ID as "dailymed:<set ID>" to fh_library_read or fh_library_add. Use this, not DailyMed's search page: fetched as Markdown the page shows no set IDs, raw it is some 150,000 characters. The same search is answered from disk for ${searchCacheDays()} days.`,
|
|
6217
|
+
{
|
|
6218
|
+
drug_name: z.string().describe('Generic or brand name: "telmisartan", "Micardis".'),
|
|
6219
|
+
labeler: z.string().optional().describe(`Part of the company's name, to narrow to its labels: "Boehringer".`),
|
|
6220
|
+
max_results: z.number().int().min(1).max(MAX_RESULTS3).default(20).describe("Rows to return (1\u2013100).")
|
|
6221
|
+
},
|
|
6222
|
+
async (args) => {
|
|
6223
|
+
const t0 = Date.now();
|
|
6224
|
+
const r = await searchLabels(args, FH_EVIDENCE_DIR);
|
|
6225
|
+
const secs = ((Date.now() - t0) / 1e3).toFixed(1).padStart(4, "0") + "s";
|
|
6226
|
+
if (!r.ok) {
|
|
6227
|
+
log("search", "dailymed", `error: ${r.error}`);
|
|
6228
|
+
return { content: [{ type: "text", text: compact2({ error: r.error }) }], isError: true };
|
|
6229
|
+
}
|
|
6230
|
+
bump("search", r.cached);
|
|
6231
|
+
const q = r.result.query;
|
|
6232
|
+
log("search", "dailymed", `ok ${r.cached ? "cached" : secs} rows=${r.result.rows.length} total=${r.result.total} | ${q.drug_name}${q.labeler ? ` labeler=${q.labeler}` : ""}`);
|
|
6233
|
+
return { content: [{ type: "text", text: searchAnswer(r.result) }] };
|
|
6234
|
+
}
|
|
6235
|
+
);
|
|
6070
6236
|
const nctEntry = async (id) => {
|
|
6071
6237
|
const p = parseId(/^\d{8}$/.test(id.trim()) ? `nct:${id.trim()}` : id);
|
|
6072
6238
|
if (p.error) return { error: p.error };
|
|
@@ -6092,7 +6258,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6092
6258
|
return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
|
|
6093
6259
|
}
|
|
6094
6260
|
const raw = e.paths.fulltextRaw("json");
|
|
6095
|
-
const r =
|
|
6261
|
+
const r = existsSync15(raw) ? recordSummary(readFileSync13(raw, "utf8")) : null;
|
|
6096
6262
|
if (!r) {
|
|
6097
6263
|
log("trials", e.requested, "record error: no stored record");
|
|
6098
6264
|
return { content: [{ type: "text", text: compact2({ error: "no stored record" }) }], isError: true };
|
|
@@ -6111,7 +6277,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6111
6277
|
log("trials", nct, `results error: ${e.error}`);
|
|
6112
6278
|
return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
|
|
6113
6279
|
}
|
|
6114
|
-
const md =
|
|
6280
|
+
const md = existsSync15(e.paths.fulltextMd) ? readFileSync13(e.paths.fulltextMd, "utf8") : "";
|
|
6115
6281
|
const r = resultsText(e.requested.replace(/^nct:/, "NCT"), md, max_chars);
|
|
6116
6282
|
log("trials", e.requested, `results ${r.has_results ? `${r.outcomes.length} outcomes${r.truncated ? " truncated" : ""}` : "none"}`);
|
|
6117
6283
|
return { content: [{ type: "text", text: leanJson(r) }] };
|