feat: expand Emby MCP with library audits, image previews and guarded FSK actions (1.4.0)
This commit is contained in:
1 parent
d586bce078
commit
4c9b8a230d
23 files changed
+1438
-20
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only inspection of actual Emby data before 1.4 activation. No secrets/media paths output."""
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from collections import Counter
|
||||
|
||||
base = os.environ['EMBY_URL'].rstrip('/')
|
||||
def get(path, query=None):
|
||||
req = urllib.request.Request(base + path + ('?' + urllib.parse.urlencode(query) if query else ''),
|
||||
headers={'X-Emby-Token': os.environ['EMBY_API_KEY']})
|
||||
with urllib.request.urlopen(req, timeout=30) as response:
|
||||
return json.load(response)
|
||||
folders = get('/Library/VirtualFolders')
|
||||
docs = [f for f in folders if f['Name'] == 'Dokumentationen']
|
||||
assert len(docs) == 1, 'Select a unique documentary library'
|
||||
page = get('/Items', {'ParentId': docs[0]['ItemId'], 'Recursive': 'true',
|
||||
'IncludeItemTypes': 'Movie,Series,Episode,Video', 'Limit': 20,
|
||||
'Fields': 'ProviderIds,MediaSources,MediaStreams,OfficialRating,CustomRating'})
|
||||
images = []
|
||||
for item in page['Items'][:3]:
|
||||
info = get('/Items/' + item['Id'] + '/Images')
|
||||
primary = [i for i in info if i['ImageType'] == 'Primary']
|
||||
images.append({'id': item['Id'], 'types': [i['ImageType'] for i in info],
|
||||
'primaryDimensions': [[i.get('Width'), i.get('Height')] for i in primary],
|
||||
'providerOriginExposed': any('Provider' in k or 'Origin' in k for i in info for k in i)})
|
||||
ratings = get('/Localization/ParentalRatings')
|
||||
print(json.dumps({'test': 'REST baseline, not new MCP execution', 'documentaryItems': page['TotalRecordCount'],
|
||||
'sampleSize': len(page['Items']), 'sampleRatings': dict(Counter(i.get('OfficialRating', '<missing>') for i in page['Items'])),
|
||||
'sampleWithMediaSources': sum(bool(i.get('MediaSources')) for i in page['Items']),
|
||||
'images': images,
|
||||
'germanRatings': [i['Name'] for i in ratings if i['Name'].startswith(('FSK-', 'DE-'))]}, indent=2))
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// Read-only acceptance test AFTER the separately approved plugin restart.
|
||||
// Run on the Emby host. No tokens or episode paths 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=>60]);
|
||||
$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,$expectError=false) {
|
||||
$r=rpc('tools/call',['name'=>$name,'arguments'=>$args]);
|
||||
if ($expectError) {requireTrue(!empty($r['isError']), 'Expected MCP tool error');return null;}
|
||||
requireTrue(empty($r['isError']), 'MCP tool failed: '.$name);
|
||||
return json_decode($r['content'][0]['text'],true,512,JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$init=rpc('initialize',(object)[]);
|
||||
requireTrue($init['serverInfo']['version']==='1.4.0','Expected loaded eMCPy 1.4.0');
|
||||
$tools=rpc('tools/list',(object)[]);
|
||||
requireTrue(count($tools['tools'])===37,'Expected 37 tools');
|
||||
$diagnostics=callTool('emby_server_diagnostics',(object)[]);
|
||||
requireTrue($diagnostics['services']['library'] && $diagnostics['services']['dto'],'Required services missing');
|
||||
$folders=callTool('emby_library_folders',(object)[]);
|
||||
$docs=array_values(array_filter($folders['folders'],fn($f)=>$f['name']==='Dokumentationen'));
|
||||
requireTrue(count($docs)===1,'Expected unique documentary library');
|
||||
$id=(string)$docs[0]['itemId'];
|
||||
$summary=[];
|
||||
foreach(['emby_image_audit','emby_rating_audit','emby_metadata_audit','emby_track_audit','emby_search_advanced'] as $name) {
|
||||
$result=callTool($name,['libraryId'=>$id,'limit'=>5]);
|
||||
$page=$name==='emby_rating_audit'?$result['page']:$result;
|
||||
requireTrue($page['scanned']<=5 && $page['returned']===count($page['items']),'Invalid page');
|
||||
$summary[$name]=['candidates'=>$page['totalCandidates'],'scanned'=>$page['scanned'],'returned'=>$page['returned']];
|
||||
if($page['hasMore']) {
|
||||
$next=callTool($name,['libraryId'=>$id,'limit'=>5,'start'=>$page['nextStart'],'expectedRevision'=>$page['inventoryRevision']]);
|
||||
$next=$name==='emby_rating_audit'?$next['page']:$next;
|
||||
requireTrue($next['start']===$page['nextStart'],'Bad next page');
|
||||
}
|
||||
}
|
||||
$search=callTool('emby_search_advanced',['libraryId'=>$id,'limit'=>2]);
|
||||
$ids=array_column($search['items'],'id');
|
||||
if($ids) {
|
||||
$batch=callTool('emby_batch_details',['ids'=>$ids]);requireTrue($batch['returned']===count($ids),'Batch mismatch');
|
||||
$image=rpc('tools/call',['name'=>'emby_image_review','arguments'=>['ids'=>$ids]]);
|
||||
requireTrue(empty($image['isError']),'Image review failed');
|
||||
$summary['imagePreviewCount']=count(array_filter($image['content'],fn($c)=>$c['type']==='image'));
|
||||
$localPrimary=false;foreach($batch['items'] as $entry)foreach($entry['images']??[] as $pic)if($pic['type']==='Primary'&&$pic['isLocalFile'])$localPrimary=true;
|
||||
if($localPrimary)requireTrue($summary['imagePreviewCount']>0,'Local primary images exist but none could be rendered');
|
||||
}
|
||||
callTool('emby_library_changes',['libraryId'=>$id,'since'=>'2026-10-01T00:00:00Z','limit'=>5]);
|
||||
callTool('emby_users',(object)[]);
|
||||
callTool('emby_playback_diagnostics',(object)[]);
|
||||
callTool('emby_scan_library',['libraryId'=>$id]); // default preview ONLY
|
||||
$movie=callTool('emby_search_advanced',['types'=>['Movie'],'limit'=>1]);
|
||||
if($movie['items']) {
|
||||
$m=$movie['items'][0];
|
||||
$rating=callTool('emby_set_rating',['id'=>$m['id'],'rating'=>'FSK-12','expectedOfficialRating'=>$m['officialRating'],
|
||||
'expectedCustomRating'=>$m['customRating'],'sourceUrl'=>'https://www.fsk.de',
|
||||
'evidence'=>'Technischer Vorschautest, keine recherchierte Freigabe; nichts speichern.']);
|
||||
requireTrue($rating['dryRun']===true,'Rating must be preview');
|
||||
$after=callTool('emby_batch_details',['ids'=>[$m['id']],'include'=>['basic']]);
|
||||
requireTrue($after['items'][0]['officialRating']===$m['officialRating']&&$after['items'][0]['customRating']===$m['customRating'],'Preview changed rating');
|
||||
callTool('emby_refresh_item',['id'=>$m['id']]); // default preview ONLY
|
||||
}
|
||||
callTool('emby_search_advanced',['libraryId'=>'invalid'],true);
|
||||
callTool('emby_image_review',[],true);
|
||||
echo json_encode(['version'=>'1.4.0','calls'=>$calls,'results'=>$summary,'mutationsExecuted'=>0,
|
||||
'note'=>'Snapshots, provider episode retrieval, duplicates and real writes tested separately with SDK doubles; no live write executed.'],JSON_PRETTY_PRINT).PHP_EOL;
|
||||
@@ -26,9 +26,9 @@ function callTool($name,$args,$expectError=false) {
|
||||
return json_decode($r['content'][0]['text'],true,512,JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$init=rpc('initialize',(object)[]);
|
||||
requireTrue($init['serverInfo']['version']==='1.3.0','Expected loaded eMCPy 1.3.0');
|
||||
requireTrue(in_array($init['serverInfo']['version'],['1.3.0','1.4.0'],true),'Expected loaded eMCPy 1.3.0 or 1.4.0');
|
||||
$tools=rpc('tools/list',(object)[]);
|
||||
requireTrue(count($tools['tools'])===18,'Expected 18 tools');
|
||||
requireTrue(count($tools['tools'])>=18,'Expected at least the existing 18 tools');
|
||||
$search=callTool('emby_search',['query'=>'Proper People','type'=>'Series']);
|
||||
requireTrue(count($search['items'])===1,'Select explicit series ID; search ambiguous');
|
||||
$id=$search['items'][0]['id'];
|
||||
|
||||
Reference in new issue
Block a user