Skip to main content
Glama
pickleton89

cBioPortal MCP Server

by pickleton89

get_molecular_profiles

Retrieve molecular profiles for a cancer study with pagination support to explore genomic data types available for analysis.

Instructions

Get a list of molecular profiles available for a specific cancer study with pagination support.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
study_idYes
page_numberNo
page_sizeNo
sort_byNo
directionNoASC
limitNo

Implementation Reference

  • Core handler function implementing the get_molecular_profiles tool logic: validates inputs, fetches data from cBioPortal API, applies client-side sorting and pagination, and formats the response.
    @handle_api_errors("get molecular profiles")
    async def get_molecular_profiles(
        self,
        study_id: str,
        page_number: int = 0,
        page_size: int = 50,
        sort_by: Optional[str] = None,
        direction: str = "ASC",
        limit: Optional[int] = None,
    ) -> Dict:
        """
        Get a list of molecular profiles available for a specific cancer study with pagination support.
        """
        # Input Validation
        validate_study_id(study_id)
        validate_page_params(page_number, page_size, limit)
        validate_sort_params(sort_by, direction)
    
        try:
            if limit == 0:
                page_size = FETCH_ALL_PAGE_SIZE
            profiles = await self.api_client.make_api_request(
                f"studies/{study_id}/molecular-profiles"
            )
            if sort_by:
                reverse = direction.upper() == "DESC"
                profiles.sort(key=lambda p: str(p.get(sort_by, "")), reverse=reverse)
            total_count = len(profiles)
            start_idx = page_number * page_size
            end_idx = start_idx + page_size
            paginated_profiles = profiles[start_idx:end_idx]
            if limit and limit > 0 and len(paginated_profiles) > limit:
                paginated_profiles = paginated_profiles[:limit]
            has_more = end_idx < total_count
            return {
                "molecular_profiles": paginated_profiles,
                "pagination": {
                    "page": page_number,
                    "page_size": page_size,
                    "total_found": total_count,
                    "has_more": has_more,
                },
            }
        except Exception as e:
            return {
                "error": f"Failed to get molecular profiles for {study_id}: {str(e)}"
            }
  • Thin wrapper method on the MCP server class that delegates to the MolecularProfilesEndpoints handler. This method is registered as the MCP tool.
    async def get_molecular_profiles(
        self,
        study_id: str,
        page_number: int = 0,
        page_size: int = 50,
        sort_by: Optional[str] = None,
        direction: str = "ASC",
        limit: Optional[int] = None,
    ) -> Dict:
        """Get a list of molecular profiles available for a specific cancer study with pagination support."""
        return await self.molecular_profiles.get_molecular_profiles(
            study_id, page_number, page_size, sort_by, direction, limit
        )
  • Registers all server methods, including get_molecular_profiles, as MCP tools using FastMCP.add_tool().
    """Register tool methods as MCP tools."""
    # List of methods to register as tools (explicitly defined)
    tool_methods = [
        # Pagination utilities
        "paginate_results",
        "collect_all_results",
        # Studies endpoints
        "get_cancer_studies",
        "get_cancer_types",
        "search_studies",
        "get_study_details",
        "get_multiple_studies",
        # Genes endpoints
        "search_genes",
        "get_genes",
        "get_multiple_genes",
        "get_mutations_in_gene",
        # Samples endpoints
        "get_samples_in_study",
        "get_sample_list_id",
        # Molecular profiles endpoints
        "get_molecular_profiles",
        "get_clinical_data",
        "get_gene_panels_for_study",
        "get_gene_panel_details",
    ]
    
    for method_name in tool_methods:
        if hasattr(self, method_name):
            method = getattr(self, method_name)
            self.mcp.add_tool(method)
            logger.debug(f"Registered tool: {method_name}")
        else:
            logger.warning(f"Method {method_name} not found for tool registration")
  • Input validation helper functions used by the get_molecular_profiles handler for study_id, pagination, and sort parameters.
    def validate_page_params(
        page_number: int,
        page_size: int,
        limit: Optional[int] = None,
    ) -> None:
        """
        Validate pagination parameters.
    
        Args:
            page_number: Page number (0-based)
            page_size: Number of items per page
            limit: Optional limit on total results
    
        Raises:
            TypeError: If parameters are not the correct type
            ValueError: If parameters have invalid values
        """
        if not isinstance(page_number, int):
            raise TypeError("page_number must be an integer")
        if page_number < 0:
            raise ValueError("page_number must be non-negative")
    
        if not isinstance(page_size, int):
            raise TypeError("page_size must be an integer")
        if page_size <= 0:
            raise ValueError("page_size must be positive")
    
        if limit is not None:
            if not isinstance(limit, int):
                raise TypeError("limit must be an integer if provided")
            if limit < 0:
                raise ValueError("limit must be non-negative if provided")
    
    
    def validate_sort_params(
        sort_by: Optional[str],
        direction: str,
    ) -> None:
        """
        Validate sorting parameters.
    
        Args:
            sort_by: Field to sort by (optional)
            direction: Sort direction (ASC or DESC)
    
        Raises:
            TypeError: If parameters are not the correct type
            ValueError: If direction is not valid
        """
        if sort_by is not None and not isinstance(sort_by, str):
            raise TypeError("sort_by must be a string if provided")
    
        if not isinstance(direction, str) or direction.upper() not in ["ASC", "DESC"]:
            raise ValueError("direction must be 'ASC' or 'DESC'")
    
    
    def validate_study_id(study_id: str) -> None:
        """
        Validate study ID parameter.
    
        Args:
            study_id: Study identifier
    
        Raises:
            TypeError: If study_id is not a string
            ValueError: If study_id is empty
        """
        if not isinstance(study_id, str):
            raise TypeError("study_id must be a string")
        if not study_id:
            raise ValueError("study_id cannot be empty")
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'pagination support,' which is useful, but fails to cover other critical traits like whether this is a read-only operation, potential rate limits, error handling, or what the output format looks like (e.g., list structure). For a tool with 6 parameters and no output schema, this is a significant gap.

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 a single, efficient sentence that front-loads the core purpose ('Get a list of molecular profiles') and adds key behavioral detail ('with pagination support'). There is no wasted verbiage, making it appropriately sized and easy to parse.

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

Completeness2/5

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

Given the complexity (6 parameters, 0% schema coverage, no output schema, no annotations), the description is incomplete. It covers the basic purpose and pagination but misses details on parameter usage, output format, error conditions, and how it differs from siblings. For a data retrieval tool in a biomedical context, more context is needed to ensure correct invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only implies 'study_id' is needed and mentions pagination, but doesn't explain the semantics of other parameters like 'sort_by', 'direction', or 'limit'. This leaves most parameters without meaningful context beyond their titles in the schema.

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 action ('Get a list') and resource ('molecular profiles available for a specific cancer study'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_clinical_data' or 'get_gene_panels_for_study', which might also retrieve study-specific data, leaving some ambiguity about uniqueness.

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 minimal guidance by mentioning 'for a specific cancer study,' but it lacks explicit when-to-use instructions, alternatives (e.g., vs. 'get_gene_panels_for_study'), or prerequisites. No context on when not to use this tool is given, leaving the agent to infer usage from the purpose alone.

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/pickleton89/cbioportal-mcp'

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