list_devices
Retrieve a detailed list of all devices connected to the Tailscale network, optionally including route information, for streamlined network management and monitoring.
Instructions
List all devices in the Tailscale network
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeRoutes | Yes | Include route information for each device |
Implementation Reference
- src/tools/device-tools.ts:33-91 (handler)The handler function that implements the core logic of the 'list_devices' MCP tool. It uses the unified Tailscale client to fetch devices (via API or CLI), handles both response formats, optionally includes route info, and returns a formatted markdown string listing all devices.
async function listDevices( args: z.infer<typeof ListDevicesSchema>, context: ToolContext, ): Promise<CallToolResult> { try { logger.debug("Listing devices with options:", args); // Use unified client which will automatically choose between API and CLI const result = await context.client.listDevices(); if (!result.success) { return returnToolError(result); } const devices = result.data || []; let output = `Found ${devices.length} devices:\n\n`; for (const device of devices) { // Handle both string arrays (from CLI) and TailscaleDevice objects (from API) if (typeof device === "string") { // CLI returns simple string array of hostnames output += `**${device}**\n`; output += " - Source: CLI (limited info available)\n\n"; } else { // API returns full TailscaleDevice objects const typedDevice = device; output += `**${typedDevice.name}** (${typedDevice.hostname})\n`; output += ` - ID: ${typedDevice.id}\n`; output += ` - OS: ${typedDevice.os}\n`; output += ` - Addresses: ${typedDevice.addresses.join(", ")}\n`; output += ` - Authorized: ${typedDevice.authorized ? "✅" : "❌"}\n`; output += ` - Last seen: ${typedDevice.lastSeen}\n`; output += ` - Client version: ${typedDevice.clientVersion}\n`; if ( args.includeRoutes && Array.isArray(typedDevice.advertisedRoutes) && typedDevice.advertisedRoutes.length > 0 ) { output += ` - Advertised routes: ${typedDevice.advertisedRoutes.join( ", ", )}\n`; output += ` - Enabled routes: ${ Array.isArray(typedDevice.enabledRoutes) ? typedDevice.enabledRoutes.join(", ") : "—" }\n`; } output += "\n"; } } return returnToolSuccess(output); } catch (error: unknown) { logger.error("Error listing devices:", error); return returnToolError(error); } } - src/tools/device-tools.ts:9-15 (schema)Zod schema defining the input parameters for the 'list_devices' tool. Supports an optional 'includeRoutes' boolean (defaults to false).
const ListDevicesSchema = z.object({ includeRoutes: z .boolean() .optional() .default(false) .describe("Include route information for each device"), }); - src/tools/device-tools.ts:171-175 (registration)The registration of the 'list_devices' tool within the deviceTools module. Specifies name, description, input schema, and handler function.
name: "list_devices", description: "List all devices in the Tailscale network", inputSchema: ListDevicesSchema, handler: listDevices, }, - src/tools/index.ts:43-43 (registration)Registration of the deviceTools module (containing list_devices) into the central ToolRegistry during loadTools().
this.registerModule(deviceTools);