lookup_rxnorm
Retrieve RxNorm concept, RxCUI, ingredient relationships, and drug class for any drug by entering its brand or generic name.
Instructions
Look up a drug's RxNorm concept, RxCUI identifier, ingredient relationships, and drug class. RxNorm is the standard for drug interoperability across EHR systems.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| drug_name | Yes | Drug name (brand or generic, e.g. 'abilify', 'aripiprazole', 'ozempic') |
Implementation Reference
- index.js:258-265 (registration)Tool registration for 'lookup_rxnorm' using server.tool() with a description and Zod schema for drug_name input.
server.tool( "lookup_rxnorm", "Look up a drug's RxNorm concept, RxCUI identifier, ingredient relationships, and drug class. RxNorm is the standard for drug interoperability across EHR systems.", { drug_name: z .string() .describe("Drug name (brand or generic, e.g. 'abilify', 'aripiprazole', 'ozempic')"), }, - index.js:261-265 (schema)Input schema defining drug_name as a Zod string describing the drug name (brand or generic).
{ drug_name: z .string() .describe("Drug name (brand or generic, e.g. 'abilify', 'aripiprazole', 'ozempic')"), }, - index.js:266-355 (handler)Handler function that calls RxNav APIs to look up RxCUI, find approximate matches if needed, fetches properties, ATC class, and related ingredients/brands, then returns formatted markdown text.
async ({ drug_name }) => { // Get RxCUI const searchData = await apiFetch( `${RXNAV_BASE}/rxcui.json?name=${encodeURIComponent(drug_name)}&search=2` ); const rxcui = searchData?.idGroup?.rxnormId?.[0]; if (!rxcui) { // Try approximate match const approxData = await apiFetch( `${RXNAV_BASE}/approximateTerm.json?term=${encodeURIComponent(drug_name)}&maxEntries=5` ); const candidates = approxData?.approximateGroup?.candidate || []; if (!candidates.length) { return { content: [{ type: "text", text: `No RxNorm concept found for "${drug_name}". Check spelling or try generic name.` }] }; } const lines = candidates.slice(0, 5).map( c => `- **RxCUI ${c.rxcui}** — Score: ${c.score} (${c.name || "name not available"})` ); return { content: [{ type: "text", text: [ `## RxNorm: Approximate Matches for "${drug_name}"`, "", ...lines, "", "Re-run with the exact name for full details." ].join("\n") }] }; } // Get properties const [propsData, classData, relData] = await Promise.all([ apiFetch(`${RXNAV_BASE}/rxcui/${rxcui}/properties.json`).catch(() => null), apiFetch(`${RXNAV_BASE}/rxclass/class/byRxcui.json?rxcui=${rxcui}&relaSource=ATC`).catch(() => null), apiFetch(`${RXNAV_BASE}/rxcui/${rxcui}/related.json?tty=IN+BN+SCD`).catch(() => null), ]); const props = propsData?.properties || {}; const classes = classData?.rxclassDrugInfoList?.rxclassDrugInfo || []; const related = relData?.relatedGroup?.conceptGroup || []; const ingredients = related .find(g => g.tty === "IN") ?.conceptProperties?.map(c => c.name) || []; const brandNames = related .find(g => g.tty === "BN") ?.conceptProperties?.map(c => c.name) || []; const atcClasses = classes.slice(0, 3).map( c => `${c.rxclassMinConceptItem?.className} (${c.rxclassMinConceptItem?.classId})` ); const text = [ `## RxNorm: ${props.name || drug_name}`, "", `### Identifiers`, `- **RxCUI:** ${rxcui}`, `- **Name:** ${props.name || "N/A"}`, `- **Synonym:** ${props.synonym || "N/A"}`, `- **Term Type:** ${props.tty || "N/A"}`, `- **Language:** ${props.language || "N/A"}`, "", `### Drug Relationships`, `- **Active Ingredient(s):** ${ingredients.join(", ") || "N/A"}`, `- **Brand Names:** ${brandNames.slice(0, 8).join(", ") || "N/A"}`, "", `### Drug Class (ATC)`, atcClasses.length ? atcClasses.map(c => `- ${c}`).join("\n") : "- ATC classification not available", "", `### Interoperability`, `- RxNorm is the **US standard** for drug naming in EHR/EMR systems`, `- RxCUI \`${rxcui}\` can be used to query drug interactions, formulary status, and prescribing data`, `- Maps to: **NDF-RT**, **SNOMED CT**, **MeSH**, **DrugBank**, **ATC**`, "", `_Source: NIH National Library of Medicine RxNav API_`, ].join("\n"); return { content: [{ type: "text", text }] }; } - index.js:28-34 (helper)Shared apiFetch utility used by lookup_rxnorm to call NIH NLM RxNav REST APIs.
async function apiFetch(url) { const res = await fetch(url, { headers: { "Accept": "application/json" } }); if (!res.ok) throw new Error(`API error ${res.status}: ${url}`); return res.json(); }