bc_search_drugs_by_therapeutic_class
Search for drugs based on their exact therapeutic or pharmacologic class using FDA database terms. Identify medications by class type (epc, moa, pe, or cs) with precise matching for accurate results.
Instructions
Search for drugs by their therapeutic or pharmacologic class.
IMPORTANT: Use get_available_pharmacologic_classes() first to see the exact class terms available in the FDA database. This function requires exact matches of the pharmacologic class terms as they appear in the FDA data.
Args: therapeutic_class (str): The exact therapeutic class term from FDA database. class_type (str): Type of classification - epc, moa, pe, or cs. limit (int): Maximum number of results to return.
Returns: dict: Search results for drugs in the specified therapeutic class.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| class_type | No | Type of pharmacologic class: 'epc' (Established Pharmacologic Class), 'moa' (Mechanism of Action), 'pe' (Physiologic Effect), or 'cs' (Chemical Structure) | epc |
| limit | No | Number of results to return | |
| therapeutic_class | Yes | Exact therapeutic/pharmacologic class term from FDA database (use get_available_pharmacologic_classes first to see options) |
Implementation Reference
- The handler function for 'bc_search_drugs_by_therapeutic_class', decorated with @core_mcp.tool(). It constructs a query to the OpenFDA API using the provided therapeutic class and class_type, fetching matching drug information.@core_mcp.tool() def search_drugs_by_therapeutic_class( therapeutic_class: Annotated[ str, Field( description="Exact therapeutic/pharmacologic class term from FDA (use get_available_pharmacologic_classes first)" ), ], class_type: Annotated[ str, Field( description="Class type: 'epc' (Established Pharmacologic Class), 'moa' (Mechanism of Action), 'pe' (Physiologic Effect), or 'cs' (Chemical Structure)" ), ] = "epc", limit: Annotated[int, Field(description="Number of results to return", ge=1, le=1000)] = 25, ) -> dict: """Search for drugs by therapeutic or pharmacologic class. Use get_available_pharmacologic_classes() first for exact terms. Returns: dict: FDA drug results array with application info, products, sponsor names or error message. """ # Map class type to the appropriate OpenFDA field class_field_mapping = { "epc": "openfda.pharm_class_epc", # Established Pharmacologic Class "moa": "openfda.pharm_class_moa", # Mechanism of Action "pe": "openfda.pharm_class_pe", # Physiologic Effect "cs": "openfda.pharm_class_cs", # Chemical Structure } if class_type.lower() not in class_field_mapping: return {"error": "class_type must be one of: epc, moa, pe, cs"} field = class_field_mapping[class_type.lower()] # Use exact term as provided - no mapping since user should get this from get_available_pharmacologic_classes query = f'{field}:"{therapeutic_class}"' base_url = "https://api.fda.gov/drug/drugsfda.json" params: Any = {"search": query, "limit": limit} try: response = requests.get(base_url, params=params) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch drugs by therapeutic class: {e!s}"}
- src/biocontext_kb/core/_server.py:3-6 (registration)Definition of the core_mcp FastMCP server instance named 'BC'. Tools decorated with @core_mcp.tool() are registered here, and later imported with 'bc' prefix.core_mcp = FastMCP( # type: ignore "BC", instructions="Provides access to biomedical knowledge bases.", )
- src/biocontext_kb/core/__init__.py:13-13 (registration)Import statement that loads the openfda module, executing the @core_mcp.tool() decorator for search_drugs_by_therapeutic_class during module initialization, thus registering the tool.from .openfda import *
- src/biocontext_kb/app.py:35-39 (registration)Imports the core_mcp server (containing the tool) into the main mcp_app with namespace slugify('BC') = 'bc', resulting in the tool name 'bc_search_drugs_by_therapeutic_class'.for mcp in [core_mcp, *(await get_openapi_mcps())]: await mcp_app.import_server( mcp, slugify(mcp.name), )
- Pydantic schema definition via Annotated and Field for the tool's input parameters: therapeutic_class (required str), class_type (str, default 'epc'), limit (int, 1-1000, default 25). Output is dict from API.def search_drugs_by_therapeutic_class( therapeutic_class: Annotated[ str, Field( description="Exact therapeutic/pharmacologic class term from FDA (use get_available_pharmacologic_classes first)" ), ], class_type: Annotated[ str, Field( description="Class type: 'epc' (Established Pharmacologic Class), 'moa' (Mechanism of Action), 'pe' (Physiologic Effect), or 'cs' (Chemical Structure)" ), ] = "epc", limit: Annotated[int, Field(description="Number of results to return", ge=1, le=1000)] = 25, ) -> dict: