Skip to main content
Glama
pickleton89

cBioPortal MCP Server

by pickleton89

paginate_results

Handle paginated API responses from cBioPortal to retrieve complete cancer genomics datasets by managing multiple result pages automatically.

Instructions

Delegate to utils.pagination.paginate_results with api_client.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointYes
paramsNo
methodNoGET
json_dataNo
max_pagesNo

Implementation Reference

  • The MCP tool handler method for 'paginate_results'. It delegates the pagination logic to the utility function in utils.pagination, passing the server's API client.
    async def paginate_results(
        self,
        endpoint: str,
        params: Optional[Dict[str, Any]] = None,
        method: str = "GET",
        json_data: Any = None,
        max_pages: Optional[int] = None,
    ) -> AsyncGenerator[List[Dict[str, Any]], None]:
        """Delegate to utils.pagination.paginate_results with api_client."""
        async for page in paginate_results(
            self.api_client, endpoint, params, method, json_data, max_pages
        ):
            yield page
  • Core helper function implementing the pagination logic: loops through pages using pageNumber/pageSize, makes API requests via api_client.make_api_request, and yields each page of results until no more pages.
    async def paginate_results(
        api_client,
        endpoint: str,
        params: Optional[Dict[str, Any]] = None,
        method: str = "GET",
        json_data: Any = None,
        max_pages: Optional[int] = None,
    ) -> AsyncGenerator[List[Dict[str, Any]], None]:
        """
        Asynchronous generator that yields pages of results from paginated API endpoints.
    
        Args:
            api_client: The APIClient instance to use for requests
            endpoint: API endpoint path
            params: Query parameters to include in the request
            method: HTTP method (GET or POST)
            json_data: JSON data for POST requests
            max_pages: Maximum number of pages to retrieve (None for all available)
    
        Yields:
            Lists of results, one page at a time
        """
        if params is None:
            params = {}
    
        # Ensure we have pagination parameters
        page = params.get("pageNumber", 0)
        page_size = params.get("pageSize", 50)
    
        # Set pagination parameters in the request
        request_params = params.copy()
    
        page_count = 0
        has_more = True
    
        while has_more and (max_pages is None or page_count < max_pages):
            # Update page number for current request
            request_params["pageNumber"] = page
    
            # Make the API request
            results = await api_client.make_api_request(
                endpoint,
                method=method,
                params=request_params.copy(),
                json_data=json_data,
            )
    
            # Check if we got any results
            if not results or len(results) == 0:
                break
    
            yield results
    
            # Check if we have more pages
            has_more = len(results) == page_size
    
            # Increment counters
            page += 1
            page_count += 1
  • Registers 'paginate_results' (line 101) as an MCP tool by adding the instance method to FastMCP 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")

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