Skip to main content
Glama

get-drug-by-generic-name

Find drug information using generic ingredient names. Retrieve all brand versions and details for medications when you know the active component but not specific products.

Instructions

Get drug information by generic (active ingredient) name. Useful when you know the generic name but not the brand name. Returns all brand versions of the generic drug.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
genericNameYesGeneric drug name (active ingredient)
limitNoMaximum number of results to return

Implementation Reference

  • The core handler function for the 'get-drug-by-generic-name' tool. It constructs an OpenFDA API query using OpenFDABuilder for the given generic name, fetches data via makeOpenFDARequest, handles errors and empty results, maps the response to simplified drug objects (brand_name, generic_name, manufacturer, product_type, route), and returns a formatted text response with the results.
    async ({ genericName, limit }) => {
      const url = new OpenFDABuilder()
        .context("label")
        .search(`openfda.generic_name:"${genericName}"`)
        .limit(limit)
        .build();
    
      const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url);
      
      if (error) {
        return {
          content: [{
            type: "text",
            text: `Failed to retrieve drug data for generic name "${genericName}": ${error.message}`,
          }],
        };
      }
    
      if (!drugData || !drugData.results || drugData.results.length === 0) {
        return {
          content: [{
            type: "text",
            text: `No drug information found for generic name "${genericName}".`,
          }],
        };
      }
    
      const drugs = drugData.results.map(drug => ({
        brand_name: drug?.openfda.brand_name?.[0] || 'Unknown',
        generic_name: drug?.openfda.generic_name?.[0] || 'Unknown',
        manufacturer_name: drug?.openfda.manufacturer_name?.[0] || 'Unknown',
        product_type: drug?.openfda.product_type?.[0] || 'Unknown',
        route: drug?.openfda.route || [],
      }));
    
      return {
        content: [{
          type: "text",
          text: `Found ${drugs.length} drug(s) with generic name "${genericName}":\n\n${JSON.stringify(drugs, null, 2)}`,
        }],
      };
    }
  • Zod input schema validation for the tool parameters: genericName (required string) and optional limit (number, defaults to 5).
    {
      genericName: z.string().describe("Generic drug name (active ingredient)"),
      limit: z.number().optional().default(5).describe("Maximum number of results to return")
    },
  • src/index.ts:150-199 (registration)
    MCP server tool registration call that defines the tool name, description, input schema, and attaches the handler function.
    server.tool(
      "get-drug-by-generic-name",
      "Get drug information by generic (active ingredient) name. Useful when you know the generic name but not the brand name. Returns all brand versions of the generic drug.",
      {
        genericName: z.string().describe("Generic drug name (active ingredient)"),
        limit: z.number().optional().default(5).describe("Maximum number of results to return")
      },
      async ({ genericName, limit }) => {
        const url = new OpenFDABuilder()
          .context("label")
          .search(`openfda.generic_name:"${genericName}"`)
          .limit(limit)
          .build();
    
        const { data: drugData, error } = await makeOpenFDARequest<OpenFDAResponse>(url);
        
        if (error) {
          return {
            content: [{
              type: "text",
              text: `Failed to retrieve drug data for generic name "${genericName}": ${error.message}`,
            }],
          };
        }
    
        if (!drugData || !drugData.results || drugData.results.length === 0) {
          return {
            content: [{
              type: "text",
              text: `No drug information found for generic name "${genericName}".`,
            }],
          };
        }
    
        const drugs = drugData.results.map(drug => ({
          brand_name: drug?.openfda.brand_name?.[0] || 'Unknown',
          generic_name: drug?.openfda.generic_name?.[0] || 'Unknown',
          manufacturer_name: drug?.openfda.manufacturer_name?.[0] || 'Unknown',
          product_type: drug?.openfda.product_type?.[0] || 'Unknown',
          route: drug?.openfda.route || [],
        }));
    
        return {
          content: [{
            type: "text",
            text: `Found ${drugs.length} drug(s) with generic name "${genericName}":\n\n${JSON.stringify(drugs, null, 2)}`,
          }],
        };
      }
    );
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. It discloses that the tool returns 'all brand versions of the generic drug,' which adds useful behavioral context beyond the input schema. However, it lacks details on error handling, rate limits, authentication needs, or what specific information is included in the response. For a read-only tool with no annotations, this is adequate but not comprehensive.

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 two sentences, front-loaded with the core purpose, followed by usage context and return behavior. Every sentence adds value without redundancy, making it efficient and well-structured.

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

Completeness4/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 (2 parameters, no output schema, no annotations), the description is reasonably complete. It covers purpose, usage context, and return behavior. However, without an output schema, it could benefit from more detail on the response format (e.g., structure of returned drug information).

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 fully documents both parameters (genericName and limit). The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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 tool's purpose: 'Get drug information by generic (active ingredient) name.' It specifies the verb ('Get'), resource ('drug information'), and key constraint ('by generic name'). It also distinguishes from siblings by emphasizing generic name lookup versus brand name or NDC-based alternatives.

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 for when to use this tool: 'Useful when you know the generic name but not the brand name.' This gives practical guidance. However, it does not explicitly state when not to use it or name specific alternatives among the sibling tools (e.g., get-drug-by-name for brand names).

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