evidence-mcp-dev 1.0.9 → 1.0.10
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 +24 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3247,6 +3247,7 @@ var VARIABLES = [
|
|
|
3247
3247
|
"FH_SEARCH_CACHE_DAYS",
|
|
3248
3248
|
"FH_NCBI_API_KEY",
|
|
3249
3249
|
"FH_EXA_API_KEY",
|
|
3250
|
+
"FH_WEB_SEARCH_SNIPPETS",
|
|
3250
3251
|
"FH_ZENROWS_API_KEY",
|
|
3251
3252
|
"FH_ZYTE_API_KEY",
|
|
3252
3253
|
"FH_BRIGHTDATA_API_KEY",
|
|
@@ -3857,7 +3858,21 @@ async function searchTrials(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liveF
|
|
|
3857
3858
|
// src/websearch.ts
|
|
3858
3859
|
var MAX_RESULTS2 = 25;
|
|
3859
3860
|
var DEFAULT_RESULTS2 = 10;
|
|
3860
|
-
var COLUMNS2 = ["title", "url", "published", "author"];
|
|
3861
|
+
var COLUMNS2 = ["title", "url", "published", "author", "snippet"];
|
|
3862
|
+
var snippetMode = (env = process.env) => {
|
|
3863
|
+
const v = (env.FH_WEB_SEARCH_SNIPPETS ?? "").trim().toLowerCase();
|
|
3864
|
+
return v === "summary" || v === "off" ? v : "highlights";
|
|
3865
|
+
};
|
|
3866
|
+
var SNIPPET_CHARS = 220;
|
|
3867
|
+
function cleanSnippet(t) {
|
|
3868
|
+
let s = (t ?? "").replace(/\s+/g, " ").trim();
|
|
3869
|
+
s = s.replace(/^(?:[#•*\-\s]*(?:last updated|updated|published|written by|reviewed by|by)\b[^.]*?(?:\d{4}|others)\s*)+/i, "").trim();
|
|
3870
|
+
s = s.replace(/^#+\s*/, "");
|
|
3871
|
+
if (!s) return null;
|
|
3872
|
+
if (s.length <= SNIPPET_CHARS) return s;
|
|
3873
|
+
const cut = s.slice(0, SNIPPET_CHARS);
|
|
3874
|
+
return cut.slice(0, Math.max(cut.lastIndexOf(" "), SNIPPET_CHARS - 40)).replace(/[,;:\s]+$/, "") + " \u2026";
|
|
3875
|
+
}
|
|
3861
3876
|
var webSearchKey = (env = process.env) => env.FH_EXA_API_KEY?.trim() || null;
|
|
3862
3877
|
var webSearchConfigured = (env = process.env) => !!webSearchKey(env);
|
|
3863
3878
|
function siteDomain(site) {
|
|
@@ -3885,14 +3900,15 @@ function normalizeQuery2(q) {
|
|
|
3885
3900
|
if (sites.length) out.sites = sites;
|
|
3886
3901
|
return out;
|
|
3887
3902
|
}
|
|
3888
|
-
var searchKey2 = (q) => createHash3("sha1").update(JSON.stringify(["web", "exa", q.query.toLowerCase(), q.sites ?? [], q.max_results])).digest("hex").slice(0, 16);
|
|
3903
|
+
var searchKey2 = (q, mode = snippetMode()) => createHash3("sha1").update(JSON.stringify(["web", "exa", mode, q.query.toLowerCase(), q.sites ?? [], q.max_results])).digest("hex").slice(0, 16);
|
|
3889
3904
|
function parseExa(json2) {
|
|
3890
3905
|
const d = JSON.parse(json2);
|
|
3891
3906
|
return (d.results ?? []).filter((x) => x.url).map((x) => [
|
|
3892
3907
|
(x.title ?? "").replace(/\s+/g, " ").trim(),
|
|
3893
3908
|
x.url,
|
|
3894
3909
|
x.publishedDate ? x.publishedDate.slice(0, 10) : null,
|
|
3895
|
-
x.author ? x.author.replace(/\s+/g, " ").trim() : null
|
|
3910
|
+
x.author ? x.author.replace(/\s+/g, " ").trim() : null,
|
|
3911
|
+
cleanSnippet(x.summary ?? x.highlights?.[0])
|
|
3896
3912
|
]);
|
|
3897
3913
|
}
|
|
3898
3914
|
var live = async (url, body, headers) => {
|
|
@@ -3923,7 +3939,9 @@ async function webSearch(raw, libraryDir = FH_EVIDENCE_DIR, post2 = live, key2 =
|
|
|
3923
3939
|
}
|
|
3924
3940
|
let rows;
|
|
3925
3941
|
try {
|
|
3926
|
-
|
|
3942
|
+
const mode = snippetMode();
|
|
3943
|
+
const contents = mode === "highlights" ? { highlights: { query: q.query, numSentences: 2, highlightsPerUrl: 1 } } : mode === "summary" ? { summary: { query: `In one sentence, what does this page say about ${q.query}?` } } : void 0;
|
|
3944
|
+
rows = parseExa(await post2("https://api.exa.ai/search", { query: q.query, numResults: q.max_results, ...q.sites ? { includeDomains: q.sites } : {}, ...contents ? { contents } : {} }, { "x-api-key": key2 }));
|
|
3927
3945
|
} catch (e) {
|
|
3928
3946
|
return { ok: false, error: `exa: ${e instanceof Error ? e.message : String(e)}` };
|
|
3929
3947
|
}
|
|
@@ -5695,7 +5713,7 @@ Tools
|
|
|
5695
5713
|
- 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.
|
|
5696
5714
|
- 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.
|
|
5697
5715
|
- 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.
|
|
5698
|
-
${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), not 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. 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.
|
|
5716
|
+
${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. 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.
|
|
5699
5717
|
- 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.
|
|
5700
5718
|
- 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.
|
|
5701
5719
|
|
|
@@ -6306,7 +6324,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
|
|
|
6306
6324
|
);
|
|
6307
6325
|
if (webSearchConfigured()) server2.tool(
|
|
6308
6326
|
"fh_web_search",
|
|
6309
|
-
`Search the web \u2014 use it instead of the built-in web search. It returns links (title, URL, date, author), not page text, so it costs a fraction of the context; read a result with fh_fetch_url. It finds more, especially within one site: restrict it with site: in the query, as with any search engine ("metformin site:nih.gov", several with "(site:nih.gov OR site:who.int)"), a restriction the built-in search often ignores. Searches are cached locally for ${searchCacheDays()} days; a repeated search is answered in milliseconds.`,
|
|
6327
|
+
`Search the web \u2014 use it instead of the built-in web search. It returns links (title, URL, date, author) with a short passage from each page, not the page text, so it costs a fraction of the context; read a result with fh_fetch_url. It finds more, especially within one site: restrict it with site: in the query, as with any search engine ("metformin site:nih.gov", several with "(site:nih.gov OR site:who.int)"), a restriction the built-in search often ignores. Searches are cached locally for ${searchCacheDays()} days; a repeated search is answered in milliseconds.`,
|
|
6310
6328
|
{
|
|
6311
6329
|
query: z.string().describe('The query, site: terms included: "metformin site:nih.gov", "statin muscle pain".'),
|
|
6312
6330
|
max_results: z.number().int().min(1).max(MAX_RESULTS2).default(10).describe("Rows to return (1\u201325).")
|