From 072d1723c910cfb813d3609ecb4dffe411ea8f67 Mon Sep 17 00:00:00 2001
From: michael <1+michael@noreply.git.casaderoll.de>
Date: Mon, 7 Sep 2026 17:46:58 +0200
Subject: [PATCH] refactor: alte eMPCby-Pfade entfernen
---
src/eMPCby/Mcp/McpToolRegistry.cs | 307 ------------------------------
1 file changed, 307 deletions(-)
delete mode 100644 src/eMPCby/Mcp/McpToolRegistry.cs
diff --git a/src/eMPCby/Mcp/McpToolRegistry.cs b/src/eMPCby/Mcp/McpToolRegistry.cs
deleted file mode 100644
index 9fa7f58..0000000
--- a/src/eMPCby/Mcp/McpToolRegistry.cs
+++ /dev/null
@@ -1,307 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.Json;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.Serialization;
-
-namespace eMPCby.Mcp
-{
- ///
- /// MCP-Tool-Registry: parst JSON-RPC 2.0 Requests (initialize, tools/list, tools/call)
- /// und implementiert die Emby-Tools direkt über die injizierten Emby-Dienste.
- /// Request-Parsing läuft über System.Text.Json (robust gegenüber Emby's Newtonsoft-Serializer).
- ///
- public class McpToolRegistry
- {
- private readonly ILogger _logger;
- private readonly IJsonSerializer _json;
-
- public McpToolRegistry(ILogger logger, IJsonSerializer json)
- {
- _logger = logger;
- _json = json;
- }
-
- private ISessionManager Sessions => Plugin.Instance?.SessionManager;
- private ILibraryManager Library => Plugin.Instance?.LibraryManager;
- private IUserManager Users => Plugin.Instance?.UserManager;
-
- // ---------- JSON-RPC 2.0 Handler ----------
-
- public object HandleRequest(string body)
- {
- JsonElement root;
- try
- {
- using (var doc = JsonDocument.Parse(body))
- {
- root = doc.RootElement.Clone();
- }
- }
- catch (Exception ex)
- {
- return RpcError(default, -32700, "Parse error: " + ex.Message);
- }
-
- if (root.ValueKind != JsonValueKind.Object)
- return RpcError(default, -32700, "Parse error: Request ist kein JSON-Objekt");
-
- var id = root.TryGetProperty("id", out var idEl) ? idEl.Clone() : default;
- var method = root.TryGetProperty("method", out var mEl) && mEl.ValueKind == JsonValueKind.String
- ? mEl.GetString() : null;
- var hasParams = root.TryGetProperty("params", out var pEl) && pEl.ValueKind == JsonValueKind.Object;
-
- switch (method)
- {
- case "initialize":
- return RpcResult(id, new
- {
- protocolVersion = "2024-11-05",
- serverInfo = new { name = "eMPCby", version = "1.0.0" },
- capabilities = new { tools = new { listChanged = false } }
- });
-
- case "notifications/initialized":
- return null; // Notification → keine Antwort
-
- case "tools/list":
- return RpcResult(id, new { tools = GetToolDefinitions() });
-
- case "tools/call":
- return HandleToolCall(id, hasParams ? pEl : default);
-
- default:
- return RpcError(id, -32601, "Methode nicht gefunden: " + method);
- }
- }
-
- private object HandleToolCall(JsonElement id, JsonElement p)
- {
- var name = p.ValueKind == JsonValueKind.Object && p.TryGetProperty("name", out var nEl)
- && nEl.ValueKind == JsonValueKind.String ? nEl.GetString() : null;
- var args = p.ValueKind == JsonValueKind.Object && p.TryGetProperty("arguments", out var aEl)
- && aEl.ValueKind == JsonValueKind.Object ? aEl : default;
- var hasArgs = args.ValueKind == JsonValueKind.Object;
-
- try
- {
- object result;
- switch (name)
- {
- case "emby_server_info":
- result = ToolServerInfo();
- break;
- case "emby_search":
- result = ToolSearch(hasArgs ? args : default);
- break;
- case "emby_now_playing":
- result = ToolNowPlaying();
- break;
- case "emby_get_item":
- result = ToolGetItem(hasArgs ? args : default);
- break;
- default:
- return RpcError(id, -32602, "Unbekanntes Tool: " + name);
- }
-
- return RpcResult(id, new
- {
- content = new[] { new { type = "text", text = _json.SerializeToString(result) } },
- isError = false
- });
- }
- catch (Exception ex)
- {
- _logger.ErrorException("[eMPCby] Tool-Fehler: " + name, ex);
- return RpcResult(id, new
- {
- content = new[] { new { type = "text", text = "Fehler: " + ex.Message } },
- isError = true
- });
- }
- }
-
- private static string ArgString(JsonElement args, string key)
- {
- if (args.ValueKind == JsonValueKind.Object && args.TryGetProperty(key, out var v)
- && v.ValueKind == JsonValueKind.String)
- return v.GetString();
- return null;
- }
-
- // ---------- Tool-Definitionen ----------
-
- private List