get_network_status
Retrieve the current network status in JSON or summary format using Tailscale CLI integration, enabling automated network monitoring and management.
Instructions
Get current network status from Tailscale CLI
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | Yes | Output format (json or summary) | json |
Implementation Reference
- src/tools/network-tools.ts:56-122 (handler)The handler function that implements the core logic of the 'get_network_status' tool. It fetches the Tailscale network status using the unified client, handles errors, and returns formatted output in either 'json' or 'summary' format.async function getNetworkStatus( args: z.infer<typeof NetworkStatusSchema>, context: ToolContext, ): Promise<CallToolResult> { try { logger.debug("Getting network status with format:", args.format); // Use unified client which will automatically choose between API and CLI const result = await context.client.getStatus(); if (!result.success) { return returnToolError(result.error); } const status = result.data as TailscaleCLIStatus; if (args.format === "summary") { let output = "**Tailscale Network Status**\n\n"; output += `Version: ${status.Version}\n`; output += `Backend state: ${status.BackendState}\n`; output += `TUN interface: ${status.TUN ? "Active" : "Inactive"}\n`; output += `Tailscale IPs: ${(status.TailscaleIPs ?? []).join(", ")}\n\n`; output += "**This device:**\n"; output += ` - Hostname: ${status.Self.HostName}\n`; output += ` - DNS name: ${status.Self.DNSName}\n`; output += ` - OS: ${status.Self.OS}\n`; output += ` - IPs: ${status.Self.TailscaleIPs.join(", ")}\n`; output += ` - Online: ${status.Self.Online ? "π’" : "π΄"}\n`; if (status.Self.ExitNode) { output += " - Exit node: Yes\n"; } output += "\n"; if (status.Peer && Object.keys(status.Peer).length > 0) { const peers = Object.values(status.Peer); output += `**Connected peers (${peers.length}):**\n`; for (const peer of peers) { const onlineStatus = peer.Online ? "π’" : "π΄"; output += ` ${onlineStatus} ${peer.HostName} (${peer.DNSName})\n`; output += ` - OS: ${peer.OS}\n`; output += ` - IPs: ${peer.TailscaleIPs.join(", ")}\n`; if (peer.LastSeen && peer.LastSeen !== "0001-01-01T00:00:00Z") { output += ` - Last seen: ${peer.LastSeen}\n`; } if (peer.ExitNode) { output += " - Exit node: Yes\n"; } if (peer.Active) { output += " - Active connection\n"; } } } return returnToolSuccess(output); } // JSON format return returnToolSuccess(JSON.stringify(status, null, 2)); } catch (error: unknown) { logger.error("Error getting network status:", error); const err = error instanceof Error ? error : new Error(String(error ?? "Unknown error")); return returnToolError(err); } }
- src/tools/network-tools.ts:9-15 (schema)Zod schema defining the input parameters for the tool, including an optional 'format' parameter defaulting to 'json'.const NetworkStatusSchema = z.object({ format: z .enum(["json", "summary"]) .optional() .default("json") .describe("Output format (json or summary)"), });
- src/tools/network-tools.ts:228-233 (registration)Registration of the 'get_network_status' tool within the networkTools module, linking the name, description, schema, and handler.{ name: "get_network_status", description: "Get current network status from Tailscale CLI", inputSchema: NetworkStatusSchema, handler: getNetworkStatus, },
- src/tools/index.ts:44-44 (registration)Registration of the networkTools module (containing get_network_status) into the central ToolRegistry during tool loading.this.registerModule(networkTools);