discover_nanoleaf
Find Nanoleaf smart lights on your local network to enable control through the MCP server for managing brightness, colors, and effects.
Instructions
Discover Nanoleaf devices on the network
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:183-215 (handler)The handler function for the 'discover_nanoleaf' tool call. It invokes NanoleafClient.discover() to find devices on the network, sets the primary device if found, and returns a formatted response with discovered devices or error messages.case 'discover_nanoleaf': try { const devices = await NanoleafClient.discover(); if (devices.length > 0) { primaryDevice = new NanoleafClient(devices[0]); return { content: [ { type: 'text', text: `Found ${devices.length} Nanoleaf device(s): ${JSON.stringify(devices, null, 2)}`, }, ], }; } else { return { content: [ { type: 'text', text: 'No Nanoleaf devices found on the network', }, ], }; } } catch (error) { return { content: [ { type: 'text', text: `Error during discovery: ${error}`, }, ], }; }
- src/nanoleaf-client.ts:68-92 (helper)Core discovery logic using SSDP (Simple Service Discovery Protocol) via node-ssdp to find Nanoleaf devices on the local network by searching for 'upnp:rootdevice' and filtering for 'nanoleaf' in ST header.static async discover(): Promise<NanoleafDevice[]> { return new Promise((resolve, reject) => { const client = new Client(); const devices: NanoleafDevice[] = []; const timeout = setTimeout(() => { client.stop(); resolve(devices); }, 5000); client.on('response', (headers: any, statusCode: number, rinfo: any) => { if (headers.ST && headers.ST.includes('nanoleaf')) { const location = headers.LOCATION; if (location) { const url = new URL(location); devices.push({ ip: url.hostname, port: parseInt(url.port) || 16021, }); } } }); client.search('upnp:rootdevice'); }); }
- src/index.ts:142-148 (registration)Registration of the 'discover_nanoleaf' tool in the list of available tools, including its description and empty input schema (no parameters required).name: 'discover_nanoleaf', description: 'Discover Nanoleaf devices on the network', inputSchema: { type: 'object', properties: {}, }, },
- src/nanoleaf-client.ts:6-10 (schema)Type definition for NanoleafDevice interface used in the discovery result.export interface NanoleafDevice { ip: string; port: number; protocol?: string; authToken?: string;