Skip to main content
Glama

get-drug-adverse-events

Retrieve adverse event reports for medications to access safety information about reported side effects and reactions using brand or generic drug names.

Instructions

Get adverse event reports for a drug. This provides safety information about reported side effects and reactions. Use brand name or generic name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
drugNameYesDrug name (brand or generic)
limitNoMaximum number of events to return
seriousnessNoFilter by event seriousnessall

Implementation Reference

  • The core handler function for the get-drug-adverse-events tool. Builds an OpenFDA API query for adverse events using the drug name, optional limit and seriousness filters. Fetches data, handles errors/no results, maps results to a user-friendly format (report ID, seriousness, patient details, reactions, etc.), and returns formatted JSON text.
    async ({ drugName, limit, seriousness }) => { let searchQuery = `patient.drug.medicinalproduct:"${drugName}"`; if (seriousness !== "all") { const serious = seriousness === "serious" ? "1" : "2"; searchQuery += `+AND+serious:${serious}`; } const url = new OpenFDABuilder() .context("event") .search(searchQuery) .limit(limit) .build(); const { data: eventData, error } = await makeOpenFDARequest<any>(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve adverse events for "${drugName}": ${error.message}`, }], }; } if (!eventData || !eventData.results || eventData.results.length === 0) { return { content: [{ type: "text", text: `No adverse events found for "${drugName}".`, }], }; } const events = eventData.results.map((event: any) => ({ report_id: event.safetyreportid, serious: event.serious === "1" ? "Yes" : "No", patient_age: event.patient?.patientonsetage || "Unknown", patient_sex: event.patient?.patientsex === "1" ? "Male" : event.patient?.patientsex === "2" ? "Female" : "Unknown", reactions: event.patient?.reaction?.map((r: any) => r.reactionmeddrapt).slice(0, 3) || [], outcomes: event.patient?.reaction?.map((r: any) => r.reactionoutcome).slice(0, 3) || [], report_date: event.receiptdate || "Unknown" })); return { content: [{ type: "text", text: `Found ${events.length} adverse event report(s) for "${drugName}":\n\n${JSON.stringify(events, null, 2)}`, }], }; }
  • Zod input schema defining parameters for the tool: drugName (required string), limit (optional number, default 10), seriousness (optional enum: serious/non-serious/all, default all).
    { drugName: z.string().describe("Drug name (brand or generic)"), limit: z.number().optional().default(10).describe("Maximum number of events to return"), seriousness: z.enum(["serious", "non-serious", "all"]).optional().default("all").describe("Filter by event seriousness") },
  • src/index.ts:201-260 (registration)
    Tool registration using server.tool() with name, description, Zod input schema, and inline async handler function.
    server.tool( "get-drug-adverse-events", "Get adverse event reports for a drug. This provides safety information about reported side effects and reactions. Use brand name or generic name.", { drugName: z.string().describe("Drug name (brand or generic)"), limit: z.number().optional().default(10).describe("Maximum number of events to return"), seriousness: z.enum(["serious", "non-serious", "all"]).optional().default("all").describe("Filter by event seriousness") }, async ({ drugName, limit, seriousness }) => { let searchQuery = `patient.drug.medicinalproduct:"${drugName}"`; if (seriousness !== "all") { const serious = seriousness === "serious" ? "1" : "2"; searchQuery += `+AND+serious:${serious}`; } const url = new OpenFDABuilder() .context("event") .search(searchQuery) .limit(limit) .build(); const { data: eventData, error } = await makeOpenFDARequest<any>(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve adverse events for "${drugName}": ${error.message}`, }], }; } if (!eventData || !eventData.results || eventData.results.length === 0) { return { content: [{ type: "text", text: `No adverse events found for "${drugName}".`, }], }; } const events = eventData.results.map((event: any) => ({ report_id: event.safetyreportid, serious: event.serious === "1" ? "Yes" : "No", patient_age: event.patient?.patientonsetage || "Unknown", patient_sex: event.patient?.patientsex === "1" ? "Male" : event.patient?.patientsex === "2" ? "Female" : "Unknown", reactions: event.patient?.reaction?.map((r: any) => r.reactionmeddrapt).slice(0, 3) || [], outcomes: event.patient?.reaction?.map((r: any) => r.reactionoutcome).slice(0, 3) || [], report_date: event.receiptdate || "Unknown" })); return { content: [{ type: "text", text: `Found ${events.length} adverse event report(s) for "${drugName}":\n\n${JSON.stringify(events, null, 2)}`, }], }; } );
  • Identical handler implementation in the built JavaScript version (bin/index.js).
    }, async ({ drugName, limit, seriousness }) => { let searchQuery = `patient.drug.medicinalproduct:"${drugName}"`; if (seriousness !== "all") { const serious = seriousness === "serious" ? "1" : "2"; searchQuery += `+AND+serious:${serious}`; } const url = new OpenFDABuilder() .context("event") .search(searchQuery) .limit(limit) .build(); const { data: eventData, error } = await makeOpenFDARequest(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve adverse events for "${drugName}": ${error.message}`, }], }; } if (!eventData || !eventData.results || eventData.results.length === 0) { return { content: [{ type: "text", text: `No adverse events found for "${drugName}".`, }], }; } const events = eventData.results.map((event) => ({ report_id: event.safetyreportid, serious: event.serious === "1" ? "Yes" : "No", patient_age: event.patient?.patientonsetage || "Unknown", patient_sex: event.patient?.patientsex === "1" ? "Male" : event.patient?.patientsex === "2" ? "Female" : "Unknown", reactions: event.patient?.reaction?.map((r) => r.reactionmeddrapt).slice(0, 3) || [], outcomes: event.patient?.reaction?.map((r) => r.reactionoutcome).slice(0, 3) || [], report_date: event.receiptdate || "Unknown" })); return { content: [{ type: "text", text: `Found ${events.length} adverse event report(s) for "${drugName}":\n\n${JSON.stringify(events, null, 2)}`, }], }; });
  • bin/index.js:174-221 (registration)
    Tool registration in the built JavaScript entry point (bin/index.js).
    server.tool("get-drug-adverse-events", "Get adverse event reports for a drug. This provides safety information about reported side effects and reactions. Use brand name or generic name.", { drugName: z.string().describe("Drug name (brand or generic)"), limit: z.number().optional().default(10).describe("Maximum number of events to return"), seriousness: z.enum(["serious", "non-serious", "all"]).optional().default("all").describe("Filter by event seriousness") }, async ({ drugName, limit, seriousness }) => { let searchQuery = `patient.drug.medicinalproduct:"${drugName}"`; if (seriousness !== "all") { const serious = seriousness === "serious" ? "1" : "2"; searchQuery += `+AND+serious:${serious}`; } const url = new OpenFDABuilder() .context("event") .search(searchQuery) .limit(limit) .build(); const { data: eventData, error } = await makeOpenFDARequest(url); if (error) { return { content: [{ type: "text", text: `Failed to retrieve adverse events for "${drugName}": ${error.message}`, }], }; } if (!eventData || !eventData.results || eventData.results.length === 0) { return { content: [{ type: "text", text: `No adverse events found for "${drugName}".`, }], }; } const events = eventData.results.map((event) => ({ report_id: event.safetyreportid, serious: event.serious === "1" ? "Yes" : "No", patient_age: event.patient?.patientonsetage || "Unknown", patient_sex: event.patient?.patientsex === "1" ? "Male" : event.patient?.patientsex === "2" ? "Female" : "Unknown", reactions: event.patient?.reaction?.map((r) => r.reactionmeddrapt).slice(0, 3) || [], outcomes: event.patient?.reaction?.map((r) => r.reactionoutcome).slice(0, 3) || [], report_date: event.receiptdate || "Unknown" })); return { content: [{ type: "text", text: `Found ${events.length} adverse event report(s) for "${drugName}":\n\n${JSON.stringify(events, null, 2)}`, }], }; });

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