Skip to main content
Glama
seayniclabs

Keel

by seayniclabs

port_check

Check if a TCP port is open on a host to test network connectivity.

Instructions

Check whether a single TCP port is open on a host.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYes
portYes
timeoutNo

Implementation Reference

  • The core handler for the port_check tool. It uses @mcp.tool() decorator to register the tool, validates the host and port, then attempts an asynchronous TCP connection. Returns {'state': 'open'} on success or {'state': 'closed'} on OSError/Timeout.
    @mcp.tool()
    async def port_check(host: str, port: int, timeout: int = 3) -> dict:
        """Check whether a single TCP port is open on a host."""
        host = validate_host(host)
        if not validate_port(port):
            raise ValueError(f"Invalid port: {port}")
    
        try:
            reader, writer = await asyncio.wait_for(
                asyncio.open_connection(host, port),
                timeout=timeout,
            )
            writer.close()
            await writer.wait_closed()
            return {"host": host, "port": port, "state": "open"}
        except (OSError, asyncio.TimeoutError):
            return {"host": host, "port": port, "state": "closed"}
  • The @mcp.tool() decorator registers port_check as an MCP tool on the FastMCP instance.
    @mcp.tool()
    async def port_check(host: str, port: int, timeout: int = 3) -> dict:
  • Validates the host parameter - strips whitespace, rejects shell meta-characters, validates IP addresses and hostnames, and optionally checks for internal/SSRF.
    def validate_host(host: str, *, allow_internal: bool = True) -> str:
        """Validate a hostname or IP address.
    
        Args:
            host: The hostname or IP to validate.
            allow_internal: If False, reject internal/private/loopback IPs and
                hostnames that resolve to them (SSRF protection). Defaults to
                True since tools like ping and traceroute legitimately target
                internal networks.
    
        Returns the cleaned host string.
        Raises ``ValueError`` on anything suspicious.
        """
        host = host.strip()
        if not host:
            raise ValueError("Host must not be empty")
    
        if _SHELL_META.search(host):
            raise ValueError(f"Host contains forbidden characters: {host!r}")
    
        # Accept valid IP addresses directly.
        try:
            addr = ipaddress.ip_address(host)
            if not allow_internal and is_internal_ip(host):
                raise ValueError(
                    f"Host {host} is an internal/private/loopback address — "
                    "requests to internal addresses are blocked"
                )
            return host
        except ValueError as exc:
            # Re-raise if it's our own SSRF block, not an ip_address parse error
            if "internal" in str(exc):
                raise
            pass
    
        if not _HOSTNAME_RE.match(host):
            raise ValueError(f"Invalid hostname: {host!r}")
    
        # If internal not allowed, resolve and check the IP
        if not allow_internal:
            _resolve_and_check(host)
    
        return host
  • Validates that the port is an integer in the valid TCP/UDP range (1-65535).
    def validate_port(port: int) -> bool:
        """Return True if *port* is in the valid TCP/UDP range (1–65535)."""
        return isinstance(port, int) and 1 <= port <= 65535
  • The FastMCP instance used for tool registration via the @mcp.tool() decorator.
    mcp = FastMCP("sounding")
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 of disclosing behavior. It does not mention how results are returned, error handling, or whether permission is required. The timeout parameter is mentioned in schema but not explained in description.

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 sentence, which is concise. However, it lacks structure such as parameter explanations or usage notes, making it only slightly above average.

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 tool is simple but has no output schema, the description does not inform the agent about return values (e.g., boolean vs details). Sibling descriptions may be richer, making this one insufficient for full contextual understanding.

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 description coverage is 0%, and the description adds no meaning to the parameters. For example, 'host' (domain or IP?), 'port' (range?), 'timeout' (units?) remain undefined.

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 action: 'Check whether a single TCP port is open on a host.' It uses a specific verb ('Check') and resource ('TCP port'), and explicitly mentions 'single' to distinguish from siblings like 'port_scan'.

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 gives no guidance on when to use this tool versus siblings. No alternatives or exclusions are mentioned, despite the presence of sibling tools like 'port_scan' which would handle multiple ports.

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