medical-terminologies-mcp 4.0.0 → 4.2.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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +116 -58
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![node](https://img.shields.io/node/v/medical-terminologies-mcp)](https://www.npmjs.com/package/medical-terminologies-mcp)
6
6
  [![MCP Registry](https://img.shields.io/badge/MCP-Registry-blue)](https://registry.modelcontextprotocol.io)
7
7
  [![LobeHub](https://lobehub.com/badge/mcp/sidneybissoli-medical-terminologies-mcp)](https://lobehub.com/mcp/sidneybissoli-medical-terminologies-mcp)
8
- [![smithery badge](https://smithery.ai/badge/sidneybissoli/medical-terminologies-mcp)](https://smithery.ai/servers/sidneybissoli/medical-terminologies-mcp)
8
+ [![smithery badge](https://img.shields.io/badge/Smithery-listed-FF5601)](https://smithery.ai/servers/sidneybissoli/medical-terminologies-mcp)
9
9
  [![Glama MCP server](https://glama.ai/mcp/servers/SidneyBissoli/medical-terminologies-mcp/badges/score.svg)](https://glama.ai/mcp/servers/SidneyBissoli/medical-terminologies-mcp)
10
10
  [![Available on CodeGuilds](https://img.shields.io/badge/Available_on-CodeGuilds-6366f1)](https://codeguilds.dev/packages/medical-terminologies-mcp)
11
11
  [![GitHub stars](https://img.shields.io/github/stars/SidneyBissoli/medical-terminologies-mcp?style=flat&logo=github)](https://github.com/SidneyBissoli/medical-terminologies-mcp)
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.0.0",
33
+ version: "4.2.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",
@@ -1009,8 +1009,10 @@ var ICD11MappingSchema = z.object({
1009
1009
  });
1010
1010
  var MapICD10ToICD11OutputSchema = z.object({
1011
1011
  query: z.string().describe("The ICD-10 code as submitted (raw, before normalization)."),
1012
- found: z.boolean().describe("Whether the code is in the WHO ICD-10 \u2192 ICD-11 transition table."),
1013
- icd10: ICD10SourceSchema.nullable().describe("Source ICD-10 entry from the WHO table. Null when found=false."),
1012
+ found: z.boolean().describe(
1013
+ "Whether the WHO ICD-10 \u2192 ICD-11 transition table maps the code: directly, or through its category for a subcategory the WHO defines only at block level (E11.9 \u2192 E11; the subcategory must exist in CID-10 V2008). icd10.code shows which code the WHO table mapped."
1014
+ ),
1015
+ icd10: ICD10SourceSchema.nullable().describe("ICD-10 entry the WHO table mapped: the code itself, or its category when the subcategory is listed only at block level (icd10.code differs from query then). Null when found=false."),
1014
1016
  primary: ICD11MappingSchema.nullable().describe("Primary 1:1 ICD-11 mapping. Null when found=false."),
1015
1017
  alternatives: z.array(ICD11MappingSchema).describe(
1016
1018
  "Additional ICD-11 candidates WHO documents for this ICD-10 code. Empty when the primary is the only documented mapping (or when found=false). 1,461 of the 11,243 indexed codes have non-empty alternatives."
@@ -1114,10 +1116,10 @@ var MatchValueSetOutputSchema = z.object({
1114
1116
  })
1115
1117
  ).describe("One entry per term, in request order."),
1116
1118
  counts: z.object({
1117
- exact: z.number().int(),
1118
- strong: z.number().int(),
1119
- needs_review: z.number().int(),
1120
- no_candidates: z.number().int()
1119
+ exact: z.number().int().describe("Terms whose best member is an exact match."),
1120
+ strong: z.number().int().describe("Terms whose best member is a strong match."),
1121
+ needs_review: z.number().int().describe("Terms whose best member needs review by a person."),
1122
+ no_candidates: z.number().int().describe("Terms with no confirmed member sharing a word with them.")
1121
1123
  }).describe("How many terms landed in each class (by their best member).")
1122
1124
  });
1123
1125
  var ComposeFunctioningParamsSchema = z.object({
@@ -1141,7 +1143,7 @@ var ComposeRoleSchema = (item, what) => z.object({
1141
1143
  items: z.array(item).describe(`${what}, best first. Empty when nothing shares a word with the term.`)
1142
1144
  });
1143
1145
  var ComposeFunctioningOutputSchema = z.object({
1144
- term: z.string(),
1146
+ term: z.string().describe("The functional concept as submitted."),
1145
1147
  functioning: ComposeRoleSchema(
1146
1148
  z.object({
1147
1149
  code: z.string().describe('ICF category code (e.g. "d450").'),
@@ -1153,7 +1155,7 @@ var ComposeFunctioningOutputSchema = z.object({
1153
1155
  icd11_counterpart: ComposeICD11CounterpartSchema.nullable().describe('The ICD-11 entity the WHO ties to this ICF category (supplementary chapter V, "Generic functioning domains"); null when the WHO ties none.')
1154
1156
  }),
1155
1157
  "ICF categories (the function or activity)"
1156
- ),
1158
+ ).describe("Functioning role: ICF categories naming the function or activity."),
1157
1159
  measures: ComposeRoleSchema(
1158
1160
  z.object({
1159
1161
  code: z.string().describe("LOINC code."),
@@ -1162,7 +1164,7 @@ var ComposeFunctioningOutputSchema = z.object({
1162
1164
  coding: FhirCodingSchema.nullable()
1163
1165
  }),
1164
1166
  "LOINC observations that measure it (retired codes dropped)"
1165
- ),
1167
+ ).describe("Measure role: LOINC observations that measure the concept."),
1166
1168
  conditions: ComposeRoleSchema(
1167
1169
  z.object({
1168
1170
  code: z.string().describe("ICD-11 MMS code."),
@@ -1172,7 +1174,7 @@ var ComposeFunctioningOutputSchema = z.object({
1172
1174
  coding: FhirCodingSchema.nullable()
1173
1175
  }),
1174
1176
  "ICD-11 conditions (chapters 01-26; chapter V and extension codes are left to icd11_counterpart)"
1175
- ),
1177
+ ).describe("Condition role: ICD-11 conditions lexically matched to the concept."),
1176
1178
  note: z.string().describe("How to read the roles: which links are WHO-given and which are lexical suggestions.")
1177
1179
  });
1178
1180
  var HARMONIZE_MAX_TERMS = 50;
@@ -2296,17 +2298,12 @@ var WHOClient = class {
2296
2298
  * @returns Postcoordination axes and scales
2297
2299
  */
2298
2300
  async getPostcoordination(code, language = "en") {
2299
- const cacheKey = `postcoord:${code}:${language}`;
2300
- return cache.getOrSet(
2301
- CACHE_PREFIX.ICD11,
2302
- cacheKey,
2303
- () => this.request(
2304
- `/release/11/${WHO_CONFIG.releaseId}/${WHO_CONFIG.linearization}/codeinfo/${code}/postcoordination`,
2305
- {},
2306
- language
2307
- ),
2308
- DEFAULT_TTL.LOOKUP
2309
- );
2301
+ const entity = await this.lookup(code, language);
2302
+ return {
2303
+ "@context": entity["@context"] ?? "",
2304
+ "@id": entity["@id"],
2305
+ postcoordinationScale: entity.postcoordinationScale
2306
+ };
2310
2307
  }
2311
2308
  };
2312
2309
  function termRefs(terms, ownerUri) {
@@ -3033,36 +3030,48 @@ async function handleICD11Chapters(args) {
3033
3030
  return handleToolError(error);
3034
3031
  }
3035
3032
  }
3033
+ function isRequired(v) {
3034
+ return v === true || typeof v === "string" && v.trim().toLowerCase() === "true";
3035
+ }
3036
+ function allowsMultiple(v) {
3037
+ const s = (v ?? "").trim().toLowerCase();
3038
+ return s === "allowalways" || s === "allowedexceptfromsameblock" || s === "true";
3039
+ }
3040
+ function axisLabel(axisName) {
3041
+ const seg = axisName.split("/").filter(Boolean).pop() ?? axisName;
3042
+ return seg.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
3043
+ }
3036
3044
  async function handleICD11Postcoordination(args) {
3037
3045
  try {
3038
3046
  const params = ICD11PostcoordinationParamsSchema.parse(args);
3039
3047
  const client = getWHOClient();
3040
3048
  const postcoord = await client.getPostcoordination(params.code);
3041
- const scales = postcoord.postcoordinationScale ?? [];
3042
- const structured = {
3043
- code: params.code,
3044
- axes: scales.map((s) => ({
3045
- axis_name: s.axisName,
3046
- required: Boolean(s.requiredPostcoordination),
3047
- allow_multiple: s.allowMultipleValues === "true",
3048
- value_count: s.scaleEntity ? s.scaleEntity.length : null
3049
- }))
3050
- };
3049
+ const scales = (postcoord.postcoordinationScale ?? []).filter(
3050
+ (s) => typeof s.axisName === "string" && s.axisName !== ""
3051
+ );
3052
+ const axes = scales.map((s) => ({
3053
+ axis_name: s.axisName,
3054
+ required: isRequired(s.requiredPostcoordination),
3055
+ allow_multiple: allowsMultiple(s.allowMultipleValues),
3056
+ value_count: Array.isArray(s.scaleEntity) ? s.scaleEntity.length : null
3057
+ }));
3058
+ const structured = { code: params.code, axes };
3051
3059
  const lines = [];
3052
3060
  lines.push(`# Postcoordination for ${params.code}`);
3053
3061
  lines.push("");
3054
- if (scales.length === 0) {
3062
+ if (axes.length === 0) {
3055
3063
  lines.push("This entity does not have postcoordination axes available.");
3056
3064
  } else {
3057
3065
  lines.push("**Available Postcoordination Axes:**");
3058
3066
  lines.push("");
3059
- for (const scale of scales) {
3060
- const required = scale.requiredPostcoordination ? "(Required)" : "(Optional)";
3061
- const multiple = scale.allowMultipleValues === "true" ? "Multiple values allowed" : "Single value only";
3062
- lines.push(`### ${scale.axisName} ${required}`);
3067
+ for (const axis of axes) {
3068
+ const required = axis.required ? "(Required)" : "(Optional)";
3069
+ const multiple = axis.allow_multiple ? "Multiple values allowed" : "Single value only";
3070
+ lines.push(`### ${axisLabel(axis.axis_name)} ${required}`);
3071
+ lines.push(`- Axis: ${axis.axis_name}`);
3063
3072
  lines.push(`- ${multiple}`);
3064
- if (scale.scaleEntity && scale.scaleEntity.length > 0) {
3065
- lines.push(`- ${scale.scaleEntity.length} possible values`);
3073
+ if (axis.value_count) {
3074
+ lines.push(`- ${axis.value_count} value set root(s) (any descendant can be used)`);
3066
3075
  }
3067
3076
  lines.push("");
3068
3077
  }
@@ -4111,12 +4120,23 @@ var RxNormClient = class {
4111
4120
  if (!response.rxclassDrugInfoList?.rxclassDrugInfo) {
4112
4121
  return [];
4113
4122
  }
4114
- return response.rxclassDrugInfoList.rxclassDrugInfo.map((info) => ({
4115
- classId: info.rxclassMinConceptItem.classId,
4116
- className: info.rxclassMinConceptItem.className,
4117
- classType: info.rxclassMinConceptItem.classType,
4118
- source: info.rela || ""
4119
- }));
4123
+ const seen = /* @__PURE__ */ new Set();
4124
+ const classes = [];
4125
+ for (const info of response.rxclassDrugInfoList.rxclassDrugInfo) {
4126
+ if (info.relaSource === "SNOMEDCT") continue;
4127
+ const source = info.rela || info.relaSource || "";
4128
+ const item = info.rxclassMinConceptItem;
4129
+ const key = `${item.classId}|${item.classType}|${source}`;
4130
+ if (seen.has(key)) continue;
4131
+ seen.add(key);
4132
+ classes.push({
4133
+ classId: item.classId,
4134
+ className: item.className,
4135
+ classType: item.classType,
4136
+ source
4137
+ });
4138
+ }
4139
+ return classes;
4120
4140
  },
4121
4141
  DEFAULT_TTL.LOOKUP
4122
4142
  );
@@ -4136,13 +4156,12 @@ var RxNormClient = class {
4136
4156
  const response = await this.request(`/rxcui/${rxcui}/allndcs.json`, {
4137
4157
  history: 0
4138
4158
  });
4139
- if (!response.ndcGroup?.ndcList?.ndc) {
4140
- return [];
4159
+ const times = response.ndcConcept?.ndcTime ?? [];
4160
+ const ndcs = /* @__PURE__ */ new Set();
4161
+ for (const t of times) {
4162
+ for (const ndc of t.ndc ?? []) ndcs.add(ndc);
4141
4163
  }
4142
- return response.ndcGroup.ndcList.ndc.map((ndc) => ({
4143
- ndc,
4144
- rxcui
4145
- }));
4164
+ return [...ndcs].map((ndc) => ({ ndc, rxcui }));
4146
4165
  },
4147
4166
  DEFAULT_TTL.LOOKUP
4148
4167
  );
@@ -5979,7 +5998,7 @@ Use this for clinical coding, billing migration, retrospective analysis, and any
5979
5998
 
5980
5999
  Provide a code like "E11" (Type 2 diabetes), "I21" (Acute MI), or "A07.8" (4 alternatives in WHO's table). Both dotted ("A07.8") and undotted ("A078") forms are accepted.
5981
6000
 
5982
- Returns "no mapping" when the code isn't in the WHO category-level table \u2014 that's the honest answer rather than a fuzzy search fallback.`,
6001
+ Subcategories the WHO defines once for a whole block (E10-E14: E11.9 "without complications") are not in the tables; they map through their category (E11 \u2192 5A11) when the subcategory exists in CID-10 V2008, and the answer says so. Returns "no mapping" when neither the code nor that route is in the WHO table \u2014 that's the honest answer rather than a fuzzy search fallback.`,
5983
6002
  inputSchema: buildInputSchema(MapICD10ToICD11ParamsSchema),
5984
6003
  outputSchema: buildOutputSchema(withProvenance(MapICD10ToICD11OutputSchema)),
5985
6004
  annotations: READ_ONLY_TOOL_ANNOTATIONS
@@ -6029,7 +6048,8 @@ async function handleMapICD10ToICD11(args) {
6029
6048
  const params = MapICD10ToICD11ParamsSchema.parse(args);
6030
6049
  const client = getICD10ToICD11MapClient();
6031
6050
  const inputCode = params.icd10_code.trim();
6032
- const entry = client.lookup(inputCode);
6051
+ const resolved = resolveICD10(inputCode);
6052
+ const entry = resolved?.entry ?? null;
6033
6053
  const structured = {
6034
6054
  query: inputCode,
6035
6055
  found: entry !== null,
@@ -6069,6 +6089,12 @@ async function handleMapICD10ToICD11(args) {
6069
6089
  `**ICD-10:** ${entry.icd10.code} \u2014 ${entry.icd10.title} (chapter ${entry.icd10.chapter})`
6070
6090
  );
6071
6091
  lines.push("");
6092
+ if (resolved?.viaCategory) {
6093
+ lines.push(
6094
+ `> **Mapped through its category.** The WHO transition tables list ${entry.icd10.code} but not ${inputCode.toUpperCase()}: WHO ICD-10 defines this fourth character once for the whole block, so the WHO maps the category. ${inputCode.toUpperCase()} exists in the CID-10 V2008 (Brazilian edition of WHO ICD-10): "${resolved.subcategoryTitlePt}". Check whether ICD-11 has a more specific code under the primary below (icd11_hierarchy, direction "children").`
6095
+ );
6096
+ lines.push("");
6097
+ }
6072
6098
  lines.push("## Primary ICD-11 mapping");
6073
6099
  lines.push("");
6074
6100
  lines.push(`- **Code:** ${entry.primary.code}`);
@@ -6105,6 +6131,18 @@ async function handleMapICD10ToICD11(args) {
6105
6131
  return handleToolError(error);
6106
6132
  }
6107
6133
  }
6134
+ function resolveICD10(code) {
6135
+ const cli = getICD10ToICD11MapClient();
6136
+ const direct = cli.lookup(code);
6137
+ if (direct) return { entry: direct, viaCategory: false, subcategoryTitlePt: null };
6138
+ const normalized = code.trim().toUpperCase().replace(".", "");
6139
+ if (!/^[A-Z]\d{3}$/.test(normalized)) return null;
6140
+ const category = cli.lookup(normalized.slice(0, 3));
6141
+ if (!category) return null;
6142
+ const sub = getCID10Client().lookup(normalized);
6143
+ if (!sub || sub.level !== "subcategory") return null;
6144
+ return { entry: category, viaCategory: true, subcategoryTitlePt: sub.title };
6145
+ }
6108
6146
  function notFoundResult(item, source) {
6109
6147
  return {
6110
6148
  code: item.code,
@@ -6136,9 +6174,26 @@ async function validateOneCode(item) {
6136
6174
  switch (item.terminology) {
6137
6175
  case "icd10": {
6138
6176
  const cli = getICD10ToICD11MapClient();
6139
- const entry = cli.lookup(item.code);
6177
+ const resolved = resolveICD10(item.code);
6140
6178
  const source = `WHO ICD-10 \u2192 ICD-11 transition tables, release ${cli.getVersion()}`;
6141
- if (!entry) return notFoundResult(item, source);
6179
+ if (!resolved) return notFoundResult(item, source);
6180
+ const entry = resolved.entry;
6181
+ if (resolved.viaCategory) {
6182
+ const sub = item.code.trim().toUpperCase().replace(/^([A-Z]\d{2})\.?(\d)$/, "$1.$2");
6183
+ return {
6184
+ code: item.code,
6185
+ terminology: "icd10",
6186
+ valid: true,
6187
+ active: null,
6188
+ // The WHO tables carry no title for the subcategory; the CID-10 one
6189
+ // is the official Brazilian Portuguese title of the same code.
6190
+ title: resolved.subcategoryTitlePt,
6191
+ replaced_by: `${entry.primary.code} (ICD-11: ${entry.primary.title}; category-level mapping of ${entry.icd10.code})`,
6192
+ coding: toFhirCoding("icd10", sub, null),
6193
+ source: `${source} (category ${entry.icd10.code}; the WHO defines this fourth character for the whole block) + CID-10 V2008, Brazilian edition of WHO ICD-10 (subcategory ${sub})`,
6194
+ error: null
6195
+ };
6196
+ }
6142
6197
  return {
6143
6198
  code: item.code,
6144
6199
  terminology: "icd10",
@@ -6357,6 +6412,7 @@ var TERMINOLOGY_LABELS = {
6357
6412
  icf: "ICF"
6358
6413
  };
6359
6414
  var LOINC_RERANK_POOL = 50;
6415
+ var RERANK_POOL = 25;
6360
6416
  async function handleFindEquivalent(args) {
6361
6417
  try {
6362
6418
  const params = FindEquivalentParamsSchema.parse(args);
@@ -6436,7 +6492,9 @@ No terminologies left to search after excluding source_terminology="${params.sou
6436
6492
  const client = getRxNormClient();
6437
6493
  const rxResults = await client.searchDrugs(term);
6438
6494
  raw.rxnorm = ok2(
6439
- rxResults.drugs.slice(0, limit).map((r) => ({ code: r.rxcui, title: r.name, uri: null, synonyms: [] }))
6495
+ // searchDrugs already returns the whole list (one request): rank
6496
+ // it, then cut — the source puts branded packs before "metformin".
6497
+ rxResults.drugs.slice(0, RERANK_POOL).map((r) => ({ code: r.rxcui, title: r.name, uri: null, synonyms: [] }))
6440
6498
  );
6441
6499
  } catch (e) {
6442
6500
  raw.rxnorm = fail(e instanceof Error ? e.message : "Error");
@@ -6449,12 +6507,12 @@ No terminologies left to search after excluding source_terminology="${params.sou
6449
6507
  (async () => {
6450
6508
  try {
6451
6509
  const client = getMeSHClient();
6452
- let meshResults = await client.searchDescriptors(term, "contains", limit);
6510
+ let meshResults = await client.searchDescriptors(term, "contains", Math.max(limit, RERANK_POOL));
6453
6511
  if (meshResults.length === 0) {
6454
6512
  meshResults = await client.searchDescriptorsByEntryTerm(term, limit);
6455
6513
  }
6456
6514
  raw.mesh = ok2(
6457
- meshResults.slice(0, limit).map((r) => ({
6515
+ meshResults.map((r) => ({
6458
6516
  code: r.id,
6459
6517
  title: r.label,
6460
6518
  uri: r.uri ?? null,
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.0.0",
4
+ "version": "4.2.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",