McpPort.'/mcp'); curl_setopt_array($c, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true, CURLOPT_HTTPHEADER=>['Content-Type: application/json','X-Api-Key: '.(string)$x->ApiKey], CURLOPT_POSTFIELDS=>json_encode(['jsonrpc'=>'2.0','id'=>$calls,'method'=>$method,'params'=>$params]),CURLOPT_TIMEOUT=>90]); $body = curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c); if ($code !== 200) throw new RuntimeException('MCP request failed: HTTP '.$code); $r = json_decode($body,true,512,JSON_THROW_ON_ERROR); if (isset($r['error'])) throw new RuntimeException('MCP JSON-RPC error'); return $r['result']; } function requireTrue($ok,$message) { if (!$ok) throw new RuntimeException($message); } function callTool($name,$args) { $r=rpc('tools/call',['name'=>$name,'arguments'=>(object)$args]); requireTrue(empty($r['isError']), 'MCP tool failed: '.$name.' – '.($r['content'][0]['text'] ?? '')); return json_decode($r['content'][0]['text'],true,512,JSON_THROW_ON_ERROR); } $init=rpc('initialize',['protocolVersion'=>'2025-06-18']); requireTrue($init['serverInfo']['version']==='1.5.0','Expected active 1.5.0'); requireTrue($init['protocolVersion']==='2025-06-18','Protocol negotiation'); requireTrue(rpc('ping',(object)[])==[],'ping'); $tools=array_column(rpc('tools/list',(object)[])['tools'],'name'); requireTrue(count($tools)===49,'Expected 49 tools, got '.count($tools)); $tasks=callTool('emby_tasks',[]); requireTrue($tasks['total']>0,'Scheduled tasks visible'); echo "Tasks: {$tasks['total']} (categories: ".implode(', ',$tasks['categories']).")\n"; foreach ($tasks['tasks'] as $t) echo sprintf(" %-28s %-14s %-8s %s\n",$t['key'],$t['category'],$t['state'],$t['runAllowed']?'allowed':'blocked'); $idle=array_values(array_filter($tasks['tasks'],fn($t)=>$t['runAllowed']&&$t['state']==='Idle')); if ($idle) { $p=callTool('emby_run_task',['key'=>$idle[0]['key']]); requireTrue($p['dryRun']===true&&$p['status']==='preview','Run preview only'); } $act=callTool('emby_activity_log',['limit'=>20]); echo "Activity entries: {$act['total']}\n"; $log=callTool('emby_server_log',['lines'=>50,'level'=>'Warn']); requireTrue($log['file']!==null,'Server log found'); $raw=json_encode($log); requireTrue(!preg_match('/(api_key|X-Emby-Token|password)=(?!\*\*\*)[^&\s"]+/i',$raw),'Log redaction'); echo "Log {$log['file']}: {$log['returned']} Warn/Error entries returned\n"; $plugins=callTool('emby_plugins',[]); echo "Plugins: ".count($plugins['plugins'])." on Emby {$plugins['serverVersion']}\n"; $dev=callTool('emby_devices',['limit'=>50]); echo "Devices: {$dev['total']}\n"; $st=callTool('emby_storage',[]); foreach ($st['locations'] as $l) echo sprintf(" %-40s %s %s\n",implode(',',$l['roles']),$l['status'],isset($l['percentFree'])?$l['percentFree'].'% frei':''); $tv=callTool('emby_livetv_status',[]); $tvRaw=json_encode($tv); foreach ($tv['tuners'] as $t) requireTrue(!str_contains((string)$t['source'],'@')&&!str_contains((string)$t['source'],'?'),'Tuner source host only'); requireTrue(!preg_match('/password|username/i',$tvRaw),'No tuner/EPG credentials'); echo "Live TV: {$tv['channels']} channels, {$tv['channelsWithoutProgramNow']} without current program, guide until ".($tv['guideRange']['end'] ?? 'n/a').", refresh task ".($tv['refreshGuideTaskKey'] ?? 'n/a')."\n"; if ($tv['channels']>0) { $ch=callTool('emby_livetv_channels',['limit'=>10]); requireTrue($ch['returned']>0,'Channels page'); $first=$ch['channels'][0]; echo "First channel: {$first['number']} {$first['name']} – {$first['guideStatus']}\n"; $g=callTool('emby_livetv_guide',['channelId'=>$first['id'],'hours'=>6]); echo "Guide entries next 6h on first channel: {$g['total']}\n"; if ($first['guideStatus']!=='no_programs_next_24h') requireTrue($g['total']>0,'Program ParentId maps to channel (guide vs channels consistent)'); } $rec=callTool('emby_livetv_recordings',[]); echo "Timers: ".count($rec['timers']).", series timers: ".count($rec['seriesTimers'])."\n"; echo "PASS live admin/livetv acceptance ({$calls} calls, read-only).\n";