Skip to main content
Glama

louvain

Detect communities in single-cell RNA sequencing data using the Louvain clustering algorithm to identify cell types and functional groups.

Instructions

Louvain clustering algorithm for community detection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resolutionNoFor the default flavor ('vtraag') or for 'RAPIDS', you can provide a resolution (higher resolution means finding more and smaller clusters), which defaults to 1.0.
random_stateNoChange the initialization of the optimization.
key_addedNoKey under which to add the cluster labels.louvain
flavorNoPackage for computing the clustering: 'vtraag' (default, more powerful), 'igraph' (built-in method), or 'rapids' (GPU accelerated).vtraag
directedNoInterpret the adjacency matrix as directed graph.
use_weightsNoUse weights from knn graph.
partition_kwargsNoKey word arguments to pass to partitioning, if 'vtraag' method is being used.
neighbors_keyNoUse neighbors connectivities as adjacency. If specified, louvain looks .obsp[.uns[neighbors_key]['connectivities_key']] for connectivities.
obspNoUse .obsp[obsp] as adjacency. You can't specify both `obsp` and `neighbors_key` at the same time.

Implementation Reference

  • Generic handler function that dispatches to sc.tl.louvain for the 'louvain' tool by inspecting signature and calling with provided arguments.
    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 
  • Pydantic input schema model for the louvain tool, defining parameters like resolution, flavor, etc., with validators.
    class LouvainModel(JSONParsingModel):
        """Input schema for the Louvain clustering algorithm."""
        
        resolution: Optional[float] = Field(
            default=None,
            description="For the default flavor ('vtraag') or for 'RAPIDS', you can provide a resolution (higher resolution means finding more and smaller clusters), which defaults to 1.0."
        )
        
        random_state: int = Field(
            default=0,
            description="Change the initialization of the optimization."
        )
        
        key_added: str = Field(
            default='louvain',
            description="Key under which to add the cluster labels."
        )
        
        flavor: Literal['vtraag', 'igraph', 'rapids'] = Field(
            default='vtraag',
            description="Package for computing the clustering: 'vtraag' (default, more powerful), 'igraph' (built-in method), or 'rapids' (GPU accelerated)."
        )
        
        directed: bool = Field(
            default=True,
            description="Interpret the adjacency matrix as directed graph."
        )
        
        use_weights: bool = Field(
            default=False,
            description="Use weights from knn graph."
        )
        
        partition_kwargs: Optional[Dict[str, Any]] = Field(
            default=None,
            description="Key word arguments to pass to partitioning, if 'vtraag' method is being used."
        )
        
        neighbors_key: Optional[str] = Field(
            default=None,
            description="Use neighbors connectivities as adjacency. If specified, louvain looks .obsp[.uns[neighbors_key]['connectivities_key']] for connectivities."
        )
        
        obsp: Optional[str] = Field(
            default=None,
            description="Use .obsp[obsp] as adjacency. You can't specify both `obsp` and `neighbors_key` at the same time."
        )
        
        @field_validator('resolution')
        def validate_resolution(cls, v: Optional[float]) -> Optional[float]:
            """Validate resolution is positive if provided"""
            if v is not None and v <= 0:
                raise ValueError("resolution must be a positive number")
            return v
        
        @field_validator('obsp', 'neighbors_key')
        def validate_graph_source(cls, v: Optional[str], info: ValidationInfo) -> Optional[str]:
            """Validate that obsp and neighbors_key are not both specified"""
            values = info.data
            if v is not None and 'obsp' in values and 'neighbors_key' in values:
                if values['obsp'] is not None and values['neighbors_key'] is not None:
                    raise ValueError("Cannot specify both obsp and neighbors_key")
            return v
        
        @field_validator('flavor')
        def validate_flavor(cls, v: str) -> str:
            """Validate flavor is supported"""
            if v not in ['vtraag', 'igraph', 'rapids']:
                raise ValueError("flavor must be one of 'vtraag', 'igraph', or 'rapids'")
            return v
  • Creates the MCP Tool instance for 'louvain' with name, description, and schema reference.
    # Add louvain tool
    louvain_tool = types.Tool(
        name="louvain",
        description="Louvain clustering algorithm for community detection",
        inputSchema=LouvainModel.model_json_schema(),
    )
  • Registers the louvain_tool in the tl_tools dictionary, which is provided to 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,
    }
  • MCP server.list_tools() decorator that includes tl_tools.values(), exposing the louvain tool to clients.
    @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 only states what the algorithm is without explaining what it does operationally. It doesn't mention that this is a computational clustering operation, what kind of input data it expects (e.g., adjacency matrices), whether it modifies data in place, what outputs are generated, or any performance characteristics like computational intensity.

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 just 6 words, with zero wasted language. It's front-loaded with the essential information (algorithm name and purpose) in a single, clear phrase. Every word earns its place by identifying both the method and its application domain.

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 clustering algorithm with 9 parameters and no output schema, the description is insufficient. It doesn't explain what the tool actually does operationally, what data structures it expects or produces, or how it integrates with the broader analysis workflow. The absence of annotations means the description must carry more weight, but it provides only minimal context.

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?

The schema description coverage is 100%, meaning all parameters are well-documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema, so it meets the baseline expectation but doesn't provide extra context about how parameters interact or typical usage patterns.

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

Purpose4/5

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

The description clearly states the tool's purpose as 'Louvain clustering algorithm for community detection', which specifies both the algorithm (Louvain) and its function (clustering for community detection). However, it doesn't differentiate from its sibling 'leiden', which appears to be another clustering algorithm in the same server, leaving room for confusion about when to choose one over the other.

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 like 'leiden' or other clustering methods available in the sibling tools. It doesn't mention prerequisites, typical use cases, or any context about what data or state is required before invoking this tool.

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