medical-terminologies-mcp 4.3.3 → 4.4.0

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 +138 -49
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ function unknownCursorError(message) {
30
30
  var package_default = {
31
31
  name: "medical-terminologies-mcp",
32
32
  mcpName: "io.github.SidneyBissoli/medical-terminologies-mcp",
33
- version: "4.3.3",
33
+ version: "4.4.0",
34
34
  description: "Unified MCP server for seven medical terminologies (ICD-11, ICF, LOINC, RxNorm, MeSH, ATC, CID-10) with authoritative WHO ICD-10\u2192ICD-11 mapping. 37 tools, hosted endpoint available, MIT.",
35
35
  author: "Sidney da Silva Pereira Bissoli",
36
36
  license: "MIT",
@@ -98,9 +98,10 @@ var package_default = {
98
98
  },
99
99
  devDependencies: {
100
100
  "@modelcontextprotocol/client": "^2.0.0",
101
- "@sbissoli/mcp-evals": "^0.2.1",
101
+ "@sbissoli/mcp-evals": "^0.3.0",
102
102
  "@sbissoli/mcp-live-source": "^0.5.0",
103
103
  "@sbissoli/mcp-surface": "^0.6.0",
104
+ "@sbissoli/mcp-tool-tests": "^0.2.0",
104
105
  "@types/node": "^26.5.1",
105
106
  esbuild: "^0.28.2",
106
107
  nock: "^15.0.1",
@@ -548,7 +549,17 @@ var lenientBoolean = z.union([
548
549
  var RxCUISchema = numericIdSchema("RxCUI");
549
550
  var LOINCNumberSchema = z.string().regex(/^\d{1,5}-\d$/, 'Invalid LOINC number; expected format like "2339-0"');
550
551
  var MeSHIdSchema = z.string().regex(/^D\d+$/, 'Invalid MeSH descriptor ID; expected "D" followed by digits (e.g., D015242)');
551
- var maxResults = (defaultValue) => z.number().int().min(1).max(100).optional().default(defaultValue).describe(`Maximum number of results (1-100). Default: ${defaultValue}`);
552
+ var maxResults = (defaultValue, max = 100) => z.number().int().min(1).max(max).optional().default(defaultValue).describe(`Maximum number of results (1-${max}). Default: ${defaultValue}`);
553
+ var offsetParam = (max) => {
554
+ const base = z.number().int().min(0);
555
+ return (max === void 0 ? base : base.max(max)).optional().default(0).describe(
556
+ "Number of results to skip, to read the next page: pass `next_offset` from the previous answer, keeping the other arguments. Default: 0" + (max === void 0 ? "" : ` (at most ${max}: the source serves at most the first ${max + 100} results)`)
557
+ );
558
+ };
559
+ var LOINC_MAX_OFFSET = 7400;
560
+ var offsetOut = z.number().int().describe("Results skipped before the first one returned (the `offset` asked for).");
561
+ var nextOffsetOut = z.number().int().nullable().describe("`offset` that returns the next page with the same arguments; null when this page reaches the end of the results.");
562
+ var nextOffset = (offset, shown, total) => shown > 0 && offset + shown < total ? offset + shown : null;
552
563
  var withinSchema = (what) => z.array(z.string().trim().min(1)).min(1).max(10).optional().describe(what);
553
564
  var WithinBranchSchema = z.object({
554
565
  value: z.string().describe("The branch as sent in `within`."),
@@ -560,6 +571,7 @@ var ICD11SearchParamsSchema = z.object({
560
571
  query: z.string().min(1).describe("Search text (disease name, symptom, or keyword)"),
561
572
  language: SupportedLanguageSchema.optional().default("en"),
562
573
  max_results: maxResults(25),
574
+ offset: offsetParam(),
563
575
  within: withinSchema(
564
576
  'Only search these branches of ICD-11 and their descendants (up to 10): a chapter number ("06", "V"), a block range ("5A10-5A14"), a category code ("5A11") or an entity URI. Uses the WHO search subtree filter. A branch that does not exist is an error, never a silent unbounded search.'
565
577
  )
@@ -595,6 +607,8 @@ var ICD11SearchOutputSchema = z.object({
595
607
  query: z.string().describe("The search text as submitted."),
596
608
  within: z.array(WithinBranchSchema).describe("The branches that bounded the search, resolved at the WHO; empty when the search was unbounded."),
597
609
  total_count: z.number().int().describe("Number of entities the WHO search returned, before the max_results cap."),
610
+ offset: offsetOut,
611
+ next_offset: nextOffsetOut,
598
612
  entities: z.array(
599
613
  z.object({
600
614
  code: z.string().nullable(),
@@ -604,7 +618,7 @@ var ICD11SearchOutputSchema = z.object({
604
618
  is_leaf: z.boolean(),
605
619
  matching_pvs: z.array(ICD11MatchingPVSchema)
606
620
  })
607
- ).describe("Matching ICD-11 MMS entities in WHO relevance order, at most max_results.")
621
+ ).describe("Matching ICD-11 MMS entities in WHO relevance order, at most max_results, starting after `offset`.")
608
622
  });
609
623
  var ICD11LabelRefSchema = z.object({
610
624
  uri: z.string().describe("URI of the entity this term comes from: the referenced entity when the WHO names one (release URI, else foundation URI), otherwise the entity being looked up itself \u2014 which is the case for most inclusions and index terms."),
@@ -669,6 +683,7 @@ var ICFSearchParamsSchema = z.object({
669
683
  query: z.string().min(1).describe('Search text (a function, activity, body structure or environmental factor, e.g. "walking")'),
670
684
  language: SupportedLanguageSchema.optional().default("en"),
671
685
  max_results: maxResults(25),
686
+ offset: offsetParam(),
672
687
  within: withinSchema(
673
688
  'Only search these branches of ICF and their descendants (up to 10): a category code ("d450", "b280") or an ICF entity URI. Uses the WHO search subtree filter. A branch that does not exist is an error, never a silent unbounded search.'
674
689
  )
@@ -688,6 +703,8 @@ var ICFSearchOutputSchema = z.object({
688
703
  query: z.string().describe("The search text as submitted."),
689
704
  within: z.array(WithinBranchSchema).describe("The branches that bounded the search, resolved at the WHO; empty when the search was unbounded."),
690
705
  total_count: z.number().int().describe("Number of entities the WHO search returned, before the max_results cap."),
706
+ offset: offsetOut,
707
+ next_offset: nextOffsetOut,
691
708
  entities: z.array(
692
709
  z.object({
693
710
  code: z.string().nullable().describe('ICF code (e.g. "d450"); null for entries without a code.'),
@@ -697,7 +714,7 @@ var ICFSearchOutputSchema = z.object({
697
714
  uri: z.string().describe("WHO ICF entity URI; pass it to icf_lookup."),
698
715
  is_leaf: z.boolean().describe("True when the category has no subcategories.")
699
716
  })
700
- ).describe("Matching ICF entities in WHO relevance order, at most max_results.")
717
+ ).describe("Matching ICF entities in WHO relevance order, at most max_results, starting after `offset`.")
701
718
  });
702
719
  var ICFLookupOutputSchema = z.object({
703
720
  code: z.string().nullable().describe('ICF code (e.g. "d450"); null for chapters and blocks, which have a code_range instead.'),
@@ -713,7 +730,8 @@ var ICFLookupOutputSchema = z.object({
713
730
  });
714
731
  var LOINCSearchParamsSchema = z.object({
715
732
  query: z.string().min(1).describe("Search term (test name, keyword, or partial LOINC code)"),
716
- max_results: maxResults(25)
733
+ max_results: maxResults(25),
734
+ offset: offsetParam(LOINC_MAX_OFFSET)
717
735
  }).strict();
718
736
  var LOINCByCodeParamsSchema = z.object({
719
737
  loinc_num: LOINCNumberSchema.describe('LOINC number (e.g., "2339-0")')
@@ -740,7 +758,9 @@ var LOINCSearchOutputSchema = z.object({
740
758
  query: z.string().describe("The search term as submitted."),
741
759
  total_count: z.number().int().describe("Total number of LOINC terms matching the query at the source, which may exceed the items returned."),
742
760
  shown_count: z.number().int().describe("Number of terms returned in items (at most max_results)."),
743
- items: z.array(LOINCItemOutputSchema).describe("Matching LOINC terms in source relevance order.")
761
+ offset: offsetOut,
762
+ next_offset: nextOffsetOut.describe("`offset` that returns the next page with the same arguments; null at the end of the results, or past the first 7,500 (the most the source serves)."),
763
+ items: z.array(LOINCItemOutputSchema).describe("Matching LOINC terms in source relevance order, starting after `offset`.")
744
764
  });
745
765
  var LOINCDetailsOutputSchema = LOINCItemOutputSchema;
746
766
  var LOINCAnswersOutputSchema = z.object({
@@ -772,7 +792,8 @@ var LOINCPanelsOutputSchema = z.object({
772
792
  });
773
793
  var RxNormSearchParamsSchema = z.object({
774
794
  query: z.string().min(1).describe("Drug name to search (brand or generic)"),
775
- max_results: maxResults(25)
795
+ max_results: maxResults(25),
796
+ offset: offsetParam()
776
797
  }).strict();
777
798
  var RxNormConceptParamsSchema = z.object({
778
799
  rxcui: RxCUISchema.describe('RxNorm Concept Unique Identifier (string of digits or integer, e.g. "161" or 161)'),
@@ -796,10 +817,12 @@ var RxNormDrugOutputSchema = z.object({
796
817
  });
797
818
  var RxNormSearchOutputSchema = z.object({
798
819
  query: z.string().describe("The drug name as submitted."),
799
- total_count: z.number().int().describe("Number of concepts RxNav returned for the name, before the max_results cap."),
820
+ total_count: z.number().int().describe("Number of distinct concepts RxNav returned for the name, before the max_results cap."),
821
+ offset: offsetOut,
822
+ next_offset: nextOffsetOut,
800
823
  // tty === 'APPROX' on items signals the search used the approximate-match
801
824
  // fallback rather than an exact name match.
802
- drugs: z.array(RxNormDrugOutputSchema).describe('Matching RxNorm concepts, at most max_results. tty "APPROX" marks results of the approximate-match fallback, used when the name matched nothing exactly.')
825
+ drugs: z.array(RxNormDrugOutputSchema).describe('Matching RxNorm concepts, at most max_results, starting after `offset`. tty "APPROX" marks results of the approximate-match fallback, used when the name matched nothing exactly.')
803
826
  });
804
827
  var RxNormConceptOutputSchema = z.object({
805
828
  rxcui: z.string().describe("The RxCUI looked up."),
@@ -863,8 +886,15 @@ var MeSHSearchParamsSchema = z.object({
863
886
  language: SupportedLanguageSchema.optional().default("en").describe(
864
887
  "Language code (default: en). MeSH is published by NLM in English; another language is returned only where the NLM record carries it (rare), otherwise English. Never machine-translated."
865
888
  ),
866
- max_results: maxResults(25)
889
+ // The NLM lookup refuses limit > 50 with HTTP 400 ("must be less than or
890
+ // equal to 50", measured 2026-12-02): 51-100 used to fail at the source.
891
+ // The schema keeps 1-100 (narrowing it would break the declared surface);
892
+ // the handler asks for at most MESH_SOURCE_LIMIT and SAYS so.
893
+ max_results: maxResults(25).describe(
894
+ `Maximum number of results (1-100). Default: 25. The NLM lookup returns at most 50: above 50, 50 are asked for and the answer says so.`
895
+ )
867
896
  }).strict();
897
+ var MESH_SOURCE_LIMIT = 50;
868
898
  var MeSHByIdParamsSchema = z.object({
869
899
  mesh_id: MeSHIdSchema.describe("MeSH Descriptor ID (e.g., D015242, D003920)")
870
900
  }).strict();
@@ -886,7 +916,7 @@ var MeSHQualifierOutputSchema = z.object({
886
916
  var MeSHSearchOutputSchema = z.object({
887
917
  query: z.string().describe("The search term as submitted."),
888
918
  match: z.enum(["exact", "contains", "startswith"]).describe("Match type applied to descriptor labels."),
889
- total_count: z.number().int().describe("Number of descriptors returned (the NLM lookup is capped at max_results, so this is not a total count of all matches)."),
919
+ total_count: z.number().int().describe("Number of descriptors returned. The NLM lookup stops at max_results and has no offset, so this is not a count of all matches and there is no next page: when it equals max_results, narrow the query or use `match`."),
890
920
  matched_via: z.enum(["descriptor_label", "entry_term"]).describe('descriptor_label = the query matched descriptor labels; entry_term = no label matched, so the descriptors were reached through MeSH entry terms (synonyms such as "Heart Attack" for Myocardial Infarction).'),
891
921
  descriptors: z.array(
892
922
  z.object({
@@ -1360,6 +1390,7 @@ var CID10SearchParamsSchema = z.object({
1360
1390
  "Restrict search to 3-char categories, 4-char subcategories, or both. Default: all"
1361
1391
  ),
1362
1392
  max_results: maxResults(25),
1393
+ offset: offsetParam(),
1363
1394
  within: withinSchema(
1364
1395
  'Only search these branches of CID-10 (up to 10): a chapter number ("5" = F00-F99), a range of categories ("F30-F39"; both ends must exist) or a category / subcategory code ("F32", "F32.1" \u2014 a category keeps its subcategories). A branch that does not exist is an error, never a silent unbounded search.'
1365
1396
  )
@@ -1407,6 +1438,8 @@ var CID10SearchOutputSchema = z.object({
1407
1438
  within: z.array(WithinBranchSchema).describe("The branches that bounded the search, resolved in the bundled dataset (uri is always null); empty when the search was unbounded."),
1408
1439
  total_count: z.number().int().describe("Number of CID-10 codes matching the query, before the max_results cap."),
1409
1440
  shown_count: z.number().int().describe("Number of codes returned in hits (at most max_results)."),
1441
+ offset: offsetOut,
1442
+ next_offset: nextOffsetOut,
1410
1443
  hits: z.array(CID10HitSchema).describe("Matching CID-10 V2008 codes with their Portuguese titles, chapter and group."),
1411
1444
  // Present only when a query word was translated to the CID-10's own wording
1412
1445
  // ("câncer" → "neoplasia maligna"); says which (src/clients/cid10-vocabulary.ts).
@@ -2327,6 +2360,20 @@ function getWHOClient() {
2327
2360
  return whoClientInstance;
2328
2361
  }
2329
2362
 
2363
+ // src/utils/page.ts
2364
+ function showingRange(offset, shown) {
2365
+ return offset === 0 ? `top ${shown}` : `${offset + 1}\u2013${offset + shown}`;
2366
+ }
2367
+ function nextPageLine(offset, shown, total, next) {
2368
+ if (next === null) return "";
2369
+ return `
2370
+
2371
+ _Showing results ${offset + 1}\u2013${offset + shown} of ${total}. Next page: call again with \`offset: ${next}\`._`;
2372
+ }
2373
+ function pastTheEndText(query, system, offset, total) {
2374
+ return `No results at offset ${offset} for "${query}" in ${system}: the search matched ${total}, so the last page starts before offset ${total}.`;
2375
+ }
2376
+
2330
2377
  // src/provenance.ts
2331
2378
  import { z as z3 } from "zod";
2332
2379
  import {
@@ -2882,11 +2929,14 @@ async function handleICD11Search(args) {
2882
2929
  return falhaDaFonte(`Search error: ${results.errorMessage || "Unknown error"}`);
2883
2930
  }
2884
2931
  const destEntities = results.destinationEntities ?? [];
2885
- const top = destEntities.slice(0, params.max_results);
2932
+ const top = destEntities.slice(params.offset, params.offset + params.max_results);
2933
+ const next = nextOffset(params.offset, top.length, destEntities.length);
2886
2934
  const structured = {
2887
2935
  query: params.query,
2888
2936
  within,
2889
2937
  total_count: destEntities.length,
2938
+ offset: params.offset,
2939
+ next_offset: next,
2890
2940
  entities: top.map((e) => ({
2891
2941
  code: e.theCode ?? null,
2892
2942
  title: e.title,
@@ -2903,19 +2953,19 @@ async function handleICD11Search(args) {
2903
2953
  };
2904
2954
  if (top.length === 0) {
2905
2955
  return provenancedResult({
2906
- text: `No results found for "${params.query}" in ICD-11${withinLabel(within)}.`,
2956
+ text: destEntities.length > 0 ? pastTheEndText(params.query, `ICD-11${withinLabel(within)}`, params.offset, destEntities.length) : `No results found for "${params.query}" in ICD-11${withinLabel(within)}.`,
2907
2957
  structured,
2908
2958
  provenance: icd11Provenance()
2909
2959
  });
2910
2960
  }
2911
- const formatted = top.map((entity, index) => formatSearchResult(entity, index)).join("\n\n");
2961
+ const formatted = top.map((entity, index) => formatSearchResult(entity, params.offset + index)).join("\n\n");
2912
2962
  const header = `## ICD-11 Search Results for "${params.query}"${withinLabel(within)}
2913
2963
 
2914
- Found ${destEntities.length} results (showing top ${top.length}):
2964
+ Found ${destEntities.length} results (showing ${showingRange(params.offset, top.length)}):
2915
2965
 
2916
2966
  `;
2917
2967
  return provenancedResult({
2918
- text: header + formatted,
2968
+ text: header + formatted + nextPageLine(params.offset, top.length, destEntities.length, next),
2919
2969
  structured,
2920
2970
  provenance: icd11Provenance()
2921
2971
  });
@@ -3214,11 +3264,14 @@ async function handleICFSearch(args) {
3214
3264
  return falhaDaFonte(`Search error: ${results.errorMessage || "Unknown error"}`);
3215
3265
  }
3216
3266
  const dest = results.destinationEntities ?? [];
3217
- const top = dest.slice(0, params.max_results);
3267
+ const top = dest.slice(params.offset, params.offset + params.max_results);
3268
+ const next = nextOffset(params.offset, top.length, dest.length);
3218
3269
  const structured = {
3219
3270
  query: params.query,
3220
3271
  within,
3221
3272
  total_count: dest.length,
3273
+ offset: params.offset,
3274
+ next_offset: next,
3222
3275
  entities: top.map((e) => ({
3223
3276
  code: e.theCode || null,
3224
3277
  title: plainTitle(e.title),
@@ -3231,22 +3284,22 @@ async function handleICFSearch(args) {
3231
3284
  const bound = within.length > 0 ? ` within ${within.map((b) => `${b.code ?? b.value} ${b.title}`).join("; ")}` : "";
3232
3285
  if (top.length === 0) {
3233
3286
  return provenancedResult({
3234
- text: `No results found for "${params.query}" in ICF${bound}.`,
3287
+ text: dest.length > 0 ? pastTheEndText(params.query, `ICF${bound}`, params.offset, dest.length) : `No results found for "${params.query}" in ICF${bound}.`,
3235
3288
  structured,
3236
3289
  provenance: icfProvenance()
3237
3290
  });
3238
3291
  }
3239
3292
  const body = structured.entities.map((e, i) => {
3240
3293
  const comp = e.component ? ` (${COMPONENT_LABEL[e.component]})` : "";
3241
- return `${i + 1}. **${e.code ?? "No code"}** - ${e.title}${comp}
3294
+ return `${params.offset + i + 1}. **${e.code ?? "No code"}** - ${e.title}${comp}
3242
3295
  Score: ${e.score.toFixed(2)} | Leaf: ${e.is_leaf ? "Yes" : "No"}`;
3243
3296
  }).join("\n\n");
3244
3297
  return provenancedResult({
3245
3298
  text: `## ICF Search Results for "${params.query}"${bound}
3246
3299
 
3247
- Found ${dest.length} results (showing top ${top.length}):
3300
+ Found ${dest.length} results (showing ${showingRange(params.offset, top.length)}):
3248
3301
 
3249
- ${body}`,
3302
+ ${body}${nextPageLine(params.offset, top.length, dest.length, next)}`,
3250
3303
  structured,
3251
3304
  provenance: icfProvenance()
3252
3305
  });
@@ -3371,18 +3424,20 @@ var NLMClient = class {
3371
3424
  *
3372
3425
  * @param query - Search term
3373
3426
  * @param maxResults - Maximum results to return (default: 25)
3427
+ * @param offset - Results to skip (pagination; default 0)
3374
3428
  * @returns Array of LOINC items
3375
3429
  */
3376
- async searchLOINC(query, maxResults2 = 25) {
3377
- const cacheKey = `loinc:search:${query}:${maxResults2}`;
3430
+ async searchLOINC(query, maxResults2 = 25, offset = 0) {
3431
+ const cacheKey = `loinc:search:${query}:${maxResults2}:${offset}`;
3378
3432
  return cache.getOrSet(
3379
3433
  CACHE_PREFIX.LOINC,
3380
3434
  cacheKey,
3381
3435
  async () => {
3382
3436
  const url = `${NLM_CONFIG.clinicalTablesUrl}/loinc_items/v3/search`;
3437
+ const page = offset === 0 ? { maxList: maxResults2 } : { count: maxResults2, offset };
3383
3438
  const response = await this.request(url, {
3384
3439
  terms: query,
3385
- maxList: maxResults2,
3440
+ ...page,
3386
3441
  df: DEFAULT_LOINC_FIELDS.join(","),
3387
3442
  // LOINC License §10: terms with third-party copyright must carry
3388
3443
  // their notice — request it and pass it through verbatim.
@@ -3732,28 +3787,37 @@ async function handleLOINCSearch(args) {
3732
3787
  try {
3733
3788
  const params = LOINCSearchParamsSchema.parse(args);
3734
3789
  const client = getNLMClient();
3735
- const results = await client.searchLOINC(params.query, params.max_results);
3790
+ const results = await client.searchLOINC(params.query, params.max_results, params.offset);
3791
+ const shown = results.items.length;
3792
+ const reachable = Math.min(results.totalCount, LOINC_MAX_OFFSET + 100);
3793
+ const candidate2 = nextOffset(params.offset, shown, reachable);
3794
+ const next = candidate2 !== null && candidate2 <= LOINC_MAX_OFFSET ? candidate2 : null;
3736
3795
  const structured = {
3737
3796
  query: params.query,
3738
3797
  total_count: results.totalCount,
3739
- shown_count: results.items.length,
3798
+ shown_count: shown,
3799
+ offset: params.offset,
3800
+ next_offset: next,
3740
3801
  items: results.items.map(loincItemToOutput)
3741
3802
  };
3742
- if (results.items.length === 0) {
3803
+ if (shown === 0) {
3743
3804
  return provenancedResult({
3744
- text: `No LOINC codes found for "${params.query}".`,
3805
+ text: results.totalCount > 0 ? pastTheEndText(params.query, "LOINC", params.offset, results.totalCount) : `No LOINC codes found for "${params.query}".`,
3745
3806
  structured,
3746
3807
  provenance: loincProvenance()
3747
3808
  });
3748
3809
  }
3749
- const formatted = results.items.map((item, index) => formatLOINCItem(item, index)).join("\n\n");
3810
+ const formatted = results.items.map((item, index) => formatLOINCItem(item, params.offset + index)).join("\n\n");
3750
3811
  const header = `## LOINC Search Results for "${params.query}"
3751
3812
 
3752
- Found ${results.totalCount} total results (showing ${results.items.length}):
3813
+ Found ${results.totalCount} total results (showing ${params.offset === 0 ? shown : showingRange(params.offset, shown)}):
3753
3814
 
3754
3815
  `;
3816
+ const ceiling = next === null && params.offset + shown < results.totalCount ? `
3817
+
3818
+ _The source serves only the first ${LOINC_MAX_OFFSET + 100} of the ${results.totalCount} results: narrow the query to reach the rest._` : "";
3755
3819
  return provenancedResult({
3756
- text: header + formatted,
3820
+ text: header + formatted + nextPageLine(params.offset, shown, results.totalCount, next) + ceiling,
3757
3821
  structured,
3758
3822
  provenance: loincProvenance()
3759
3823
  });
@@ -4403,6 +4467,7 @@ function getRxNormClient() {
4403
4467
  }
4404
4468
 
4405
4469
  // src/tools/rxnorm.ts
4470
+ var APPROX_POOL = 100;
4406
4471
  var rxnormProvenance = () => medicalProvenance("NLM_RXNAV");
4407
4472
  var rxnormSearchTool = {
4408
4473
  name: "rxnorm_search",
@@ -4614,10 +4679,12 @@ async function handleRxNormSearch(args) {
4614
4679
  const client = getRxNormClient();
4615
4680
  let result = await client.searchDrugs(params.query);
4616
4681
  if (result.drugs.length === 0) {
4617
- const approxMatches = await client.getApproximateMatch(params.query, params.max_results);
4618
- if (approxMatches.length > 0) {
4682
+ const approxMatches = await client.getApproximateMatch(params.query, APPROX_POOL);
4683
+ const seen = /* @__PURE__ */ new Set();
4684
+ const distinct = approxMatches.filter((m) => !seen.has(m.rxcui) && seen.add(m.rxcui));
4685
+ if (distinct.length > 0) {
4619
4686
  result = {
4620
- drugs: approxMatches.map((m) => ({
4687
+ drugs: distinct.map((m) => ({
4621
4688
  rxcui: m.rxcui,
4622
4689
  name: m.name,
4623
4690
  synonym: "",
@@ -4627,10 +4694,13 @@ async function handleRxNormSearch(args) {
4627
4694
  };
4628
4695
  }
4629
4696
  }
4630
- const drugsCapped = result.drugs.slice(0, params.max_results);
4697
+ const drugsCapped = result.drugs.slice(params.offset, params.offset + params.max_results);
4698
+ const next = nextOffset(params.offset, drugsCapped.length, result.drugs.length);
4631
4699
  const structured = {
4632
4700
  query: params.query,
4633
4701
  total_count: result.drugs.length,
4702
+ offset: params.offset,
4703
+ next_offset: next,
4634
4704
  drugs: drugsCapped.map((d) => ({
4635
4705
  rxcui: d.rxcui,
4636
4706
  name: d.name,
@@ -4639,21 +4709,21 @@ async function handleRxNormSearch(args) {
4639
4709
  language: d.language
4640
4710
  }))
4641
4711
  };
4642
- if (result.drugs.length === 0) {
4712
+ if (drugsCapped.length === 0) {
4643
4713
  return provenancedResult({
4644
- text: `No drugs found for "${params.query}".`,
4714
+ text: result.drugs.length > 0 ? pastTheEndText(params.query, "RxNorm", params.offset, result.drugs.length) : `No drugs found for "${params.query}".`,
4645
4715
  structured,
4646
4716
  provenance: rxnormProvenance()
4647
4717
  });
4648
4718
  }
4649
- const formatted = drugsCapped.map((drug, index) => formatDrug(drug, index)).join("\n\n");
4719
+ const formatted = drugsCapped.map((drug, index) => formatDrug(drug, params.offset + index)).join("\n\n");
4650
4720
  const header = `## RxNorm Search Results for "${params.query}"
4651
4721
 
4652
4722
  Found ${result.drugs.length} result(s):
4653
4723
 
4654
4724
  `;
4655
4725
  return provenancedResult({
4656
- text: header + formatted,
4726
+ text: header + formatted + nextPageLine(params.offset, drugsCapped.length, result.drugs.length, next),
4657
4727
  structured,
4658
4728
  provenance: rxnormProvenance()
4659
4729
  });
@@ -5299,7 +5369,9 @@ Use this tool to:
5299
5369
 
5300
5370
  NLM publishes MeSH in English: the search matches and returns English labels whatever \`language\` says (a handful of records also carry other languages \u2014 13 Portuguese labels in the whole dataset, measured 2026-11-28 \u2014 and mesh_descriptor returns those). Content is never machine-translated.
5301
5371
 
5302
- Returns matching descriptors with MeSH IDs and labels. When no descriptor LABEL matches (lay words such as "heart attack" or "bedsore"), the search falls back to MeSH entry terms and says so (\`matched_via: "entry_term"\`, with the \`matched_term\` per descriptor) \u2014 that fallback takes a few seconds. Not applied with \`match: "exact"\`.`,
5372
+ Returns matching descriptors with MeSH IDs and labels. When no descriptor LABEL matches (lay words such as "heart attack" or "bedsore"), the search falls back to MeSH entry terms and says so (\`matched_via: "entry_term"\`, with the \`matched_term\` per descriptor) \u2014 that fallback takes a few seconds. Not applied with \`match: "exact"\`.
5373
+
5374
+ No pagination: the NLM lookup returns at most 50 descriptors and has no offset. When \`total_count\` equals \`max_results\` there may be more \u2014 narrow the query or use \`match: "startswith"\` / \`"exact"\`.`,
5303
5375
  inputSchema: buildInputSchema(MeSHSearchParamsSchema),
5304
5376
  outputSchema: buildOutputSchema(withProvenance(MeSHSearchOutputSchema)),
5305
5377
  annotations: READ_ONLY_TOOL_ANNOTATIONS
@@ -5480,10 +5552,11 @@ async function handleMeSHSearch(args) {
5480
5552
  try {
5481
5553
  const params = MeSHSearchParamsSchema.parse(args);
5482
5554
  const client = getMeSHClient();
5555
+ const capped = params.max_results > MESH_SOURCE_LIMIT;
5483
5556
  let results = await client.searchDescriptors(
5484
5557
  params.query,
5485
5558
  params.match,
5486
- params.max_results,
5559
+ Math.min(params.max_results, MESH_SOURCE_LIMIT),
5487
5560
  params.language
5488
5561
  );
5489
5562
  let matchedVia = "descriptor_label";
@@ -5507,7 +5580,9 @@ async function handleMeSHSearch(args) {
5507
5580
  }))
5508
5581
  };
5509
5582
  return provenancedResult({
5510
- text: formatSearchResults(params.query, results),
5583
+ text: formatSearchResults(params.query, results) + (capped && matchedVia === "descriptor_label" && results.length >= MESH_SOURCE_LIMIT ? `
5584
+
5585
+ _Asked for ${params.max_results}; the NLM lookup returns at most ${MESH_SOURCE_LIMIT} descriptors and has no next page \u2014 narrow the query or use \`match\` to reach others._` : ""),
5511
5586
  structured,
5512
5587
  provenance: meshProvenance()
5513
5588
  });
@@ -5836,7 +5911,7 @@ var CID10Client = class {
5836
5911
  * had to appear verbatim: "câncer de mama" returned zero against "Neoplasia
5837
5912
  * maligna da mama". `notes` says when a word was translated.
5838
5913
  */
5839
- search(query, level2, maxResults2, branches = []) {
5914
+ search(query, level2, maxResults2, branches = [], offset = 0) {
5840
5915
  const expanded = expandQuery(query);
5841
5916
  if (expanded.length === 0) {
5842
5917
  return { totalCount: 0, hits: [], notes: [] };
@@ -5854,7 +5929,7 @@ var CID10Client = class {
5854
5929
  }
5855
5930
  }
5856
5931
  const kept = branches.length > 0 ? all.filter((h) => branches.some((b) => inBranch(h.code, b))) : all;
5857
- return { totalCount: kept.length, hits: kept.slice(0, maxResults2), notes: vocabularyNotes(expanded) };
5932
+ return { totalCount: kept.length, hits: kept.slice(offset, offset + maxResults2), notes: vocabularyNotes(expanded) };
5858
5933
  }
5859
5934
  /**
5860
5935
  * Resolves a `within` value of cid10_search to a branch (PROGRESS.md 24.4b):
@@ -7585,19 +7660,30 @@ async function handleCID10Search(args) {
7585
7660
  params.query,
7586
7661
  params.level,
7587
7662
  params.max_results,
7588
- branches
7663
+ branches,
7664
+ params.offset
7589
7665
  );
7666
+ const next = nextOffset(params.offset, hits.length, totalCount);
7590
7667
  const structured = {
7591
7668
  query: params.query,
7592
7669
  level: params.level,
7593
7670
  within: branches.map((b) => ({ value: b.value, code: b.code, title: b.title, uri: null })),
7594
7671
  total_count: totalCount,
7595
7672
  shown_count: hits.length,
7673
+ offset: params.offset,
7674
+ next_offset: next,
7596
7675
  hits,
7597
7676
  ...notes.length > 0 ? { vocabulary_notes: notes } : {}
7598
7677
  };
7599
7678
  const notesText = notes.map((n) => `_${n}_
7600
7679
  `).join("");
7680
+ if (hits.length === 0 && totalCount > 0) {
7681
+ return provenancedResult({
7682
+ text: `Nenhum resultado no deslocamento (offset) ${params.offset} para "${params.query}": a busca casou ${totalCount} c\xF3digos, ent\xE3o a \xFAltima p\xE1gina come\xE7a antes de ${totalCount}.`,
7683
+ structured,
7684
+ provenance: cid10Provenance()
7685
+ });
7686
+ }
7601
7687
  if (hits.length === 0) {
7602
7688
  return provenancedResult({
7603
7689
  text: `Nenhum c\xF3digo CID-10 encontrado para "${params.query}".
@@ -7609,12 +7695,15 @@ async function handleCID10Search(args) {
7609
7695
  }
7610
7696
  const header = `## Resultados CID-10 para "${params.query}"
7611
7697
 
7612
- Total: ${totalCount} (mostrando ${hits.length}, escopo: ${params.level}).
7698
+ Total: ${totalCount} (mostrando ${params.offset === 0 ? hits.length : `${params.offset + 1}\u2013${params.offset + hits.length}`}, escopo: ${params.level}).
7613
7699
 
7614
7700
  ` + (notesText ? notesText + "\n" : "");
7615
- const body = hits.map((h, i) => `${i + 1}. ${formatHit(h)}`).join("\n\n");
7701
+ const body = hits.map((h, i) => `${params.offset + i + 1}. ${formatHit(h)}`).join("\n\n");
7702
+ const nextLine = next === null ? "" : `
7703
+
7704
+ _Mostrando ${params.offset + 1}\u2013${params.offset + hits.length} de ${totalCount}. Pr\xF3xima p\xE1gina: chame de novo com \`offset: ${next}\`._`;
7616
7705
  return provenancedResult({
7617
- text: header + body,
7706
+ text: header + body + nextLine,
7618
7707
  structured,
7619
7708
  provenance: cid10Provenance()
7620
7709
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "medical-terminologies-mcp",
3
3
  "mcpName": "io.github.SidneyBissoli/medical-terminologies-mcp",
4
- "version": "4.3.3",
4
+ "version": "4.4.0",
5
5
  "description": "Unified MCP server for seven medical terminologies (ICD-11, ICF, LOINC, RxNorm, MeSH, ATC, CID-10) with authoritative WHO ICD-10→ICD-11 mapping. 37 tools, hosted endpoint available, MIT.",
6
6
  "author": "Sidney da Silva Pereira Bissoli",
7
7
  "license": "MIT",
@@ -69,9 +69,10 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@modelcontextprotocol/client": "^2.0.0",
72
- "@sbissoli/mcp-evals": "^0.2.1",
72
+ "@sbissoli/mcp-evals": "^0.3.0",
73
73
  "@sbissoli/mcp-live-source": "^0.5.0",
74
74
  "@sbissoli/mcp-surface": "^0.6.0",
75
+ "@sbissoli/mcp-tool-tests": "^0.2.0",
75
76
  "@types/node": "^26.5.1",
76
77
  "esbuild": "^0.28.2",
77
78
  "nock": "^15.0.1",