measure_latency
Measures network latency to a URL by taking multiple samples and reporting the minimum, providing accurate representation of connection speed.
Instructions
Measure the latency using multiple samples and report the minimum.
Takes a number of samples and reports the lowest
value for the most accurate representation of network latency.
Args:
url (str): The URL to measure latency to
samples (int): Number of samples to take (default: 10)
Returns:
Dictionary with latency result (minimum of all samples)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | https://httpi.dev/get | |
| samples | No |
Implementation Reference
- mcp_internet_speed_test/main.py:758-797 (handler)The measure_latency function is the actual tool handler. It measures latency by sending HTTP GET requests to a specified URL, recording response times, and returning min/max/avg latency statistics along with server info.
@mcp.tool(icons=[ICON_LATENCY]) async def measure_latency( url: str = DEFAULT_LATENCY_URL, samples: int = 10, ) -> dict: """Measure the latency using multiple samples and report the minimum. Takes a number of samples and reports the lowest value for the most accurate representation of network latency. Args: url (str): The URL to measure latency to samples (int): Number of samples to take (default: 10) Returns: Dictionary with latency result (minimum of all samples) """ latency_values = [] server_info = None async with httpx.AsyncClient() as client: for sample_index in range(samples): start = time.time() response = await client.get(url) end = time.time() latency_values.append((end - start) * 1000) if sample_index == 0: server_info = extract_server_info(dict(response.headers)) return { "latency": round(min(latency_values), 2), "unit": "ms", "url": url, "samples": samples, "min_latency": round(min(latency_values), 2), "max_latency": round(max(latency_values), 2), "avg_latency": round(sum(latency_values) / len(latency_values), 2), "server_info": server_info, } - mcp_internet_speed_test/main.py:758-758 (registration)The @mcp.tool(icons=[ICON_LATENCY]) decorator registers measure_latency as an MCP tool on the FastMCP instance.
@mcp.tool(icons=[ICON_LATENCY]) - The function signature defines the input schema: 'url' (str, defaults to DEFAULT_LATENCY_URL) and 'samples' (int, defaults to 10). The return type is dict.
async def measure_latency( url: str = DEFAULT_LATENCY_URL, samples: int = 10, - Uses the extract_server_info helper to parse HTTP headers and extract CDN/pop/location details from the first sample's response.
if sample_index == 0: server_info = extract_server_info(dict(response.headers)) - The FastMCP singleton instance that the @mcp.tool decorator registers measure_latency on.
mcp = FastMCP("internet_speed_test", dependencies=["httpx"])