Skip to main content
Glama
milliomics

millimap-mcp

Official
by milliomics

run_clustering

Perform clustering on the active dataset by running PCA, nearest neighbor calculation, Leiden clustering, and UMAP, then update the 3D visualization with new cluster labels.

Instructions

Run MilliMap's clustering pipeline on the active dataset.

Runs PCA → neighbors (n_neighbors) → Leiden (resolution) → UMAP using Scanpy and updates the 3D view in MilliMap with the new cluster labels.

Args: resolution: Leiden resolution (higher = more clusters). Default 0.5. n_neighbors: k for the neighbors graph. Default 15.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resolutionNo
n_neighborsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The run_clustering tool handler — a FastMCP tool decorated function that forwards the request to the MilliMap desktop app via HTTP POST to /tool. It passes resolution and n_neighbors parameters to the MilliMap backend which runs PCA, neighbors graph, Leiden clustering, and UMAP.
    @mcp.tool()
    def run_clustering(resolution: float = 0.5, n_neighbors: int = 15) -> str:
        """Run MilliMap's clustering pipeline on the active dataset.
    
        Runs PCA → neighbors (n_neighbors) → Leiden (resolution) → UMAP using
        Scanpy and updates the 3D view in MilliMap with the new cluster labels.
    
        Args:
            resolution: Leiden resolution (higher = more clusters). Default 0.5.
            n_neighbors: k for the neighbors graph. Default 15.
        """
        return _fmt_json(_post_tool("run_clustering", {
            "resolution": resolution,
            "n_neighbors": n_neighbors,
        }))
  • Registration of run_clustering as an MCP tool via the @mcp.tool() decorator on the FastMCP instance named 'mcp' (line 22).
    @mcp.tool()
  • Input schema for run_clustering: resolution (float, default 0.5) and n_neighbors (int, default 15), defined via type hints and docstring.
    Args:
        resolution: Leiden resolution (higher = more clusters). Default 0.5.
        n_neighbors: k for the neighbors graph. Default 15.
  • Helper function _post_tool that makes the HTTP POST call to the MilliMap desktop app at http://host:port/tool, used by run_clustering to delegate execution.
    def _post_tool(name: str, args: dict, timeout: float = 600.0) -> dict:
        ctrl = _load_control()
        if not ctrl or not ctrl.get("port"):
            return {
                "ok": False,
                "error": (
                    f"MilliMap control endpoint not found at {CONTROL_PATH}. "
                    "Make sure MilliMap is running with a dataset loaded."
                ),
            }
        host = ctrl.get("host", "127.0.0.1")
        port = int(ctrl["port"])
        url = f"http://{host}:{port}/tool"
        data = json.dumps({"name": name, "args": args}).encode("utf-8")
        req = urllib.request.Request(
            url, data=data,
            headers={"Content-Type": "application/json"},
            method="POST",
        )
        try:
            with urllib.request.urlopen(req, timeout=timeout) as resp:
                return json.loads(resp.read().decode("utf-8"))
        except urllib.error.URLError as exc:
            return {"ok": False, "error": f"connection failed: {exc.reason}"}
        except Exception as exc:
            return {"ok": False, "error": f"HTTP call failed: {exc}"}
  • Helper _fmt_json that converts the tool response dict to a JSON string, used by run_clustering to format its return value.
    def _fmt_json(payload: Any) -> str:
        return json.dumps(payload, indent=2, default=str)
Behavior3/5

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

Without annotations, the description carries the burden. It discloses that the tool updates the 3D view with new cluster labels, but does not mention whether previous clusters are overwritten, or any constraints like dataset size or computational cost.

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

Conciseness4/5

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

The description is concise, with a clear intro sentence and a bulleted overview of steps and parameters. It avoids redundancy and front-loads the main purpose, though the argument list could be more compact.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of an output schema (which explains return values), the description adequately covers the tool's operation and side effects on the 3D view. Minor gaps in usage guidelines and parameter ranges are acceptable for a tool with two simple parameters.

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?

With 0% schema description coverage, the description partially compensates by explaining resolution as 'Leiden resolution (higher = more clusters)' and n_neighbors as 'k for the neighbors graph', along with defaults. However, ranges or impact details are missing.

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

Purpose5/5

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

The description clearly states the tool runs MilliMap's clustering pipeline on the active dataset, listing the exact steps (PCA, neighbors, Leiden, UMAP). It distinguishes itself from siblings that handle annotation, filtering, or marker finding.

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

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for initial clustering, but lacks explicit guidance on when to use it versus alternatives like annotate_cluster or find_markers. No 'when not to use' or prerequisites are mentioned.

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/milliomics/millimap-mcp'

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