Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_search_drugs_by_therapeutic_class

Search FDA-approved drugs by therapeutic or pharmacologic class. Provide exact class term from get_available_pharmacologic_classes for precise results.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
therapeutic_classYesExact therapeutic/pharmacologic class term from FDA (use get_available_pharmacologic_classes first)
class_typeNoClass type: 'epc' (Established Pharmacologic Class), 'moa' (Mechanism of Action), 'pe' (Physiologic Effect), or 'cs' (Chemical Structure)epc
limitNoNumber of results to return

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual handler function for the 'bc_search_drugs_by_therapeutic_class' MCP tool. It queries the FDA openFDA API to search for drugs by therapeutic/pharmacologic class (EPC, MOA, PE, CS). Decorated with @core_mcp.tool().
    @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}"}
  • Pydantic/Annotated Field definitions for the tool's input parameters: therapeutic_class (str), class_type (str with default 'epc'), and limit (int with default 25). The return type is dict.
    @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.
  • The core_mcp FastMCP server instance used by the @core_mcp.tool() decorator to register the tool. This is where the tool gets registered as part of the 'BC' MCP server.
    from fastmcp import FastMCP
    
    core_mcp = FastMCP(  # type: ignore
        "BC",
        instructions="Provides access to biomedical knowledge bases.",
    )
  • The function is exported from the openfda package's __init__.py, making it part of the openfda module that is imported in core/__init__.py.
    from ._advanced_search import (
        get_available_pharmacologic_classes,
        get_generic_equivalents,
        search_drugs_by_therapeutic_class,
    )
  • Supporting tool get_available_pharmacologic_classes() in the same file is designed to be called first to get exact class terms before using search_drugs_by_therapeutic_class.
    @core_mcp.tool()
    def get_available_pharmacologic_classes(
        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 unique classes to return", ge=1, le=1000)] = 100,
    ) -> dict:
        """Get available pharmacologic classes from FDA database. Call this first to see available options.
    
        Returns:
            dict: Class type, field, available_classes array with term/count, total_found 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 the count endpoint to get unique values
        base_url = "https://api.fda.gov/drug/drugsfda.json"
        params: Any = {"count": field, "limit": limit}
    
        try:
            response = requests.get(base_url, params=params)
            response.raise_for_status()
            data = response.json()
    
            return {
                "class_type": class_type,
                "field": field,
                "available_classes": data.get("results", []),
                "total_found": len(data.get("results", [])),
            }
        except requests.exceptions.RequestException as e:
            return {"error": f"Failed to fetch available pharmacologic classes: {e!s}"}
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description is the sole source of behavioral info. It mentions returning a dictionary with FDA results or an error, but does not disclose rate limits, authentication needs, or what happens with invalid terms. Adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: two sentences covering purpose, prerequisite, and return value. No unnecessary words, well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the sibling tools, this focused search is well-defined. The output schema exists (though not visible), and the description indicates the content of the return object. Minor gaps (pagination, error types) but overall sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% coverage, so baseline is 3. The description adds value by reiterating the prerequisite for the therapeutic_class parameter, which is not in the schema, thus enhancing understanding beyond the schema alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches for drugs by therapeutic or pharmacologic class, distinguishing from siblings like bc_search_drugs_fda by specifying the search criterion.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly advises using get_available_pharmacologic_classes() first for exact terms, providing clear context on prerequisites. It lacks explicit when-not-to-use guidance but is otherwise helpful.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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