Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_get_studies_by_intervention

Search clinical trials by drug or therapy name with filters for condition, phase, and status to find relevant studies with paginated results and breakdowns.

Instructions

Search trials by intervention with condition and phase filters. Returns paginated results with breakdowns.

Returns: dict: Studies list with summary containing intervention searched, total studies, status/phase breakdowns, top conditions/sponsors or error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
interventionYesDrug/therapy name (e.g., 'aspirin', 'pembrolizumab', 'radiation')
conditionNoMedical condition filter (e.g., 'cancer')
phaseNo'PHASE1', 'PHASE2', 'PHASE3', 'PHASE4', or 'EARLY_PHASE1'
statusNo'RECRUITING', 'ACTIVE_NOT_RECRUITING', 'COMPLETED', or 'ALL'ALL
intervention_typeNo'DRUG', 'BIOLOGICAL', 'DEVICE', 'PROCEDURE', 'RADIATION', 'BEHAVIORAL', or 'ALL'ALL
page_sizeNoResults per page (1-1000)
sortNo'LastUpdatePostDate:desc', 'StudyFirstPostDate:desc', or 'EnrollmentCount:desc'LastUpdatePostDate:desc

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function get_studies_by_intervention decorated with @core_mcp.tool(). Queries ClinicalTrials.gov API for studies matching the intervention (e.g., drug name), with optional filters for condition, phase, status, intervention_type. Processes response to include summary breakdowns (status, phase, conditions, sponsors). Tool name prefixed to 'bc_get_studies_by_intervention' via server import.
    @core_mcp.tool()
    def get_studies_by_intervention(
        intervention: Annotated[
            str,
            Field(description="Drug/therapy name (e.g., 'aspirin', 'pembrolizumab', 'radiation')"),
        ],
        condition: Annotated[Optional[str], Field(description="Medical condition filter (e.g., 'cancer')")] = None,
        phase: Annotated[
            Optional[str], Field(description="'PHASE1', 'PHASE2', 'PHASE3', 'PHASE4', or 'EARLY_PHASE1'")
        ] = None,
        status: Annotated[
            Optional[str], Field(description="'RECRUITING', 'ACTIVE_NOT_RECRUITING', 'COMPLETED', or 'ALL'")
        ] = "ALL",
        intervention_type: Annotated[
            Optional[str],
            Field(description="'DRUG', 'BIOLOGICAL', 'DEVICE', 'PROCEDURE', 'RADIATION', 'BEHAVIORAL', or 'ALL'"),
        ] = "ALL",
        page_size: Annotated[int, Field(description="Results per page (1-1000)", ge=1, le=1000)] = 50,
        sort: Annotated[
            str,
            Field(description="'LastUpdatePostDate:desc', 'StudyFirstPostDate:desc', or 'EnrollmentCount:desc'"),
        ] = "LastUpdatePostDate:desc",
    ) -> Union[Dict[str, Any], dict]:
        """Search trials by intervention with condition and phase filters. Returns paginated results with breakdowns.
    
        Returns:
            dict: Studies list with summary containing intervention searched, total studies, status/phase breakdowns, top conditions/sponsors or error message.
        """
        if not intervention:
            return {"error": "Intervention name must be provided"}
    
        # Build query components
        query_parts = [f"AREA[InterventionName]{intervention}"]
    
        if condition:
            query_parts.append(f"AREA[ConditionSearch]{condition}")
    
        if phase:
            query_parts.append(f"AREA[Phase]{phase}")
    
        if status and status != "ALL":
            query_parts.append(f"AREA[OverallStatus]{status}")
    
        if intervention_type and intervention_type != "ALL":
            query_parts.append(f"AREA[InterventionType]{intervention_type}")
    
        # Join query parts with AND
        query = " AND ".join(query_parts)
    
        url = f"https://clinicaltrials.gov/api/v2/studies?query.term={query}&pageSize={page_size}&sort={sort}&format=json"
    
        try:
            response = requests.get(url)
            response.raise_for_status()
            data = response.json()
    
            # Add summary statistics
            if "studies" in data:
                total_studies = data.get("totalCount", len(data["studies"]))
    
                # Count studies by various attributes
                status_counts: dict[str, int] = {}
                phase_counts: dict[str, int] = {}
                condition_counts: dict[str, int] = {}
                sponsor_counts: dict[str, int] = {}
    
                for study in data["studies"]:
                    # Extract status
                    status_module = study.get("protocolSection", {}).get("statusModule", {})
                    study_status = status_module.get("overallStatus", "Unknown")
                    status_counts[study_status] = status_counts.get(study_status, 0) + 1
    
                    # Extract phase
                    design_module = study.get("protocolSection", {}).get("designModule", {})
                    phases = design_module.get("phases", [])
                    if phases:
                        for phase_item in phases:
                            phase_counts[phase_item] = phase_counts.get(phase_item, 0) + 1
                    else:
                        phase_counts["N/A"] = phase_counts.get("N/A", 0) + 1
    
                    # Extract primary conditions
                    conditions_module = study.get("protocolSection", {}).get("conditionsModule", {})
                    conditions = conditions_module.get("conditions", [])
                    if conditions:
                        for cond in conditions[:3]:  # Limit to first 3 conditions
                            condition_counts[cond] = condition_counts.get(cond, 0) + 1
    
                    # Extract lead sponsor
                    sponsor_module = study.get("protocolSection", {}).get("sponsorCollaboratorsModule", {})
                    lead_sponsor = sponsor_module.get("leadSponsor", {}).get("name", "Unknown")
                    sponsor_counts[lead_sponsor] = sponsor_counts.get(lead_sponsor, 0) + 1
    
                # Add summary to response
                data["summary"] = {
                    "intervention_searched": intervention,
                    "total_studies": total_studies,
                    "studies_returned": len(data["studies"]),
                    "status_breakdown": status_counts,
                    "phase_breakdown": phase_counts,
                    "top_conditions": dict(sorted(condition_counts.items(), key=lambda x: x[1], reverse=True)[:10]),
                    "top_sponsors": dict(sorted(sponsor_counts.items(), key=lambda x: x[1], reverse=True)[:10]),
                }
    
            return data
        except requests.exceptions.RequestException as e:
            return {"error": f"Failed to fetch studies by intervention: {e!s}"}
  • Pydantic-based input schema defined via Annotated[ ] and Field( ) descriptions for the tool parameters.
    def get_studies_by_intervention(
        intervention: Annotated[
            str,
            Field(description="Drug/therapy name (e.g., 'aspirin', 'pembrolizumab', 'radiation')"),
        ],
        condition: Annotated[Optional[str], Field(description="Medical condition filter (e.g., 'cancer')")] = None,
        phase: Annotated[
            Optional[str], Field(description="'PHASE1', 'PHASE2', 'PHASE3', 'PHASE4', or 'EARLY_PHASE1'")
        ] = None,
        status: Annotated[
            Optional[str], Field(description="'RECRUITING', 'ACTIVE_NOT_RECRUITING', 'COMPLETED', or 'ALL'")
        ] = "ALL",
        intervention_type: Annotated[
            Optional[str],
            Field(description="'DRUG', 'BIOLOGICAL', 'DEVICE', 'PROCEDURE', 'RADIATION', 'BEHAVIORAL', or 'ALL'"),
        ] = "ALL",
        page_size: Annotated[int, Field(description="Results per page (1-1000)", ge=1, le=1000)] = 50,
        sort: Annotated[
            str,
            Field(description="'LastUpdatePostDate:desc', 'StudyFirstPostDate:desc', or 'EnrollmentCount:desc'"),
        ] = "LastUpdatePostDate:desc",
    ) -> Union[Dict[str, Any], dict]:
  • Explicit import of the tool handler function in the clinicaltrials package __init__.py, which executes the @tool() decorator registration.
    from ._get_studies_by_intervention import get_studies_by_intervention
  • Imports all clinicaltrials tools in core package __init__.py, importing the function and triggering its registration on core_mcp.
    from .clinicaltrials import *
  • Main app.py imports core_mcp into the root FastMCP server with prefix slugify('BC')='bc', making the tool available as 'bc_get_studies_by_intervention'.
    for mcp in [core_mcp, *(await get_openapi_mcps())]:
        await mcp_app.import_server(
            mcp,
            slugify(mcp.name),
        )
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that results are paginated and include breakdowns, which adds useful behavioral context beyond the input schema. However, it doesn't mention rate limits, authentication requirements, or potential side effects like data freshness or API constraints. The description doesn't contradict any annotations (since none exist).

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

Conciseness4/5

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

The description is appropriately concise with two sentences: one stating the purpose and key filters, and another describing the return format. It's front-loaded with the core functionality. There's minimal waste, though the 'Returns:' section could be slightly more integrated.

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 tool's complexity (7 parameters, search functionality) and the presence of an output schema (implied by 'Has output schema: true'), the description is reasonably complete. It covers the core purpose, key filters, and return characteristics. With no annotations, it could benefit from more behavioral details, but the output schema reduces the need to fully describe return values.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents all 7 parameters. The description adds marginal value by mentioning 'condition and phase filters' and 'paginated results', but doesn't provide additional semantic context beyond what's in the schema descriptions. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the tool searches trials by intervention with filters and returns paginated results with breakdowns. It specifies the verb ('search'), resource ('trials'), and key parameters ('intervention', 'condition', 'phase'). However, it doesn't explicitly differentiate from sibling tools like 'bc_get_studies_by_condition' or 'bc_search_studies', which would be needed for a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'bc_get_studies_by_condition' or 'bc_search_studies'. It mentions filters but doesn't specify scenarios where this tool is preferred over other study-related tools in the sibling list. No exclusions or prerequisites are mentioned.

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