Skip to main content
Glama

dendrogram

Creates hierarchical clustering dendrograms for single-cell RNA sequencing data to visualize relationships between cell groups based on gene expression patterns.

Instructions

Hierarchical clustering dendrogram

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupbyYesThe categorical observation annotation to use for grouping.
n_pcsNoUse this many PCs. If n_pcs==0 use .X if use_rep is None.
use_repNoUse the indicated representation. 'X' or any key for .obsm is valid.
var_namesNoList of var_names to use for computing the hierarchical clustering. If provided, use_rep and n_pcs are ignored.
use_rawNoOnly when var_names is not None. Use raw attribute of adata if present.
cor_methodNoCorrelation method to use: 'pearson', 'kendall', or 'spearman'.pearson
linkage_methodNoLinkage method to use for hierarchical clustering.complete
optimal_orderingNoReorders the linkage matrix so that the distance between successive leaves is minimal.
key_addedNoBy default, the dendrogram information is added to .uns[f'dendrogram_{groupby}'].

Implementation Reference

  • Handler function that executes the dendrogram tool. Retrieves sc.tl.dendrogram from tl_func mapping and calls it with parsed arguments on the active AnnData object.
    def run_tl_func(ads, func, arguments):
        adata = ads.adata_dic[ads.active]
        if func not in tl_func:
            raise ValueError(f"Unsupported function: {func}")
        run_func = tl_func[func]
        parameters = inspect.signature(run_func).parameters
        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 Exception as e:
            logger.error(f"Error running function {func}: {e}")
            raise
        return 
  • Mapping dictionary that associates the 'dendrogram' tool name with scanpy's sc.tl.dendrogram function.
    tl_func = {
        "tsne": sc.tl.tsne,
        "umap": sc.tl.umap,
        "draw_graph": sc.tl.draw_graph,
        "diffmap": sc.tl.diffmap,
        "embedding_density": sc.tl.embedding_density,
        "leiden": sc.tl.leiden,
        "louvain": sc.tl.louvain,
        "dendrogram": sc.tl.dendrogram,
        "dpt": sc.tl.dpt,
        "paga": sc.tl.paga,
        "ingest": sc.tl.ingest,
        "rank_genes_groups": sc.tl.rank_genes_groups,
        "filter_rank_genes_groups": sc.tl.filter_rank_genes_groups,
        "marker_gene_overlap": sc.tl.marker_gene_overlap,
        "score_genes": sc.tl.score_genes,
        "score_genes_cell_cycle": sc.tl.score_genes_cell_cycle,
    }
  • Pydantic model defining the input schema and validation for the dendrogram tool.
    class DendrogramModel(JSONParsingModel):
        """Input schema for the hierarchical clustering dendrogram tool."""
        
        groupby: str = Field(
            ...,  # Required field
            description="The categorical observation annotation to use for grouping."
        )
        n_pcs: Optional[int] = Field(
            default=None,
            description="Use this many PCs. If n_pcs==0 use .X if use_rep is None.",
            ge=0
        )
        use_rep: Optional[str] = Field(
            default=None,
            description="Use the indicated representation. 'X' or any key for .obsm is valid."
        )
        var_names: Optional[List[str]] = Field(
            default=None,
            description="List of var_names to use for computing the hierarchical clustering. If provided, use_rep and n_pcs are ignored."
        )
        use_raw: Optional[bool] = Field(
            default=None,
            description="Only when var_names is not None. Use raw attribute of adata if present."
        )
        cor_method: str = Field(
            default='pearson',
            description="Correlation method to use: 'pearson', 'kendall', or 'spearman'."
        )
        linkage_method: str = Field(
            default='complete',
            description="Linkage method to use for hierarchical clustering."
        )
        optimal_ordering: bool = Field(
            default=False,
            description="Reorders the linkage matrix so that the distance between successive leaves is minimal."
        )
        key_added: Optional[str] = Field(
            default=None,
            description="By default, the dendrogram information is added to .uns[f'dendrogram_{groupby}']."
        )
        
        @field_validator('cor_method')
        def validate_cor_method(cls, v: str) -> str:
            """Validate correlation method is supported"""
            valid_methods = ['pearson', 'kendall', 'spearman']
            if v.lower() not in valid_methods:
                raise ValueError(f"cor_method must be one of {valid_methods}")
            return v.lower()
        
        @field_validator('linkage_method')
        def validate_linkage_method(cls, v: str) -> str:
            """Validate linkage method is supported"""
            valid_methods = ['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward']
            if v.lower() not in valid_methods:
                raise ValueError(f"linkage_method must be one of {valid_methods}")
            return v.lower()
        
        @field_validator('n_pcs')
        def validate_n_pcs(cls, v: Optional[int]) -> Optional[int]:
            """Validate n_pcs is non-negative"""
            if v is not None and v < 0:
                raise ValueError("n_pcs must be a non-negative integer")
            return v
  • Definition and registration of the MCP Tool object for 'dendrogram', referencing the input schema.
    # Add dendrogram tool
    dendrogram_tool = types.Tool(
        name="dendrogram",
        description="Hierarchical clustering dendrogram",
        inputSchema=DendrogramModel.model_json_schema(),
    )
  • Registration of the dendrogram_tool in the tl_tools dictionary, which is exposed via the MCP server.
    tl_tools = {
        "tsne": tsne_tool,
        "umap": umap_tool,
        "draw_graph": draw_graph_tool,
        "diffmap": diffmap_tool,
        "embedding_density": embedding_density_tool,
        "leiden": leiden_tool,
        "louvain": louvain_tool,
        "dendrogram": dendrogram_tool,
        "dpt": dpt_tool,
        "paga": paga_tool,
        "ingest": ingest_tool,
        "rank_genes_groups": rank_genes_groups_tool,
        "filter_rank_genes_groups": filter_rank_genes_groups_tool,
        "marker_gene_overlap": marker_gene_overlap_tool,
        "score_genes": score_genes_tool,
        "score_genes_cell_cycle": score_genes_cell_cycle_tool,
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. 'Hierarchical clustering dendrogram' implies a computation/visualization tool but doesn't disclose behavioral traits: whether it modifies data (e.g., adds to .uns), requires specific data formats, has performance considerations, or what the output looks like (plot vs data structure). For a tool with 9 parameters and no annotations, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is extremely concise at two words with zero waste. It's front-loaded with the core concept. While it's under-specified, this dimension scores conciseness, not completeness, and it earns full marks for brevity.

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?

Given the tool's complexity (9 parameters, clustering operation), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (plot, data structure, or modification to data object), typical use cases, or how it fits into analysis workflows. For a computational tool with many parameters, more context is needed.

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 parameters are well-documented in the schema itself. The description adds no parameter information beyond what's in the schema. It doesn't explain relationships between parameters (e.g., how var_names overrides use_rep and n_pcs) or provide usage examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Hierarchical clustering dendrogram' states the tool's purpose but is vague. It identifies the output type (dendrogram) and method (hierarchical clustering) but doesn't specify what action the tool performs (e.g., computes, generates, plots) or what data it operates on. It doesn't distinguish from siblings like 'leiden' or 'louvain' which are also clustering methods.

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

Usage Guidelines2/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. It doesn't mention sibling tools like 'leiden' (community detection) or 'paga' (trajectory inference) that might be used for similar clustering or analysis tasks. There's no indication of prerequisites, typical workflows, or when hierarchical clustering is preferred over other methods.

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