Skip to main content
Glama

get-drug-by-product-ndc

Retrieve comprehensive drug information using a product NDC code in XXXXX-XXXX format. This tool finds all package variations for a specific pharmaceutical product from the OpenFDA database.

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
NameRequiredDescriptionDefault
productNDCYesProduct NDC in format XXXXX-XXXX

Implementation Reference

  • The core handler function that implements the 'get-drug-by-product-ndc' tool logic. Validates the product NDC format, constructs OpenFDA API query for exact product NDC match in drug labels, fetches data using makeOpenFDARequest, processes results to include all matching package NDCs, and returns formatted drug information including brand, generic, manufacturer, packages, etc.
    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)}`,
        }],
      };
    }
  • Zod input schema defining the 'productNDC' parameter as a string with description specifying the required XXXXX-XXXX format.
    {
      productNDC: z.string().describe("Product NDC in format XXXXX-XXXX")
    },
  • src/index.ts:477-548 (registration)
    MCP tool registration call that registers 'get-drug-by-product-ndc' with McpServer.tool, including name, description, input schema, and handler reference.
    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)}`,
          }],
        };
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does operationally. It doesn't disclose behavioral traits like whether this is a read-only operation, what format the drug information returns, error handling, rate limits, or authentication requirements for a tool that accesses drug data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just two sentences that are front-loaded with the core purpose. Every word earns its place - the first sentence states what the tool does, and the second clarifies its scope and behavior.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple lookup tool with 100% schema coverage but no annotations or output schema, the description adequately covers the basic operation. However, it doesn't address what 'drug information' includes, the response format, or potential limitations - gaps that become more significant without structured output documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the single parameter's format. The description reinforces the format requirement but doesn't add meaningful semantic context beyond what the schema provides, such as examples of valid NDCs or what constitutes a 'product' versus 'package' NDC.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific verb ('Get drug information') and resource ('by product NDC'), and explicitly distinguishes from sibling tools by specifying it uses product NDC format and ignores package variations (unlike 'get-drug-by-ndc' which likely handles package-level NDCs).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool ('by product NDC only') and what it does ('ignores package variations and finds all packages for a product'), but doesn't explicitly mention when NOT to use it or name specific alternatives among the sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ythalorossy/openfda'

If you have feedback or need assistance with the MCP directory API, please join our Discord server