Skip to main content
Glama

get_processes_by_ports

Identify processes listening on specific network ports to monitor and debug local services by returning process names and PIDs.

Instructions

Return all running processes listening on the given ports.

Args: ports: List of port numbers to check.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:9-46 (handler)
    Implementation of the get_processes_by_ports MCP tool handler.
    @mcp.tool()
    def get_processes_by_ports(ports: list[int]) -> str:
        """Return all running processes listening on the given ports.
    
        Args:
            ports: List of port numbers to check.
        """
        results = {}
    
        for port in ports:
            try:
                output = subprocess.check_output(
                    ["ss", "-tlnp", f"sport = :{port}"],
                    stderr=subprocess.STDOUT,
                    text=True,
                )
                lines = [l for l in output.strip().splitlines() if str(port) in l]
                processes = []
                for line in lines:
                    # Extract PID/process name from ss output: users:(("name",pid=N,fd=N))
                    if "users:((" in line:
                        users_part = line.split("users:((")[1].rstrip(")")
                        for entry in users_part.split("),("):
                            entry = entry.strip('(")')
                            parts = entry.split(",")
                            name = parts[0].strip('"')
                            pid = next(
                                (p.split("=")[1] for p in parts if p.strip().startswith("pid=")),
                                None,
                            )
                            processes.append({"name": name, "pid": pid})
                    else:
                        processes.append({"raw": line})
                results[port] = processes if processes else []
            except subprocess.CalledProcessError as e:
                results[port] = {"error": e.output.strip()}
    
        return json.dumps(results, indent=2)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions 'running processes' and 'listening on ports', which gives some behavioral context, but lacks details on permissions needed, rate limits, error handling, or what 'return' entails (e.g., format, pagination). This is a significant gap for a tool with no annotation coverage.

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 front-loaded with the core purpose in the first sentence, followed by a brief parameter explanation. It's appropriately sized with zero waste, making it easy to scan and understand quickly.

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 tool's low complexity (1 parameter, no nested objects) and the presence of an output schema (which handles return values), the description is mostly complete. It covers the purpose and parameter semantics adequately, though behavioral transparency could be improved to fully compensate for the lack of annotations.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that 'ports' are 'port numbers to check', clarifying the parameter's purpose beyond the schema's basic type definition. However, it doesn't detail constraints like valid port ranges or handling of invalid inputs.

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 specific action ('Return all running processes listening on') and resource ('the given ports'), with no sibling tools to differentiate from. It directly answers what the tool does without being vague or tautological.

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 usage when you need to find processes by ports, but provides no explicit guidance on when to use this tool versus alternatives, prerequisites, or exclusions. With no sibling tools, the context is straightforward but lacks detailed usage instructions.

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/chalshik/mcp-infra'

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