Skip to main content
Glama

get-drug-by-name

Retrieve comprehensive drug information from OpenFDA by brand name, including usage, warnings, manufacturer details, and safety guidelines.

Instructions

Get drug by name. Use this tool to get the drug information by name. The drug name should be the brand name. It returns the brand name, generic name, manufacturer name, product NDC, product type, route, substance name, indications and usage, warnings, do not use, ask doctor, ask doctor or pharmacist, stop use, pregnancy or breast feeding.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
drugNameYesDrug name

Implementation Reference

  • src/index.ts:71-149 (registration)
    Registration of the 'get-drug-by-name' tool using server.tool(), including the tool name, description, input schema, and inline handler function.
    server.tool(
      "get-drug-by-name",
      "Get drug by name. Use this tool to get the drug information by name. The drug name should be the brand name. It returns the brand name, generic name, manufacturer name, product NDC, product type, route, substance name, indications and usage, warnings, do not use, ask doctor, ask doctor or pharmacist, stop use, pregnancy or breast feeding.",
      {
        drugName: z.string().describe("Drug name"),
      },
      async ({ drugName }) => {
        const url = new OpenFDABuilder()
          .context("label")
          .search(`openfda.brand_name:"${drugName}"`)
          .limit(1)
          .build();
    
        const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url);
        
        if (error) {
          let errorMessage = `Failed to retrieve drug data for "${drugName}": ${error.message}`;
          
          // Provide helpful suggestions based on error type
          switch (error.type) {
            case 'http':
              if (error.status === 404) {
                errorMessage += `\n\nSuggestions:\n- Verify the exact brand name spelling\n- Try searching for the generic name instead\n- Check if the drug is FDA-approved`;
              } else if (error.status === 401 || error.status === 403) {
                errorMessage += `\n\nPlease check the API key configuration.`;
              }
              break;
            case 'network':
              errorMessage += `\n\nPlease check your internet connection and try again.`;
              break;
            case 'timeout':
              errorMessage += `\n\nThe request took too long. Please try again.`;
              break;
          }
    
          return {
            content: [{
              type: "text",
              text: errorMessage,
            }],
          };
        }
    
        if (!drugData || !drugData.results || drugData.results.length === 0) {
          return {
            content: [{
              type: "text",
              text: `No drug information found for "${drugName}". Please verify the brand name spelling or try searching for the generic name.`,
            }],
          };
        }
    
        const drug = drugData.results[0];
        const drugInfo = {
          brand_name: drug?.openfda.brand_name,
          generic_name: drug?.openfda.generic_name,
          manufacturer_name: drug?.openfda.manufacturer_name,
          product_ndc: drug?.openfda.product_ndc,
          product_type: drug?.openfda.product_type,
          route: drug?.openfda.route,
          substance_name: drug?.openfda.substance_name,
          indications_and_usage: drug?.indications_and_usage,
          warnings: drug?.warnings,
          do_not_use: drug?.do_not_use,
          ask_doctor: drug?.ask_doctor,
          ask_doctor_or_pharmacist: drug?.ask_doctor_or_pharmacist,
          stop_use: drug?.stop_use,
          pregnancy_or_breast_feeding: drug?.pregnancy_or_breast_feeding,
        };
    
        return {
          content: [{
            type: "text",
            text: `Drug information retrieved successfully:\n\n${JSON.stringify(drugInfo, null, 2)}`,
          }],
        };
      }
    );
  • The core handler function that executes the tool: builds OpenFDA API query for brand name search in label context, fetches data, handles various errors with user-friendly messages, extracts and formats key drug information (brand/generic name, manufacturer, NDC, type, route, substance, safety sections), and returns structured text response.
    async ({ drugName }) => {
      const url = new OpenFDABuilder()
        .context("label")
        .search(`openfda.brand_name:"${drugName}"`)
        .limit(1)
        .build();
    
      const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url);
      
      if (error) {
        let errorMessage = `Failed to retrieve drug data for "${drugName}": ${error.message}`;
        
        // Provide helpful suggestions based on error type
        switch (error.type) {
          case 'http':
            if (error.status === 404) {
              errorMessage += `\n\nSuggestions:\n- Verify the exact brand name spelling\n- Try searching for the generic name instead\n- Check if the drug is FDA-approved`;
            } else if (error.status === 401 || error.status === 403) {
              errorMessage += `\n\nPlease check the API key configuration.`;
            }
            break;
          case 'network':
            errorMessage += `\n\nPlease check your internet connection and try again.`;
            break;
          case 'timeout':
            errorMessage += `\n\nThe request took too long. Please try again.`;
            break;
        }
    
        return {
          content: [{
            type: "text",
            text: errorMessage,
          }],
        };
      }
    
      if (!drugData || !drugData.results || drugData.results.length === 0) {
        return {
          content: [{
            type: "text",
            text: `No drug information found for "${drugName}". Please verify the brand name spelling or try searching for the generic name.`,
          }],
        };
      }
    
      const drug = drugData.results[0];
      const drugInfo = {
        brand_name: drug?.openfda.brand_name,
        generic_name: drug?.openfda.generic_name,
        manufacturer_name: drug?.openfda.manufacturer_name,
        product_ndc: drug?.openfda.product_ndc,
        product_type: drug?.openfda.product_type,
        route: drug?.openfda.route,
        substance_name: drug?.openfda.substance_name,
        indications_and_usage: drug?.indications_and_usage,
        warnings: drug?.warnings,
        do_not_use: drug?.do_not_use,
        ask_doctor: drug?.ask_doctor,
        ask_doctor_or_pharmacist: drug?.ask_doctor_or_pharmacist,
        stop_use: drug?.stop_use,
        pregnancy_or_breast_feeding: drug?.pregnancy_or_breast_feeding,
      };
    
      return {
        content: [{
          type: "text",
          text: `Drug information retrieved successfully:\n\n${JSON.stringify(drugInfo, null, 2)}`,
        }],
      };
    }
  • Input schema using Zod: defines 'drugName' as a required string parameter.
    {
      drugName: z.string().describe("Drug name"),
    },
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the return values (e.g., brand name, generic name, manufacturer name) and specifies that the input should be a brand name, which adds useful context. However, it doesn't cover potential errors, rate limits, or authentication needs, leaving gaps in behavioral transparency.

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

Conciseness4/5

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

The description is front-loaded with the core purpose and usage, followed by a detailed list of return values. While the list of return values is lengthy, each item is relevant to the tool's function. The structure is efficient, with no redundant sentences, though it could be slightly more concise by grouping related return categories.

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?

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description is adequate but has gaps. It explains the purpose, input semantics, and return values, but lacks error handling, performance expectations, or integration with sibling tools. Without annotations or output schema, more behavioral context would improve completeness.

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

Parameters4/5

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

The input schema has 100% description coverage, with the parameter 'drugName' documented as 'Drug name.' The description adds semantic value by clarifying that 'The drug name should be the brand name,' which provides crucial context beyond the schema. Since there's only one parameter, this compensation is effective, warranting a score above the baseline.

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

Purpose4/5

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

The description clearly states the tool's purpose as 'Get drug by name' and specifies it retrieves drug information, which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'get-drug-by-generic-name' or 'get-drug-by-ndc' beyond mentioning 'brand name' in the description.

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

Usage Guidelines3/5

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

The description provides some guidance by stating 'The drug name should be the brand name,' which implies when to use this tool versus alternatives like 'get-drug-by-generic-name.' However, it lacks explicit when-not-to-use instructions or clear alternatives, leaving usage context somewhat implied rather than fully articulated.

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