docs: Emby-Plugin-Recherche (SDK, Interfaces, DI, MCP-Protokoll, Deploy)
This commit is contained in:
1 parent
74699c61d3
commit
6fe05698cf
1 file changed
+139
@@ -0,0 +1,139 @@
|
||||
# Emby-Plugin-Recherche (Stand: 07.09.2026)
|
||||
|
||||
Quellen: dev.emby.media (offizielle Doku), MediaBrowser/Emby GitHub-Wiki, MediaBrowser/Emby.Plugins (Referenz-Plugins), NuGet, Live-Inspektion des Unraid-Emby-Containers.
|
||||
|
||||
## 1. Runtime & Projekttyp
|
||||
|
||||
- Emby Server läuft auf **.NET Core 2.0+** (Linux/Mac) bzw. Mono (Windows-Legacy). Plugins werden als **.NET Standard 2.0**-Assembly gebaut und laufen auf beiden Runtimes.
|
||||
- Projektgerüst: .NET Standard 2.0 Class Library mit `PackageReference` auf `MediaBrowser.Server.Core`.
|
||||
- **Aktuelle stabile NuGet-Version: 4.9.1.90** (Beta: 4.10.0.24-beta2). Unser Server: **4.9.5.0** → 4.9.x-Paket passt.
|
||||
- Referenz-Plugins: `MediaBrowser/Emby.Plugins` (RottenTomatoes, Bookshelf, OneDrive) – RottenTomatoes ist das kleinste vollständige Beispiel.
|
||||
|
||||
## 2. Pflicht-Klassen
|
||||
|
||||
### Plugin.cs
|
||||
```csharp
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace eMPCby
|
||||
{
|
||||
public class Plugin : BasePlugin<PluginConfiguration>
|
||||
{
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override string Name => "eMPCby – emby MCP";
|
||||
public override string Description => "MCP-Server (Model Context Protocol) für AI-Agenten.";
|
||||
|
||||
/// <summary>Feste GUID – NIE ändern (Emby identifiziert das Plugin daran).</summary>
|
||||
public override string Id => "eMPCbyEmbyMcp"; // GUID-Format empfohlen
|
||||
|
||||
public static Plugin Instance { get; private set; }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### PluginConfiguration.cs
|
||||
```csharp
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace eMPCby
|
||||
{
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
public int McpPort { get; set; } = 8097;
|
||||
public string ApiKey { get; set; } = string.Empty;
|
||||
public bool Enabled { get; set; } = true;
|
||||
}
|
||||
}
|
||||
```
|
||||
- Config wird automatisch als XML gespeichert: `plugins/configurations/<PluginId>/configuration.xml`.
|
||||
|
||||
### PluginEntryPoint.cs (IServerEntryPoint)
|
||||
```csharp
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace eMPCby
|
||||
{
|
||||
public class PluginEntryPoint : IServerEntryPoint
|
||||
{
|
||||
private readonly IServerManager _serverManager;
|
||||
private readonly IMediaLibraryManager _libraryManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly INetworkManager _networkManager;
|
||||
private McpServer _mcpServer;
|
||||
|
||||
public PluginEntryPoint(IServerManager serverManager, IMediaLibraryManager libraryManager,
|
||||
IUserManager userManager, INetworkManager networkManager)
|
||||
{
|
||||
_serverManager = serverManager;
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
_networkManager = networkManager;
|
||||
}
|
||||
|
||||
public void Initialize() { /* DI-Container registrieren, Tools registrieren */ }
|
||||
|
||||
public void Start() => _mcpServer = new McpServer(Plugin.Instance.Configuration, /* deps */); _mcpServer.Start();
|
||||
|
||||
public void Dispose() => _mcpServer?.Stop();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Automatic Type Discovery
|
||||
|
||||
Emby scannt die Plugin-Assembly und registriert automatisch alle Typen mit diesen Interfaces:
|
||||
|
||||
| Interface | Zweck |
|
||||
|---|---|
|
||||
| `IServerEntryPoint` | Init/Start/Dispose beim Serverlebenszyklus – **Kern für eMPCby** |
|
||||
| `IRestfulService` | Eigene REST-Endpunkte (`/emby/<route>/...`) |
|
||||
| `IScheduledTask` | Task im Dashboard (manuell + Trigger) |
|
||||
| `IPluginConfigurationPage` | HTML-Config-Seite im Dashboard |
|
||||
| `IItemResolver` | Eigene Medientypen |
|
||||
| `IWeatherProvider`, `IImageEnhancer`, `IMetadataSaver`, `IIsoMounter`, … | weitere Hooks |
|
||||
|
||||
Kein manuelles Wiring nötig – Interface implementieren reicht.
|
||||
|
||||
## 4. Dependency Injection
|
||||
|
||||
Konstruktoren von EntryPoints/Services können beliebige Emby-Dienste anfordern. Für eMPCby relevant:
|
||||
|
||||
- `IServerManager` – Version, Status, Health
|
||||
- `IMediaLibraryManager` – Bibliotheken, Scan-Trigger
|
||||
- `IMediaSourceManager` / `IMediaEncoder` – Playback, Stream-Infos
|
||||
- `IUserManager` – User, API-Tokens
|
||||
- `ISessionManager` – Sessions, Now-Playing
|
||||
- `IScheduledTaskManager` – Tasks auflösen/ausführen
|
||||
- `IHttpClient`, `IFileSystem`, `INetworkManager`, `IZipClient` – Basis-Dienste
|
||||
|
||||
## 5. Build & Deploy (Unraid/Docker)
|
||||
|
||||
- Build: `dotnet build -c Release` → `bin/Release/netstandard2.0/eMPCby.dll`
|
||||
- Deploy: DLL nach `/mnt/user/appdata/Emby/plugins/` (Container-Pfad `/emby/plugins/`), Emby-Container neu starten.
|
||||
- Verifikation: Dashboard → Plugins → „eMPCby“ sichtbar; `plugins/configurations/<Id>/` wird angelegt.
|
||||
- Debugging: Emby-Logs unter `/mnt/user/appdata/Emby/logs/embyserver.txt`.
|
||||
|
||||
## 6. MCP-Protokoll (Kurzreferenz)
|
||||
|
||||
- Transport: HTTP (Streamable HTTP) oder stdio. Für ein eingebettetes Plugin: **HTTP-Listener auf eigenem Port** (Emby-Port 8096 bleibt unberührt).
|
||||
- JSON-RPC 2.0. Wichtige Requests:
|
||||
- `initialize` → Server-Capabilities (tools)
|
||||
- `tools/list` → Tool-Definitionen (name, description, inputSchema JSON-Schema)
|
||||
- `tools/call` → `{name, arguments}` → Ergebnis (content[] mit type=text)
|
||||
- Tool-Namen: `snake_case`, Beschreibung präzise (der LLM liest sie), inputSchema strikt.
|
||||
- Auth: statischer Key im Header (`Authorization: Bearer <key>`), Key in Plugin-Config; Port nur LAN-binden.
|
||||
|
||||
## 7. Offene Fragen / Risiken
|
||||
|
||||
- **Port-Konflikt**: 8097 muss frei sein (Unraid-Host-Port mappen im Docker-Template, falls nicht schon).
|
||||
- **Threading**: MCP-Requests laufen in eigenen Threads – Emby-Dienste sind thread-safe (DI-Instanzen sind Singletons).
|
||||
- **Emby-Update**: Bei Server-Updates ggf. NuGet-Paket-Version anpassen (4.9.x → 4.10.x).
|
||||
- **Plugin-Id**: Beim ersten Build eine echte GUID generieren und in `Plugin.Id` fest eintragen.
|
||||
Reference in new issue
Block a user