Skip to main content
Glama
pickleton89

cBioPortal MCP Server

by pickleton89

search_genes

Find genes by symbol or name keyword in cancer genomics data with pagination and sorting options.

Instructions

Search for genes by keyword in their symbol or name with pagination support.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes
page_numberNo
page_sizeNo
sort_byNo
directionNoASC
limitNo

Implementation Reference

  • Core handler implementation of the search_genes tool in GenesEndpoints class. Performs input validation, constructs API parameters, calls the cBioPortal /genes endpoint, handles pagination metadata including 'has_more' flag and server-side limit.
    async def search_genes(
        self,
        keyword: str,
        page_number: int = 0,
        page_size: int = 50,
        sort_by: Optional[str] = None,
        direction: str = "ASC",
        limit: Optional[int] = None,
    ) -> Dict:
        """
        Search for genes by keyword in their symbol or name with pagination support.
        """
        # Input Validation
        validate_keyword(keyword)
        validate_page_params(page_number, page_size, limit)
        validate_sort_params(sort_by, direction)
    
        try:
            api_call_params = {
                "keyword": keyword,
                "pageNumber": page_number,
                "pageSize": page_size,
                "direction": direction,
            }
            if sort_by:
                api_call_params["sortBy"] = sort_by
            if limit == 0:
                api_call_params["pageSize"] = FETCH_ALL_PAGE_SIZE
    
            genes_from_api = await self.api_client.make_api_request(
                "genes", params=api_call_params
            )
    
            # Determine if the API might have more data
            api_might_have_more = len(genes_from_api) == api_call_params["pageSize"]
            # If 'fetch all' was intended and API returned less than max fetch size, then it's definitely the end.
            if (
                api_call_params["pageSize"] == FETCH_ALL_PAGE_SIZE
                and len(genes_from_api) < FETCH_ALL_PAGE_SIZE
            ):
                api_might_have_more = False
    
            # Apply server-side limit if specified (after fetching the page from API)
            genes_for_response = genes_from_api
            if limit and limit > 0 and len(genes_from_api) > limit:
                genes_for_response = genes_from_api[:limit]
    
            # total_found in pagination now means number of items in this specific response payload
            # This makes the count consistent with the actual returned data structure
            total_items_in_response = len(genes_for_response)
    
            return {
                "genes": genes_for_response,
                "pagination": {
                    "page": page_number,
                    "page_size": page_size,  # Report original requested page_size to client
                    "total_found": total_items_in_response,
                    "has_more": api_might_have_more,
                },
            }
        except Exception as e:
            return {"error": f"Failed to search genes: {str(e)}"}
  • The _register_tools method registers 'search_genes' (line 110) and other methods as MCP tools by adding them to FastMCP instance via self.mcp.add_tool().
    def _register_tools(self):
        """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")
  • Thin wrapper handler method search_genes on CBioPortalMCPServer class that delegates the call to self.genes.search_genes() - this is the method directly registered as the MCP tool.
    async def search_genes(
        self,
        keyword: str,
        page_number: int = 0,
        page_size: int = 50,
        sort_by: Optional[str] = None,
        direction: str = "ASC",
        limit: Optional[int] = None,
    ) -> Dict:
        """Search for genes by keyword in their symbol or name with pagination support."""
        return await self.genes.search_genes(
            keyword, page_number, page_size, sort_by, direction, limit
        )
  • validate_keyword function used for input validation of the keyword parameter in search_genes.
    def validate_keyword(keyword: str) -> None:
        """
        Validate keyword parameter for search operations.
    
        Args:
            keyword: Search keyword
    
        Raises:
            TypeError: If keyword is not a string
            ValueError: If keyword is empty
        """
        if not isinstance(keyword, str):
            raise TypeError("keyword must be a string")
        if not keyword:
            raise ValueError("keyword cannot be empty")
  • validate_page_params function used for input validation of pagination parameters (page_number, page_size, limit) in search_genes.
    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")
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pagination support but doesn't describe the return format, error conditions, rate limits, authentication requirements, or what happens when no matches are found. For a search tool with 6 parameters, this leaves significant behavioral gaps.

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 functionality. Every word earns its place: 'Search for genes' establishes the action and resource, 'by keyword in their symbol or name' specifies the search scope, and 'with pagination support' adds a crucial behavioral constraint.

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?

For a search tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (gene objects? IDs?), how results are structured, error handling, or the relationship between the various pagination/sorting parameters. The agent would need to guess about important behavioral aspects.

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?

With 0% schema description coverage for all 6 parameters, the description must compensate but only mentions 'keyword' and 'pagination support' (which implies page_number/page_size). It doesn't explain the meaning of 'sort_by', 'direction', or 'limit' parameters, nor does it clarify the relationship between pagination parameters and the limit parameter.

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's purpose: searching for genes by keyword in symbol or name with pagination support. It specifies the resource (genes), verb (search), and scope (keyword matching in symbol/name). However, it doesn't explicitly distinguish this from sibling tools like 'get_genes' or 'get_multiple_genes', which prevents 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. With multiple sibling tools like 'get_genes', 'get_multiple_genes', and 'paginate_results', there's no indication of when this keyword-based search is preferred over other gene retrieval methods or how it relates to the general pagination tool.

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