get-drug-details
Retrieve comprehensive drug information using National Drug Code (NDC) to access detailed medication data from FDA, WHO, and medical databases.
Instructions
Get detailed information about a specific drug by NDC (National Drug Code)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ndc | Yes | National Drug Code (NDC) of the drug |
Implementation Reference
- src/index.ts:69-83 (registration)Registers the 'get-drug-details' MCP tool, defines input schema (NDC string), and provides inline handler that fetches data via getDrugByNDC and formats it.server.tool( "get-drug-details", "Get detailed information about a specific drug by NDC (National Drug Code)", { ndc: z.string().describe("National Drug Code (NDC) of the drug"), }, async ({ ndc }) => { try { const drug = await getDrugByNDC(ndc); return formatDrugDetails(drug, ndc); } catch (error: any) { return createErrorResponse("fetching drug details", error); } }, );
- src/utils.ts:65-79 (handler)Core handler function that queries the FDA drug label API by product NDC code to retrieve detailed drug information.export async function getDrugByNDC(ndc: string): Promise<DrugLabel | null> { try { const res = await superagent .get(`${FDA_API_BASE}/drug/label.json`) .query({ search: `openfda.product_ndc:${ndc}`, limit: 1, }) .set("User-Agent", USER_AGENT); return res.body.results?.[0] || null; } catch (error) { return null; } }
- src/index.ts:72-74 (schema)Zod input schema defining the required 'ndc' parameter as a string.{ ndc: z.string().describe("National Drug Code (NDC) of the drug"), },
- src/types.ts:1-18 (schema)TypeScript interface defining the structure of FDA DrugLabel data used by the tool.export type DrugLabel = { openfda: { brand_name?: string[]; generic_name?: string[]; manufacturer_name?: string[]; product_ndc?: string[]; substance_name?: string[]; route?: string[]; dosage_form?: string[]; }; purpose?: string[]; warnings?: string[]; adverse_reactions?: string[]; drug_interactions?: string[]; dosage_and_administration?: string[]; clinical_pharmacology?: string[]; effective_time: string; };
- src/utils.ts:413-452 (helper)Helper function that formats the raw FDA drug data into a user-friendly MCP response with sections for basic info, purpose, warnings, and interactions.export function formatDrugDetails(drug: any, ndc: string) { if (!drug) { return createMCPResponse(`No drug found with NDC: ${ndc}`); } let result = `**Drug Details for NDC: ${ndc}**\n\n`; result += `**Basic Information:**\n`; result += `- Brand Name: ${drug.openfda.brand_name?.[0] || "Not specified"}\n`; result += `- Generic Name: ${drug.openfda.generic_name?.[0] || "Not specified"}\n`; result += `- Manufacturer: ${drug.openfda.manufacturer_name?.[0] || "Not specified"}\n`; result += `- Route: ${drug.openfda.route?.[0] || "Not specified"}\n`; result += `- Dosage Form: ${drug.openfda.dosage_form?.[0] || "Not specified"}\n`; result += `- Last Updated: ${drug.effective_time}\n\n`; if (drug.purpose && drug.purpose.length > 0) { result += `**Purpose/Uses:**\n`; drug.purpose.forEach((purpose: string, index: number) => { result += `${index + 1}. ${purpose}\n`; }); result += "\n"; } if (drug.warnings && drug.warnings.length > 0) { result += `**Warnings:**\n`; drug.warnings.forEach((warning: string, index: number) => { result += `${index + 1}. ${warning.substring(0, 300)}${warning.length > 300 ? "..." : ""}\n`; }); result += "\n"; } if (drug.drug_interactions && drug.drug_interactions.length > 0) { result += `**Drug Interactions:**\n`; drug.drug_interactions.forEach((interaction: string, index: number) => { result += `${index + 1}. ${interaction.substring(0, 300)}${interaction.length > 300 ? "..." : ""}\n`; }); result += "\n"; } return createMCPResponse(result); }