discover_nanoleaf
Locate and identify Nanoleaf devices on your network for streamlined setup and management. Enables device discovery to simplify control of smart lights via MCP-compatible clients.
Instructions
Discover Nanoleaf devices on the network
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/index.ts:183-216 (handler)The handler function for the 'discover_nanoleaf' tool. It calls NanoleafClient.discover(), sets the primaryDevice if found, and returns a text response with discovered devices or error.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/index.ts:142-148 (registration)Registration of the 'discover_nanoleaf' tool in the ListTools response, including its name, description, and input schema (no parameters).name: 'discover_nanoleaf', description: 'Discover Nanoleaf devices on the network', inputSchema: { type: 'object', properties: {}, }, },
- src/nanoleaf-client.ts:68-92 (helper)Supporting static method on NanoleafClient that uses SSDP (via node-ssdp) to discover 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'); }); }