Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_get_generic_equivalents

Identify generic drug alternatives for brand-name medications by querying ANDA entries, including manufacturers, through verified biomedical data integration.

Instructions

Find generic equivalents for a brand name drug.

This function searches for ANDA (Abbreviated New Drug Application) entries that are generic equivalents of a specified brand name drug.

Args: brand_name (str): The brand name drug to find generics for.

Returns: dict: Generic drug equivalents and their manufacturers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
brand_nameYesBrand name drug to find generic equivalents for

Implementation Reference

  • The primary handler function for the 'get_generic_equivalents' MCP tool. Decorated with @core_mcp.tool() for automatic registration and schema inference from type annotations. Implements the logic to retrieve generic equivalents for a given brand name drug by querying the OpenFDA API.
    @core_mcp.tool() def get_generic_equivalents( brand_name: Annotated[str, Field(description="Brand name drug to find generics for")], ) -> dict: """Find generic equivalents for a brand name drug. Searches ANDA entries with matching active ingredients. Returns: dict: Brand drug info, generic_equivalents array, total_generics_found count or error message. """ # First, search for the brand name drug to get its active ingredient brand_query = f"(openfda.brand_name:{brand_name} OR products.brand_name:{brand_name})" base_url = "https://api.fda.gov/drug/drugsfda.json" brand_params: Any = {"search": brand_query, "limit": 1} try: brand_response = requests.get(base_url, params=brand_params) brand_response.raise_for_status() brand_data = brand_response.json() if not brand_data.get("results"): return {"error": f"Brand name drug '{brand_name}' not found in FDA database"} # Extract active ingredients from the brand drug brand_drug = brand_data["results"][0] # Check if we have products and active ingredients if not brand_drug.get("products"): return {"error": f"Could not find product information for '{brand_name}'"} # Search for generic drugs (ANDA applications) with similar active ingredients generic_results = [] # Try to find active ingredients from the first product for product in brand_drug["products"][:1]: # Just check first product if product.get("active_ingredients"): active_ingredients = product["active_ingredients"] # Handle case where active_ingredients might be an object or array if isinstance(active_ingredients, dict): ingredient_name = active_ingredients.get("name", "") if ingredient_name: # Search for ANDA applications with this active ingredient generic_query = ( f"application_number:ANDA* AND products.active_ingredients.name:{ingredient_name}" ) generic_params: Any = {"search": generic_query, "limit": 20} try: generic_response = requests.get(base_url, params=generic_params) generic_response.raise_for_status() generic_data = generic_response.json() if generic_data.get("results"): generic_results.extend(generic_data["results"]) except requests.exceptions.RequestException: continue # Skip this ingredient if search fails elif isinstance(active_ingredients, list): for ingredient in active_ingredients: if isinstance(ingredient, dict): ingredient_name = ingredient.get("name", "") if ingredient_name: # Search for ANDA applications with this active ingredient generic_query = ( f"application_number:ANDA* AND products.active_ingredients.name:{ingredient_name}" ) generic_params = {"search": generic_query, "limit": 20} try: generic_response = requests.get(base_url, params=generic_params) generic_response.raise_for_status() generic_data = generic_response.json() if generic_data.get("results"): generic_results.extend(generic_data["results"]) except requests.exceptions.RequestException: continue # Skip this ingredient if search fails return { "brand_drug": brand_drug, "generic_equivalents": generic_results, "total_generics_found": len(generic_results), } except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch generic equivalents: {e!s}"}
  • Input schema for the tool defined inline using Pydantic Annotated and Field for description, used by FastMCP for tool schema.
    brand_name: Annotated[str, Field(description="Brand name drug to find generics for")], ) -> dict:
  • MCP tool registration via FastMCP decorator @core_mcp.tool(), which registers the function as a tool named 'get_generic_equivalents'.
    @core_mcp.tool()
  • Python module export/import of the get_generic_equivalents function for use within the package.
    from ._advanced_search import ( get_available_pharmacologic_classes, get_generic_equivalents, search_drugs_by_therapeutic_class, ) from ._count_drugs import count_drugs_by_field, get_drug_statistics from ._get_drug_info import get_drug_by_application_number, get_drug_label_info from ._search_drugs import search_drugs_fda __all__ = [ "count_drugs_by_field", "get_available_pharmacologic_classes", "get_drug_by_application_number", "get_drug_label_info", "get_drug_statistics", "get_generic_equivalents", "search_drugs_by_therapeutic_class", "search_drugs_fda", ]

Other Tools

Related 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/biocontext-ai/knowledgebase-mcp'

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