Skip to main content
Glama

check-drug-interactions

Identify potential drug-drug interactions between two medications to help prevent adverse effects and ensure medication safety.

Instructions

Check for potential drug-drug interactions between two medications

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
drug1YesFirst drug name
drug2YesSecond drug name

Implementation Reference

  • src/index.ts:215-230 (registration)
    Registration of the 'check-drug-interactions' tool with MCP server, including inline input schema (zod) and thin wrapper handler that delegates to core logic.
    server.tool( "check-drug-interactions", "Check for potential drug-drug interactions between two medications", { drug1: z.string().describe("First drug name"), drug2: z.string().describe("Second drug name"), }, async ({ drug1, drug2 }) => { try { const interactions = await checkDrugInteractions(drug1, drug2); return formatDrugInteractions(interactions, drug1, drug2); } catch (error: any) { return createErrorResponse("checking drug interactions", error); } }, );
  • Core handler implementation: Queries PubMed API for literature on drug interactions between the two input drugs, parses abstracts to detect interactions, classifies severity, extracts clinical effects and management advice.
    export async function checkDrugInteractions( drug1: string, drug2: string, ): Promise<DrugInteraction[]> { try { // Search for interaction studies between the two drugs const interactionTerms = [ `"${drug1}" AND "${drug2}" AND "interaction"`, `"${drug1}" AND "${drug2}" AND "contraindication"`, `"${drug1}" AND "${drug2}" AND "adverse"`, ]; const interactions: DrugInteraction[] = []; for (const term of interactionTerms) { try { const searchRes = await superagent .get(`${PUBMED_API_BASE}/esearch.fcgi`) .query({ db: "pubmed", term: term, retmode: "json", retmax: 3, }) .set("User-Agent", USER_AGENT); const idList = searchRes.body.esearchresult?.idlist || []; if (idList.length > 0) { const fetchRes = await superagent .get(`${PUBMED_API_BASE}/efetch.fcgi`) .query({ db: "pubmed", id: idList.join(","), retmode: "xml", }) .set("User-Agent", USER_AGENT); const articles = parsePubMedXML(fetchRes.text); for (const article of articles) { const abstract = (article.abstract || "").toLowerCase(); if ( (abstract.includes("interaction") || abstract.includes("contraindication")) && !abstract.includes("no interaction") && !abstract.includes("safe combination") && !abstract.includes("no contraindication") && !abstract.includes("can be used together") ) { let severity: "Minor" | "Moderate" | "Major" | "Contraindicated" = "Moderate"; // More careful severity assessment if ( abstract.includes("contraindicated") || abstract.includes("avoid") ) { severity = "Contraindicated"; } else if ( abstract.includes("severe") || abstract.includes("major") ) { severity = "Major"; } else if ( abstract.includes("minor") || abstract.includes("mild") ) { severity = "Minor"; } // Avoid duplicates const existingInteraction = interactions.find( (i) => i.drug1 === drug1 && i.drug2 === drug2, ); if (!existingInteraction) { // Extract specific clinical effects from the abstract const clinicalEffects = extractClinicalEffects(abstract); const management = extractManagementAdvice(abstract); interactions.push({ drug1, drug2, severity, description: `Interaction between ${drug1} and ${drug2} - see referenced literature`, clinical_effects: clinicalEffects || "See referenced literature for clinical effects", management: management || "Consult healthcare provider before combining medications", evidence_level: "Literature Review", }); } } } } } catch (error) { console.error(`Error checking interactions for term: ${term}`, error); } } return interactions; } catch (error) { console.error("Error checking drug interactions:", error); return []; } }
  • Type definition for DrugInteraction results returned by the handler.
    export type DrugInteraction = { drug1: string; drug2: string; severity: "Minor" | "Moderate" | "Major" | "Contraindicated"; description: string; clinical_effects: string; management: string; evidence_level: string; };
  • Helper function to format DrugInteraction results into a user-friendly MCP text response.
    export function formatDrugInteractions( interactions: any[], drug1: string, drug2: string, ) { if (interactions.length === 0) { return createMCPResponse( `No significant drug interactions found between ${drug1} and ${drug2}. However, always consult a healthcare provider before combining medications.`, ); } let result = `**Drug Interaction Check: ${drug1} + ${drug2}**\n\n`; result += `Found ${interactions.length} interaction(s)\n\n`; interactions.forEach((interaction, index) => { result += `${index + 1}. **${interaction.severity} Interaction**\n`; result += ` Description: ${interaction.description}\n`; if (interaction.clinical_effects) { result += ` Clinical Effects: ${interaction.clinical_effects}\n`; } if (interaction.management) { result += ` Management: ${interaction.management}\n`; } result += "\n"; }); return createMCPResponse(result); }

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/JamesANZ/medical-mcp'

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