port_check
Check if a TCP port is open on a specified host to verify network connectivity and service availability.
Instructions
Check if a TCP port is open on a host.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| port | Yes | ||
| timeout | No |
Implementation Reference
- src/mcp_nettools/server.py:52-61 (handler)The port_check tool handler: uses a TCP socket with connect_ex() to check if a given port is open on a host. Returns {'host', 'port', 'open'} on success, or {'error', 'tool', 'host', 'port'} on exception.
@mcp.tool() def port_check(host: str, port: int, timeout: int = 5) -> dict: """Check if a TCP port is open on a host.""" try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.settimeout(timeout) result = sock.connect_ex((host, port)) return {"host": host, "port": port, "open": result == 0} except Exception as e: return {"error": str(e), "tool": "port_check", "host": host, "port": port} - src/mcp_nettools/server.py:52-53 (registration)The @mcp.tool() decorator registers port_check as an MCP tool on the FastMCP('nettools') instance.
@mcp.tool() def port_check(host: str, port: int, timeout: int = 5) -> dict: - src/mcp_nettools/server.py:52-53 (schema)Input schema: host (str), port (int), timeout (int, default 5). Output schema: dict with host, port, open (bool) or error info.
@mcp.tool() def port_check(host: str, port: int, timeout: int = 5) -> dict: