Backend Functions Reference
Theget_nbm
and get_ads
functions are essential utility functions in the scmcphub ecosystem that provide access to the backend managers during MCP server execution. These functions are used to retrieve the appropriate backend context based on the execution mode.
Overview
These functions serve as accessors to the backend managers that are injected into the MCP server’s lifespan context. They are crucial for:- Tool Mode: Accessing
AdataManager
for AnnData operations - Code Mode: Accessing
NotebookManager
for Jupyter notebook operations
Function Reference
get_ads()
Retrieves the AdataManager
instance from the current request context.
Signature
Returns
- Type:
AdataManager
- Description: The AdataManager instance that manages AnnData objects
Usage Context
- Mode: Tool Mode (
tool-mode
) - Backend:
AdataManager
- Purpose: Managing AnnData objects for single-cell analysis
Example
get_nbm()
Retrieves the NotebookManager
instance from the current request context.
Signature
Returns
- Type:
NotebookManager
- Description: The NotebookManager instance that manages Jupyter notebooks
Usage Context
- Mode: Code Mode (
code-mode
) - Backend:
NotebookManager
- Purpose: Managing Jupyter notebook execution
Example
Backend Managers
AdataManager
TheAdataManager
is responsible for managing AnnData objects in tool mode.
Key Features
- Multi-type Support: Manages different types of AnnData (exp, activity, cnv, splicing)
- Active Sample Management: Tracks the currently active sample ID
- Sample ID Validation: Ensures data consistency across operations
Main Methods
Example Usage
NotebookManager
TheNotebookManager
is responsible for managing Jupyter notebooks in code mode.
Key Features
- Multiple Notebook Support: Manages multiple notebook instances
- Active Notebook Tracking: Maintains the currently active notebook
- Kernel Management: Handles Jupyter kernel lifecycle
Main Methods
Example Usage
Context System
Both functions rely on FastMCP’s context system to access the backend managers.Context Flow
- Server Initialization: Backend manager is created and injected into lifespan context
- Request Processing: Context is available during tool execution
- Function Call:
get_context()
retrieves the current request context - Backend Access: Backend manager is extracted from lifespan context
Context Structure
Mode-Specific Usage
Tool Mode (Default)
Code Mode
Error Handling
Common Issues
- Context Not Available: Ensure the function is called within an MCP tool context
- Wrong Backend Type: Verify the correct backend is configured for your use case
- Missing Dependencies: Ensure FastMCP dependencies are properly installed