paginate_results
Retrieve and manage paginated data from the cBioPortal MCP Server by specifying endpoints, parameters, and methods, enabling efficient access to cancer genomics information.
Instructions
Delegate to utils.pagination.paginate_results with api_client.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | Yes | ||
| json_data | No | ||
| max_pages | No | ||
| method | No | GET | |
| params | No |
Implementation Reference
- cbioportal_mcp/server.py:132-145 (handler)MCP tool handler method for 'paginate_results' that delegates to the core pagination utility.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 implementation of the pagination logic used by the MCP tool handler.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
- cbioportal_mcp/server.py:96-131 (registration)Registers the paginate_results method as an MCP tool using FastMCP's 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")