get-drug-by-product-ndc
Retrieve comprehensive drug information using a product NDC code in the XXXXX-XXXX format. This tool identifies all package variations associated with a specific drug product.
Instructions
Get drug information by product NDC only (XXXXX-XXXX format). This ignores package variations and finds all packages for a product.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productNDC | Yes | Product NDC in format XXXXX-XXXX |
Implementation Reference
- src/index.ts:483-547 (handler)Handler function for the 'get-drug-by-product-ndc' tool. Validates the product NDC format, queries the OpenFDA API using OpenFDABuilder and makeOpenFDARequest, processes the response to extract drug information and all matching package NDCs, constructs a drugInfo object, and returns a formatted text response.async ({ productNDC }) => { // Validate product NDC format if (!/^\d{5}-\d{4}$/.test(productNDC.trim())) { return { content: [{ type: "text", text: `Invalid product NDC format: "${productNDC}"\n\n✅ Required format: XXXXX-XXXX (e.g., 12345-1234)`, }], }; } const url = new OpenFDABuilder() .context("label") .search(`openfda.product_ndc:"${productNDC.trim()}"`) .limit(1) .build(); const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve drug data for product NDC "${productNDC}": ${error.message}`, }], }; } if (!drugData || !drugData.results || drugData.results.length === 0) { return { content: [{ type: "text", text: `No drug found with product NDC "${productNDC}".`, }], }; } const drug = drugData.results[0]; // Get all packages for this product const allPackagesForProduct = drug.openfda.package_ndc?.filter(ndc => ndc.startsWith(productNDC.trim()) ) || []; const drugInfo = { product_ndc: productNDC, available_packages: allPackagesForProduct, brand_name: drug.openfda.brand_name || [], generic_name: drug.openfda.generic_name || [], manufacturer_name: drug.openfda.manufacturer_name || [], product_type: drug.openfda.product_type || [], route: drug.openfda.route || [], substance_name: drug.openfda.substance_name || [], active_ingredient: drug.active_ingredient || [], purpose: drug.purpose || [], dosage_and_administration: drug.dosage_and_administration || [] }; return { content: [{ type: "text", text: `✅ Product NDC "${productNDC}" found with ${allPackagesForProduct.length} package variation(s):\n\n${JSON.stringify(drugInfo, null, 2)}`, }], }; }
- src/index.ts:480-482 (schema)Input schema for the tool using Zod, defining the 'productNDC' parameter as a string with description.{ productNDC: z.string().describe("Product NDC in format XXXXX-XXXX") },
- src/index.ts:477-548 (registration)Registration of the 'get-drug-by-product-ndc' tool via server.tool(), specifying name, description, input schema, and inline handler function.server.tool( "get-drug-by-product-ndc", "Get drug information by product NDC only (XXXXX-XXXX format). This ignores package variations and finds all packages for a product.", { productNDC: z.string().describe("Product NDC in format XXXXX-XXXX") }, async ({ productNDC }) => { // Validate product NDC format if (!/^\d{5}-\d{4}$/.test(productNDC.trim())) { return { content: [{ type: "text", text: `Invalid product NDC format: "${productNDC}"\n\n✅ Required format: XXXXX-XXXX (e.g., 12345-1234)`, }], }; } const url = new OpenFDABuilder() .context("label") .search(`openfda.product_ndc:"${productNDC.trim()}"`) .limit(1) .build(); const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve drug data for product NDC "${productNDC}": ${error.message}`, }], }; } if (!drugData || !drugData.results || drugData.results.length === 0) { return { content: [{ type: "text", text: `No drug found with product NDC "${productNDC}".`, }], }; } const drug = drugData.results[0]; // Get all packages for this product const allPackagesForProduct = drug.openfda.package_ndc?.filter(ndc => ndc.startsWith(productNDC.trim()) ) || []; const drugInfo = { product_ndc: productNDC, available_packages: allPackagesForProduct, brand_name: drug.openfda.brand_name || [], generic_name: drug.openfda.generic_name || [], manufacturer_name: drug.openfda.manufacturer_name || [], product_type: drug.openfda.product_type || [], route: drug.openfda.route || [], substance_name: drug.openfda.substance_name || [], active_ingredient: drug.active_ingredient || [], purpose: drug.purpose || [], dosage_and_administration: drug.dosage_and_administration || [] }; return { content: [{ type: "text", text: `✅ Product NDC "${productNDC}" found with ${allPackagesForProduct.length} package variation(s):\n\n${JSON.stringify(drugInfo, null, 2)}`, }], }; } );