Skip to main content
Glama

process_list

List and sort running processes by CPU or memory usage, filter by name, user, status, and thresholds, and exclude system processes for efficient system monitoring and management.

Instructions

List running processes sorted by CPU or memory with optional name, user, status, CPU/memory thresholds, system-process filtering, sort order and limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ctxNo
durationNo
include_systemNo
limitNo
min_cpuNo
min_memoryNo
name_filterNo
sort_ascNo
sort_byNocpu
status_filterNo
user_filterNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'process_list' tool. Decorated with @mcp.tool(), it handles input parameters, validates them, samples CPU usage, collects and serializes processes using psutil, applies filters (name, user, status, CPU, memory, system), sorts by CPU or memory usage, applies limit, and returns the list of process dictionaries.
    @mcp.tool()
    async def process_list(sort_by: Literal["cpu", "memory"] = "cpu", duration: int | str = 2, limit: int | str | None = None, name_filter: str | None = None, user_filter: str | None = None, status_filter: Literal["running", "sleeping", "stopped", "zombie"] | None = None, min_cpu: float | str | None = None, min_memory: int | str | None = None, include_system: bool = False, sort_asc: bool = False, ctx: Context | None = None,) -> List[Dict[str, Any]]:
        """List running processes sorted by CPU or memory with optional name, user, status, CPU/memory thresholds, system-process filtering, sort order and limit."""
    
        if ctx:
            await ctx.info(
                f"process_list called sort_by={sort_by} duration={duration} (type={type(duration)}) "
                f"limit={limit} (type={type(limit)}) name_filter={name_filter} user_filter={user_filter} "
                f"status_filter={status_filter} min_cpu={min_cpu} (type={type(min_cpu)}) "
                f"min_memory={min_memory} (type={type(min_memory)}) include_system={include_system} "
                f"sort_asc={sort_asc}"
            )
    
        if sort_by not in {"cpu", "memory"}:
            raise ValueError(f"sort_by must be 'cpu' or 'memory', got: {sort_by} (type: {type(sort_by)})")
    
        if limit is not None:
            limit = _to_int(limit, "limit")
            if limit < 0:
                raise ValueError(f"limit must be non-negative, got: {limit}")
    
        duration = _to_int(duration, "duration")
        if duration < 0:
            raise ValueError(f"duration must be non-negative, got: {duration}")
    
        if min_cpu is not None:
            min_cpu = _to_float(min_cpu, "min_cpu")
            if min_cpu < 0:
                raise ValueError(f"min_cpu must be non-negative, got: {min_cpu}")
    
        if min_memory is not None:
            min_memory = _to_int(min_memory, "min_memory")
            if min_memory < 0:
                raise ValueError(f"min_memory must be non-negative, got: {min_memory}")
    
        _snapshot_cpu()
    
        await asyncio.sleep(max(0.5, duration if sort_by == "cpu" else duration))
    
        procs = _collect_processes()
        serialised = [_serialize(p) for p in procs]
    
        if not include_system:
            serialised = [p for p in serialised if p["username"] not in SYSTEM_USERS]
        if name_filter is not None:
            serialised = [p for p in serialised if name_filter.lower() in p["name"].lower()]
        if user_filter is not None:
            serialised = [p for p in serialised if user_filter.lower() in p["username"].lower()]
        if status_filter is not None:
            serialised = [p for p in serialised if p["status"] == status_filter]
        if min_cpu is not None:
            serialised = [p for p in serialised if p["cpu_percent"] >= min_cpu]
        if min_memory is not None:
            serialised = [p for p in serialised if p["rss"] >= min_memory]
    
        key = "cpu_percent" if sort_by == "cpu" else "rss"
        result = sorted(serialised, key=lambda p: p[key], reverse=not sort_asc)
    
        if limit is not None:
            result = result[:limit]
    
        return result
  • Input schema defined by the function parameters with type annotations (Literal, int|str, etc.) and comprehensive docstring describing usage. Output is List[Dict[str, Any]] containing process info (pid, name, username, status, cpu_percent, rss).
    async def process_list(sort_by: Literal["cpu", "memory"] = "cpu", duration: int | str = 2, limit: int | str | None = None, name_filter: str | None = None, user_filter: str | None = None, status_filter: Literal["running", "sleeping", "stopped", "zombie"] | None = None, min_cpu: float | str | None = None, min_memory: int | str | None = None, include_system: bool = False, sort_asc: bool = False, ctx: Context | None = None,) -> List[Dict[str, Any]]:
        """List running processes sorted by CPU or memory with optional name, user, status, CPU/memory thresholds, system-process filtering, sort order and limit."""
  • The @mcp.tool() decorator on process_list registers it as an MCP tool with FastMCP instance.
    @mcp.tool()
  • Helper function to serialize psutil.Process objects into JSON-safe dicts with pid, name, username, status, cpu_percent, and rss (resident set size or physical footprint on macOS). Used in process_list.
    def _serialize(proc: psutil.Process) -> Dict[str, Any]:
        try:
            try:
                mem = _phys_footprint(proc.pid)
            except Exception:
                mem = 0
            if not mem:
                try:
                    mi = proc.memory_full_info()
                    mem = getattr(mi, "uss", mi.rss)
                except Exception:
                    try:
                        mem = proc.memory_info().rss
                    except Exception:
                        mem = 0
    
            if sys.platform == "win32":
                try:
                    exe_name = os.path.basename(proc.exe())
                    name = exe_name if exe_name else proc.name()
                except (psutil.Error, OSError, FileNotFoundError):
                    name = proc.name()
            else:
                try:
                    name = proc.name()
                except psutil.Error:
                    name = "<unknown>"
    
            cpu = proc.cpu_percent(None)
            return {"pid": proc.pid, "name": name, "username": proc.username(), "status": proc.status(), "cpu_percent": cpu, "rss": mem}
        except psutil.Error:
            return {"pid": proc.pid, "name": "<terminated>", "username": "<unknown>", "status": "<terminated>", "cpu_percent": 0.0, "rss": 0}
  • Helper to safely collect a list of current psutil.Process instances, skipping errors.
    def _collect_processes() -> List[psutil.Process]:
        procs: List[psutil.Process] = []
        for proc in psutil.process_iter(attrs=["pid", "username"]):
            try:
                procs.append(proc)
            except psutil.Error:
                continue
        return procs
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. While it mentions the tool lists processes with sorting and filtering, it doesn't describe what the output looks like, whether this is a read-only operation, potential performance implications, or any system requirements. The description lacks behavioral context beyond the basic action.

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 a single, efficient sentence that packs substantial information about the tool's capabilities. It's appropriately sized for a tool with 11 parameters, though it could benefit from better structure by separating core purpose from parameter details.

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

Completeness3/5

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

Given the complexity (11 parameters, no annotations, but with output schema), the description is moderately complete. It covers the core purpose and most parameters but lacks behavioral context and usage guidance. The presence of an output schema reduces the need to describe return values, but more context about the tool's operation would be helpful.

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

Parameters4/5

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

With 0% schema description coverage for 11 parameters, the description compensates well by listing most key parameters: name, user, status, CPU/memory thresholds, system-process filtering, sort order, and limit. It provides semantic meaning for what would otherwise be completely undocumented parameters, though it doesn't cover all 11 parameters (missing 'duration' and 'ctx').

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 verb ('List') and resource ('running processes') with specific attributes ('sorted by CPU or memory'). It distinguishes from the sibling 'process_kill' by focusing on listing rather than termination. However, it doesn't explicitly contrast with the sibling tool beyond the different action.

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 mentions optional filtering capabilities but provides no guidance on when to use this tool versus alternatives. There's no mention of the sibling tool 'process_kill' or any context about when listing processes is appropriate versus terminating them. Usage is implied through parameter listing rather than explicit guidance.

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

Related 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/misiektoja/kill-process-mcp'

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