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"), },

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