feat: scheduled tasks, admin overview and read-only Live TV tools (1.5.0)

- emby_tasks / emby_run_task / emby_cancel_task with the existing write gate
  (dryRun, write enable, API key, confirm, journal); restart/update/backup/
  restore/delete tasks blocked unless listed in the new AllowedTaskKeys.
- emby_activity_log, emby_server_log (secrets redacted, multi-line entries),
  emby_plugins, emby_devices, emby_storage.
- emby_livetv_status / _channels / _guide / _recordings; tuner and guide
  sources reduced to scheme+host, never credentials or options.
- Extra Emby services resolved via TryResolve so a missing one cannot break
  the other tools.
- Config page field for allowed task keys, docs, read-only live acceptance
  script, release package 1.5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikei386andClaude Opus 5.5 committed 2026-11-22 21:27:50 +01:00
1 parent fc4740d3bc
commit 60e4a66952
19 files changed
+1125 -9

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
<?php
// Read-only acceptance test for 1.5.0 AFTER the separately approved plugin restart.
// Run on the Emby host. Calls only read tools and previews (dryRun); never runs or cancels tasks.
// No tokens, log contents or tuner URLs are printed.
$config = $argv[1] ?? '/mnt/nvme-storage/appdata/Emby/plugins/configurations/eMCPy.xml';
$x = simplexml_load_file($config);
if (!$x) throw new RuntimeException('Cannot read local plugin configuration');
$calls = 0;
function rpc($method, $params) {
global $x, $calls;
$calls++;
$c = curl_init('http://127.0.0.1:'.(int)$x->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";