Skip to main content
Glama

pca

Reduce dimensionality of single-cell RNA sequencing data to identify key patterns and simplify analysis for biological insights.

Instructions

Principal component analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
n_compsNoNumber of principal components to compute. Defaults to 50 or 1 - minimum dimension size.
layerNoIf provided, which element of layers to use for PCA.
zero_centerNoIf True, compute standard PCA from covariance matrix.
svd_solverNoSVD solver to use.
mask_varNoBoolean mask or string referring to var column for subsetting genes.
dtypeNoNumpy data type string for the result.float32
chunkedNoIf True, perform an incremental PCA on segments.
chunk_sizeNoNumber of observations to include in each chunk.

Implementation Reference

  • Handler function that executes the 'pca' tool (and other pp tools). It retrieves the active AnnData object, maps 'pca' to sc.pp.pca via pp_func dict, calls it with parsed arguments (forcing inplace=True), logs the operation, and handles errors.
    def run_pp_func(ads, func, arguments):
        adata = ads.adata_dic[ads.active]
        if func not in pp_func:
            raise ValueError(f"不支持的函数: {func}")
        
        run_func = pp_func[func]
        parameters = inspect.signature(run_func).parameters
        arguments["inplace"] = True
        kwargs = {k: arguments.get(k) for k in parameters if k in arguments}
        try:
            res = run_func(adata, **kwargs)
            add_op_log(adata, run_func, kwargs)
        except KeyError as e:
            raise KeyError(f"Can not foud {e} column in adata.obs or adata.var")
        except Exception as e:
           raise e
        return res
  • Pydantic model defining the input schema for the 'pca' tool, including parameters like n_comps, layer, zero_center, svd_solver, etc., with validators.
    class PCAModel(JSONParsingModel):
        """Input schema for the PCA preprocessing tool."""
        
        n_comps: Optional[int] = Field(
            default=None,
            description="Number of principal components to compute. Defaults to 50 or 1 - minimum dimension size.",
            gt=0
        )
        
        layer: Optional[str] = Field(
            default=None,
            description="If provided, which element of layers to use for PCA."
        )
        
        zero_center: Optional[bool] = Field(
            default=True,
            description="If True, compute standard PCA from covariance matrix."
        )
        
        svd_solver: Optional[Literal["arpack", "randomized", "auto", "lobpcg", "tsqr"]] = Field(
            default=None,
            description="SVD solver to use."
        )
        mask_var: Optional[Union[str, bool]] = Field(
            default=None,
            description="Boolean mask or string referring to var column for subsetting genes."
        )
        dtype: str = Field(
            default="float32",
            description="Numpy data type string for the result."
        )
        chunked: bool = Field(
            default=False,
            description="If True, perform an incremental PCA on segments."
        )
        
        chunk_size: Optional[int] = Field(
            default=None,
            description="Number of observations to include in each chunk.",
            gt=0
        )
        
        @field_validator('n_comps', 'chunk_size')
        def validate_positive_integers(cls, v: Optional[int]) -> Optional[int]:
            """Validate positive integers"""
            if v is not None and v <= 0:
                raise ValueError("must be a positive integer")
            return v
        
        @field_validator('dtype')
        def validate_dtype(cls, v: str) -> str:
            """Validate numpy dtype"""
            if v not in ["float32", "float64"]:
                raise ValueError("dtype must be either 'float32' or 'float64'")
            return v
  • MCP Tool object registration for 'pca', specifying name, description, and input schema from PCAModel.
    pca = types.Tool(
        name="pca",
        description="Principal component analysis",
        inputSchema=PCAModel.model_json_schema(),
    )
  • Dictionary mapping tool names to Scanpy functions. 'pca' maps directly to sc.pp.pca, used by run_pp_func to execute the tool.
    pp_func = {
        "filter_genes": sc.pp.filter_genes,
        "filter_cells": sc.pp.filter_cells,
        "calculate_qc_metrics": partial(sc.pp.calculate_qc_metrics, inplace=True),
        "log1p": sc.pp.log1p,
        "normalize_total": sc.pp.normalize_total,
        "pca": sc.pp.pca,
        "highly_variable_genes": sc.pp.highly_variable_genes,
        "regress_out": sc.pp.regress_out,
        "scale": sc.pp.scale,
        "combat": sc.pp.combat,
        "scrublet": sc.pp.scrublet,
        "neighbors": sc.pp.neighbors,
    }
  • Server's list_tools method that returns the registered tools, including pp_tools which contains the 'pca' tool, based on MODULE environment variable.
    @server.list_tools()
    async def list_tools() -> list[types.Tool]:
        if MODULE == "io":
            tools = io_tools.values()
        elif MODULE == "pp":
            tools = pp_tools.values()
        elif MODULE == "tl":
            tools = tl_tools.values()
        elif MODULE == "pl":
            tools = pl_tools.values()
        elif MODULE == "util":
            tools = util_tools.values()
        else:
            tools = [
                *io_tools.values(),
                *pp_tools.values(),
                *tl_tools.values(),
                *pl_tools.values(),
                *util_tools.values(),
                *ccc_tools.values(),
            ]
        return tools
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 but offers none. It doesn't indicate whether this is a read-only analysis tool or if it modifies data, what the computational requirements might be, whether it's reversible, or what the output format is. The description fails to provide any behavioral context beyond the bare name.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While technically concise with just two words, this is under-specification rather than effective conciseness. The description doesn't earn its place by providing any useful information beyond the tool name. A truly concise description would still convey essential purpose and context in minimal words.

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 complex statistical analysis tool with 8 parameters and no output schema, the description is completely inadequate. It doesn't explain what PCA does in this context, what data it operates on, what results to expect, or how it fits with other tools. The absence of annotations and output schema means the description should provide substantial context, which it fails to do.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents all 8 parameters. The description adds no parameter information beyond what's in the schema. The baseline score of 3 reflects adequate parameter documentation purely through the schema, with no value added by the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Principal component analysis' is a tautology that merely restates the tool name 'pca' without specifying what it actually does. It doesn't indicate what resource it operates on (e.g., gene expression data), what the output is, or how it differs from sibling tools like 'pl_pca' or 'pl_pca_variance_ratio'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/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. There are multiple related PCA tools in the sibling list (pl_pca, pl_pca_variance_ratio), but the description doesn't explain when this computational PCA tool should be used versus visualization tools or what prerequisites might be needed.

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/huang-sh/scmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server