traceroute
Map the network path to a host, showing each hop and latency to pinpoint connection problems.
Instructions
Trace the network path to a host.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| max_hops | No | ||
| timeout | No |
Implementation Reference
- src/mcp_nettools/server.py:64-80 (handler)The traceroute tool handler function decorated with @mcp.tool(). It runs the system 'traceroute' command via subprocess, passing max_hops and timeout parameters, and returns the output as a dict.
@mcp.tool() def traceroute(host: str, max_hops: int = 30, timeout: int = 60) -> dict: """Trace the network path to a host.""" try: result = subprocess.run( ["traceroute", "-m", str(max_hops), host], capture_output=True, text=True, timeout=timeout, ) return { "host": host, "output": result.stdout, "returncode": result.returncode, } except Exception as e: return {"error": str(e), "tool": "traceroute", "host": host} - src/mcp_nettools/server.py:64-64 (registration)The @mcp.tool() decorator on line 64 registers the traceroute function as an MCP tool with the FastMCP server instance.
@mcp.tool() - src/mcp_nettools/server.py:148-153 (helper)The main() function that runs the MCP server, which serves all registered tools including traceroute.
def main() -> None: mcp.run() if __name__ == "__main__": main() - src/mcp_nettools/server.py:65-65 (schema)The function signature defines the input schema: host (str, required), max_hops (int, default 30), timeout (int, default 60).
def traceroute(host: str, max_hops: int = 30, timeout: int = 60) -> dict: