Get Key Light Color
get_key_light_colorRetrieve the current key light color as a hex code. Use this before making relative color adjustments to maintain accuracy.
Instructions
Get the current key light color as a hex color code (e.g., "#ffffff"). Query this before relative color changes to ensure accuracy. For absolute changes, you may use recently queried state from context if no manual interactions occurred.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_key_light_color"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:1213-1260 (registration)Registration of the 'get_key_light_color' tool via mcpServer.registerTool
mcpServer.registerTool( 'get_key_light_color', { title: 'Get Key Light Color', description: 'Get the current key light color as a hex color code (e.g., "#ffffff"). ' + 'Query this before relative color changes to ensure accuracy. ' + 'For absolute changes, you may use recently queried state from context if no manual interactions occurred.', inputSchema: {} }, async () => { const sessionId = getCurrentSessionId(); if (!sessionId) { return { content: [ { type: 'text', text: 'Error: No active session found.' } ], isError: true }; } try { const { state, metadata } = await getState(sessionId); const color = state.keyLight?.color || '#ffffff'; return { content: [ { type: 'text', text: formatStateResponse(color, 'Key light color', sessionId, metadata) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error retrieving key light color: ${error.message}` } ], isError: true }; } } ); - server.js:1222-1260 (handler)Handler function for the 'get_key_light_color' tool. Gets the current key light color from browser state (state.keyLight?.color) and returns it as a hex color code.
async () => { const sessionId = getCurrentSessionId(); if (!sessionId) { return { content: [ { type: 'text', text: 'Error: No active session found.' } ], isError: true }; } try { const { state, metadata } = await getState(sessionId); const color = state.keyLight?.color || '#ffffff'; return { content: [ { type: 'text', text: formatStateResponse(color, 'Key light color', sessionId, metadata) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error retrieving key light color: ${error.message}` } ], isError: true }; } } ); - server.js:1214-1221 (schema)Input schema for 'get_key_light_color' tool - empty object (no input parameters needed)
'get_key_light_color', { title: 'Get Key Light Color', description: 'Get the current key light color as a hex color code (e.g., "#ffffff"). ' + 'Query this before relative color changes to ensure accuracy. ' + 'For absolute changes, you may use recently queried state from context if no manual interactions occurred.', inputSchema: {} }, - server.js:319-327 (helper)formatStateResponse helper function used by the handler to format the response with metadata.
function formatStateResponse(value, propertyName, sessionId, metadata) { const timestamp = metadata.timestamp; const source = metadata.source; const stalenessWarning = metadata.wasCached ? ' (using cached state - browser may be disconnected)' : ''; return `${propertyName}: ${value} (queried at ${timestamp}, source: ${source}${stalenessWarning})`; } - server.js:284-316 (helper)getState helper function used by the handler to fetch current state from the browser (with cache fallback).
async function getState(sessionId) { let state; let source; let wasCached = false; // Always query browser for current state try { state = await queryStateFromBrowser(sessionId); source = 'fresh'; } catch (error) { // If query fails, fall back to cache if available (browser may be disconnected) const cached = sessionStateCache.get(sessionId); if (cached) { console.warn(`Browser query failed for session ${sessionId}, returning cached state: ${error.message}`); state = cached.state; source = 'cache'; wasCached = true; } else { // No cache available, throw error throw new Error(`Unable to retrieve state: ${error.message}. Browser may be disconnected.`); } } // Return state with metadata return { state, metadata: { source, wasCached, timestamp: new Date().toISOString() } }; }