pickleton89/cbioportal-mcp
If you are the rightful owner of cbioportal-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The cBioPortal MCP Server is a high-performance, production-ready Model Context Protocol (MCP) server designed to facilitate seamless interaction between AI assistants and cancer genomics data from cBioPortal.
get_cancer_studies
List all available cancer studies with pagination and filtering.
search_studies
Search studies by keyword with full-text search and sorting.
get_study_details
Retrieve detailed study information with comprehensive metadata.
get_samples_in_study
Fetch samples for specific studies with paginated results.
get_genes
Retrieve gene information by ID or symbol with flexible identifiers.
๐งฌ cBioPortal MCP Server
A high-performance, production-ready Model Context Protocol (MCP) server that enables AI assistants to seamlessly interact with cancer genomics data from cBioPortal. Built with modern async Python architecture and modular design for enterprise-grade reliability and 4.5x faster performance.
๐ Overview & Key Features
๐ Performance & Architecture
- โก 4.5x Performance Boost: Full async implementation with concurrent API operations
- ๐๏ธ Modular Architecture: Professional structure with 71% code reduction (1,357 โ 396 lines)
- ๐ฆ Modern Package Management: uv-based workflow with pyproject.toml
- ๐ Concurrent Operations: Bulk fetching of studies and genes with automatic batching
๐ง Enterprise Features
- โ๏ธ Multi-layer Configuration: CLI args โ Environment variables โ YAML config โ Defaults
- ๐ Comprehensive Testing: 92 tests across 8 organized test suites with full coverage
- ๐ก๏ธ Input Validation: Robust parameter validation and error handling
- ๐ Pagination Support: Efficient data retrieval with automatic pagination
๐งฌ Cancer Genomics Capabilities
- ๐ Study Management: Browse, search, and analyze cancer studies
- ๐งช Molecular Data: Access mutations, clinical data, and molecular profiles
- ๐ Bulk Operations: Concurrent fetching of multiple entities
- ๐ Advanced Search: Keyword-based discovery across studies and genes
๐ง ๐ค AI-Collaborative Development
This project demonstrates cutting-edge human-AI collaboration in bioinformatics software development:
- ๐ง Domain Expertise: 20+ years cancer research experience guided architecture and feature requirements
- ๐ค AI Implementation: Advanced code generation, API design, and performance optimization through systematic LLM collaboration
- ๐ Quality Assurance: Iterative refinement ensuring professional standards and production reliability
- ๐ Innovation Approach: Showcases how domain experts can effectively leverage AI tools to build enterprise-grade bioinformatics platforms
Methodology: This collaborative approach combines deep biological domain knowledge with AI-powered development capabilities, accelerating innovation while maintaining rigorous code quality and scientific accuracy.
๐ Quick Start
Prerequisites
- Python 3.10+ ๐
- uv (modern package manager) - recommended ๐ฆ
- Git (optional, for cloning)
โก Installation & Launch
# Install uv if needed
pipx install uv
# Clone and setup
git clone https://github.com/pickleton89/cbioportal-mcp.git
cd cbioportal-mcp
uv sync
# Launch server
uv run cbioportal-mcp
That's it! ๐ Your server is running and ready for AI assistant connections.
๐ฆ Installation Options
๐ฅ Option 1: uv (Recommended)
Modern, lightning-fast package management with automatic environment handling:
# Install uv
pipx install uv
# Or with Homebrew: brew install uv
# Clone repository
git clone https://github.com/pickleton89/cbioportal-mcp.git
cd cbioportal-mcp
# One-command setup (creates venv + installs dependencies)
uv sync
# Alternative: development mode with all dev dependencies
uv sync --group dev
๐ Option 2: pip (Traditional)
Standard Python package management approach:
# Create virtual environment
python -m venv cbioportal-mcp-env
# Activate environment
# Windows: cbioportal-mcp-env\Scripts\activate
# macOS/Linux: source cbioportal-mcp-env/bin/activate
# Install dependencies
pip install -e .
โ๏ธ Configuration
๐๏ธ Multi-Layer Configuration System
The server supports flexible configuration with priority: CLI args > Environment variables > Config file > Defaults
YAML Configuration ๐
Create config.yaml
for persistent settings:
# cBioPortal MCP Server Configuration
server:
base_url: "https://www.cbioportal.org/api"
transport: "stdio"
logging:
level: "INFO"
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
api:
timeout: 480
max_retries: 3
rate_limit: 100
# Performance settings
performance:
concurrent_batch_size: 10
max_concurrent_requests: 20
Environment Variables ๐
export CBIOPORTAL_BASE_URL="https://custom-instance.org/api"
export CBIOPORTAL_LOG_LEVEL="DEBUG"
export CBIOPORTAL_TIMEOUT=600
CLI Options ๐ป
# Basic usage
uv run cbioportal-mcp
# Custom configuration
uv run cbioportal-mcp --config config.yaml --log-level DEBUG
# Custom API endpoint
uv run cbioportal-mcp --base-url https://custom-instance.org/api
# Generate example config
uv run cbioportal-mcp --create-example-config
๐ Usage & Integration
๐ฅ๏ธ Claude Desktop Integration
Configure in your Claude Desktop MCP settings:
{
"mcpServers": {
"cbioportal": {
"command": "uv",
"args": ["run", "cbioportal-mcp"],
"cwd": "/path/to/cbioportal-mcp",
"env": {
"CBIOPORTAL_LOG_LEVEL": "INFO"
}
}
}
}
๐ง VS Code Integration
Add to your workspace settings:
{
"mcp.servers": {
"cbioportal": {
"command": "uv",
"args": ["run", "cbioportal-mcp"],
"cwd": "/path/to/cbioportal-mcp"
}
}
}
๐โโ๏ธ Command Line Usage
# Development server with debug logging
uv run python cbioportal_server.py --log-level DEBUG
# Production server with custom config
uv run cbioportal-mcp --config production.yaml
# Using custom cBioPortal instance
uv run cbioportal-mcp --base-url https://private-instance.org/api
๐๏ธ Architecture
๐ Modern Project Structure
cbioportal-mcp/
โโโ ๐ cbioportal_server.py # Main MCP server (396 lines - 71% reduction!)
โโโ ๐ api_client.py # Dedicated HTTP client class
โโโ โ๏ธ config.py # Multi-layer configuration system
โโโ ๐ constants.py # Centralized constants
โโโ ๐ endpoints/ # Domain-specific API modules
โ โโโ ๐ฌ studies.py # Cancer studies & search
โ โโโ ๐งฌ genes.py # Gene operations & mutations
โ โโโ ๐งช samples.py # Sample data management
โ โโโ ๐ molecular_profiles.py # Molecular & clinical data
โโโ ๐ utils/ # Shared utilities
โ โโโ ๐ pagination.py # Efficient pagination logic
โ โโโ โ
validation.py # Input validation
โ โโโ ๐ logging.py # Logging configuration
โโโ ๐ tests/ # Comprehensive test suite (92 tests)
โโโ ๐ docs/ # Documentation
โโโ ๐ scripts/ # Development utilities
โโโ ๐ pyproject.toml # Modern Python project config
๐ฏ Design Principles
- ๐ง Modular: Clear separation of concerns with domain-specific modules
- โก Async-First: Full asynchronous implementation for maximum performance
- ๐ก๏ธ Robust: Comprehensive input validation and error handling
- ๐งช Testable: 92 tests ensuring reliability and preventing regressions
- ๐ Maintainable: Clean code architecture with 71% reduction in complexity
๐ ๏ธ Available Tools
The server provides 12 high-performance tools for AI assistants:
๐ง Tool | ๐ Description | โก Features |
---|---|---|
get_cancer_studies | List all available cancer studies | ๐ Pagination, ๐ Filtering |
search_studies | Search studies by keyword | ๐ Full-text search, ๐ Sorting |
get_study_details | Detailed study information | ๐ Comprehensive metadata |
get_samples_in_study | Samples for specific studies | ๐ Paginated results |
get_genes | Gene information by ID/symbol | ๐ท๏ธ Flexible identifiers |
search_genes | Search genes by keyword | ๐ Symbol & name search |
get_mutations_in_gene | Gene mutations in studies | ๐งฌ Mutation details |
get_clinical_data | Patient clinical information | ๐ฅ Patient-centric data |
get_molecular_profiles | Study molecular profiles | ๐ Profile metadata |
get_multiple_studies | ๐ Concurrent study fetching | โก Bulk operations |
get_multiple_genes | ๐ Concurrent gene retrieval | ๐ฆ Automatic batching |
get_gene_panels_for_study | Gene panels in studies | ๐งฌ Panel information |
๐ Performance Features
- โก Concurrent Operations:
get_multiple_*
methods useasyncio.gather
for parallel processing - ๐ฆ Smart Batching: Automatic batching for large gene lists
- ๐ Efficient Pagination: Async generators for memory-efficient data streaming
- โฑ๏ธ Performance Metrics: Execution timing and batch count reporting
๐ Performance
๐ Benchmark Results
Our async implementation delivers significant performance improvements:
๐โโ๏ธ Sequential Study Fetching: 1.31 seconds (10 studies)
โก Concurrent Study Fetching: 0.29 seconds (10 studies)
๐ฏ Performance Improvement: 4.57x faster!
๐ฅ Async Benefits
- ๐ 4.5x Faster: Concurrent API requests vs sequential operations
- ๐ฆ Bulk Processing: Efficient batched operations for multiple entities
- โฑ๏ธ Non-blocking: Asynchronous I/O prevents request blocking
- ๐งฎ Smart Batching: Automatic optimization for large datasets
๐ก Performance Tips
- Use
get_multiple_studies
for fetching multiple studies concurrently - Leverage
get_multiple_genes
with automatic batching for gene lists - Configure
concurrent_batch_size
in config for optimal performance - Monitor execution metrics included in response metadata
๐จโ๐ป Development
๐จ Development Workflow
# Setup development environment
uv sync --group dev
# Run tests
uv run pytest
# Run with coverage
uv run pytest --cov=.
# Run specific test file
uv run pytest tests/test_server_lifecycle.py
# Update snapshots
uv run pytest --snapshot-update
# Lint code
uv run ruff check .
# Format code
uv run ruff format .
๐งช Testing
Comprehensive test suite with 92 tests across 8 categories:
- ๐
test_server_lifecycle.py
- Server startup/shutdown & tool registration - ๐
test_pagination.py
- Pagination logic & edge cases - ๐
test_multiple_entity_apis.py
- Concurrent operations & bulk fetching - โ
test_input_validation.py
- Parameter validation & error handling - ๐ธ
test_snapshot_responses.py
- API response consistency (syrupy) - ๐ป
test_cli.py
- Command-line interface & argument parsing - ๐ก๏ธ
test_error_handling.py
- Error scenarios & network issues - โ๏ธ
test_configuration.py
- Configuration system validation
๐ ๏ธ Development Tools
- ๐ฆ uv: Modern package management (10-100x faster than pip)
- ๐งช pytest: Testing framework with async support
- ๐ธ syrupy: Snapshot testing for API responses
- ๐ ruff: Lightning-fast linting and formatting
- ๐ pytest-cov: Code coverage reporting
๐ค Contributing
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature
) - โ
Test your changes (
uv run pytest
) - ๐ Commit with clear messages (
git commit -m 'Add amazing feature'
) - ๐ Push to branch (
git push origin feature/amazing-feature
) - ๐ Create a Pull Request
๐ง Troubleshooting
๐จ Common Issues
Server Fails to Start
# Check Python version
python --version # Should be 3.10+
# Verify dependencies
uv sync
# Check for conflicts
uv run python -c "import mcp, httpx, fastmcp; print('Dependencies OK')"
Claude Desktop Connection Issues
- โ Verify paths in MCP configuration are absolute
- โ
Check that
uv
is in your system PATH - โ
Ensure
cwd
points to project directory - โ Review Claude Desktop logs for detailed errors
Performance Issues
- ๐ง Increase
concurrent_batch_size
in config - ๐ง Adjust
max_concurrent_requests
for your system - ๐ง Use
get_multiple_*
methods for bulk operations - ๐ง Monitor network latency to cBioPortal API
Configuration Problems
# Generate example config
uv run cbioportal-mcp --create-example-config
# Validate configuration
uv run cbioportal-mcp --config your-config.yaml --log-level DEBUG
# Check environment variables
env | grep CBIOPORTAL
๐ API Connectivity
# Test cBioPortal API accessibility
curl https://www.cbioportal.org/api/cancer-types
# Test with custom instance
curl https://your-instance.org/api/studies
๐ก Examples & Use Cases
๐ Research Queries
"What cancer studies are available for breast cancer research?"
"Search for melanoma studies with genomic data"
"Get mutation data for TP53 in lung cancer studies"
"Find clinical data for patients in the TCGA-BRCA study"
"What molecular profiles are available for pediatric brain tumors?"
๐งฌ Genomic Analysis
"Compare mutation frequencies between two cancer studies"
"Get all genes in the DNA repair pathway for ovarian cancer"
"Find studies with both RNA-seq and mutation data"
"What are the most frequently mutated genes in glioblastoma?"
๐ Bulk Operations
"Fetch data for multiple cancer studies concurrently"
"Get information for a list of cancer genes efficiently"
"Compare clinical characteristics across multiple studies"
"Retrieve molecular profiles for several cancer types"
๐ License
This project is licensed under the MIT License - see the file for details.
๐ Acknowledgments
- ๐งฌ cBioPortal - Open-access cancer genomics data platform
- ๐ Model Context Protocol - Enabling seamless AI-tool interactions
- โก FastMCP - High-performance MCP server framework
- ๐ฆ uv - Modern Python package management
- ๐ค AI Collaboration - Demonstrating the power of human-AI partnership in scientific software development
๐ Built with passion for cancer research and cutting-edge technology! ๐งฌโจ