Skip to main content
Glama
seayniclabs

Keel

by seayniclabs

port_scan

Identify open TCP ports on a host by scanning common ports. Each scan is limited to 100 ports for safety.

Instructions

Scan common TCP ports on a host.

Safety limits: max 100 ports, rate-limited to one scan per second.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYes
portsNo

Implementation Reference

  • The `port_scan` tool handler function, decorated with @mcp.tool(). It validates the host, defaults to common ports, limits to 100 ports, enforces rate-limiting (1 scan/sec), then concurrently scans each port via asyncio.open_connection with a 2s timeout. Returns a dict with host, ports_scanned, open_ports, and all_results.
    async def port_scan(host: str, ports: Optional[list[int]] = None) -> dict:
        """Scan common TCP ports on a host.
    
        Safety limits: max 100 ports, rate-limited to one scan per second.
        """
        global _last_scan_time
    
        host = validate_host(host)
        if ports is None:
            ports = DEFAULT_PORTS
        if len(ports) > 100:
            raise ValueError("port_scan is limited to 100 ports per call")
        for p in ports:
            if not validate_port(p):
                raise ValueError(f"Invalid port in list: {p}")
    
        # Rate limiting — one scan per second.
        async with _scan_lock:
            now = time.monotonic()
            wait = 1.0 - (now - _last_scan_time)
            if wait > 0:
                await asyncio.sleep(wait)
            _last_scan_time = time.monotonic()
    
        async def _check(p: int) -> dict:
            try:
                reader, writer = await asyncio.wait_for(
                    asyncio.open_connection(host, p),
                    timeout=2,
                )
                writer.close()
                await writer.wait_closed()
                return {"port": p, "state": "open"}
            except (OSError, asyncio.TimeoutError):
                return {"port": p, "state": "closed"}
    
        results = await asyncio.gather(*[_check(p) for p in ports])
        open_ports = [r for r in results if r["state"] == "open"]
    
        return {
            "host": host,
            "ports_scanned": len(ports),
            "open_ports": open_ports,
            "all_results": results,
        }
  • The `@mcp.tool()` decorator that registers `port_scan` as an MCP tool on the FastMCP instance.
    @mcp.tool()
    async def port_scan(host: str, ports: Optional[list[int]] = None) -> dict:
  • Rate-limit state variables (`_last_scan_time`, `_scan_lock`) and the default port list (`DEFAULT_PORTS`) used by port_scan.
    # Rate-limit state for port_scan.
    _last_scan_time: float = 0.0
    _scan_lock = asyncio.Lock()
    
    # Default common ports for port_scan.
    DEFAULT_PORTS = [
        21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, 443, 445,
        993, 995, 1723, 3306, 3389, 5432, 5900, 8080, 8443,
    ]
  • Type signature for port_scan: takes `host: str` and optional `ports: Optional[list[int]]`, returns `dict`.
    async def port_scan(host: str, ports: Optional[list[int]] = None) -> dict:
Behavior3/5

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

With no annotations, the description carries full burden. It discloses safety limits (max 100 ports, rate limit), but omits details like error handling, output format, or permission requirements.

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?

Two short sentences with no unnecessary words. The safety limits are front-loaded. However, the description is too sparse to fully serve its purpose.

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 parameter count and lack of output schema or annotations, the description is insufficient. It does not differentiate from sibling 'port_check' or explain when to use which.

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

Parameters1/5

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

Schema has 0% description coverage, and the description adds no parameter-specific meaning. The 'ports' parameter's default behavior (common ports?) is not explained.

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 states the tool scans common TCP ports on a host, which is specific. However, it does not explicitly differentiate from sibling tool 'port_check', which likely also scans ports, though 'common' implies a preset list.

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?

No guidance on when to use this tool vs alternatives (e.g., port_check). Only safety limits are provided, not usage context.

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/seayniclabs/sounding'

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