diff --git a/src/eMCPy/Configuration/configPage.html b/src/eMCPy/Configuration/configPage.html index f767b9e..bb309a8 100644 --- a/src/eMCPy/Configuration/configPage.html +++ b/src/eMCPy/Configuration/configPage.html @@ -9,7 +9,7 @@
-

eMCPy Configuration

+

eMCPy Configuration

MCP-Server (Model Context Protocol) für AI-Agenten. Läuft eingebettet in Emby auf einem eigenen Port.

@@ -50,6 +50,16 @@
+ +
+ + +
+ Nur nötig, wenn du das Dashboard über eine Domain/Reverse-Proxy nutzt und der MCP-Port dort nicht direkt erreichbar ist. + Leer = Status-Check nutzt http://<ServerHost>:<Port>/mcp. +
+
+
Status wird geladen …
diff --git a/src/eMCPy/Configuration/configPage.js b/src/eMCPy/Configuration/configPage.js index 09a12e9..541db29 100644 --- a/src/eMCPy/Configuration/configPage.js +++ b/src/eMCPy/Configuration/configPage.js @@ -11,6 +11,47 @@ define(['baseView', 'loading', 'toast'], function (BaseView, loading, toast) { return ApiClient.updatePluginConfiguration(pluginId, config); } + function buildCandidateUrls(config) { + // Kandidaten für den Status-Check, in Prioritätsreihenfolge: + // 1. Explizit konfigurierte McpUrl (z. B. hinter Reverse-Proxy) + // 2. Host des Emby-Servers + MCP-Port + // 3. Host der aktuellen Seite + MCP-Port + var urls = []; + if (config.McpUrl) { + urls.push(config.McpUrl); + } + var port = config.McpPort || 8097; + try { + var serverHost = new URL(ApiClient.serverAddress()).hostname; + urls.push('http://' + serverHost + ':' + port + '/mcp'); + } catch (e) { /* ignore */ } + try { + var pageHost = window.location.hostname; + var candidate = 'http://' + pageHost + ':' + port + '/mcp'; + if (urls.indexOf(candidate) === -1) urls.push(candidate); + } catch (e) { /* ignore */ } + return urls; + } + + function probeUrl(url, apiKey) { + var body = JSON.stringify({ + jsonrpc: '2.0', + id: 1, + method: 'initialize', + params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'emcpy-dashboard', version: '1.0' } } + }); + var headers = { 'Content-Type': 'application/json' }; + if (apiKey) { + headers['X-Api-Key'] = apiKey; + } + return fetch(url, { method: 'POST', headers: headers, body: body, cache: 'no-store' }) + .then(function (r) { + if (r.status === 401) { var e = new Error('401'); e.status = 401; throw e; } + if (!r.ok) { var e2 = new Error('HTTP ' + r.status); e2.status = r.status; throw e2; } + return r.json(); + }); + } + return class extends BaseView { constructor(view, params) { super(view, params); @@ -34,6 +75,7 @@ define(['baseView', 'loading', 'toast'], function (BaseView, loading, toast) { view.querySelector('#mcpPort').value = config.McpPort || 8097; view.querySelector('#listenAddress').value = config.ListenAddress || '0.0.0.0'; view.querySelector('#apiKey').value = config.ApiKey || ''; + view.querySelector('#mcpUrl').value = config.McpUrl || ''; this.checkServerStatus(view, config); loading.hide(); }).catch(() => { @@ -56,6 +98,7 @@ define(['baseView', 'loading', 'toast'], function (BaseView, loading, toast) { config.McpPort = port; config.ListenAddress = view.querySelector('#listenAddress').value.trim() || '0.0.0.0'; config.ApiKey = view.querySelector('#apiKey').value.trim(); + config.McpUrl = view.querySelector('#mcpUrl').value.trim(); updatePluginConfiguration(config).then(result => { loading.hide(); @@ -71,7 +114,6 @@ define(['baseView', 'loading', 'toast'], function (BaseView, loading, toast) { checkServerStatus(view, config) { const el = view.querySelector('#serverStatus'); - const port = config.McpPort || 8097; const enabled = config.EnableMcpServer !== false; if (!enabled) { @@ -80,43 +122,36 @@ define(['baseView', 'loading', 'toast'], function (BaseView, loading, toast) { return; } - el.className = 'emcpy-status pending'; - el.textContent = 'Verbinde mit MCP-Server auf Port ' + port + ' …'; - - let hostname = 'localhost'; - try { - hostname = new URL(ApiClient.serverAddress()).hostname; - } catch (e) { /* fallback */ } - - const url = 'http://' + hostname + ':' + port + '/mcp'; - const body = JSON.stringify({ - jsonrpc: '2.0', - id: 1, - method: 'initialize', - params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'emcpy-dashboard', version: '1.0' } } - }); - - const headers = { 'Content-Type': 'application/json' }; - if (config.ApiKey) { - headers['X-Api-Key'] = config.ApiKey; + const urls = buildCandidateUrls(config); + if (urls.length === 0) { + el.className = 'emcpy-status err'; + el.textContent = 'Keine URL für Status-Check verfügbar.'; + return; } - fetch(url, { method: 'POST', headers: headers, body: body, cache: 'no-store' }) - .then(r => { - if (r.status === 401) throw new Error('401'); - return r.json(); - }) - .then(data => { - const name = data.result && data.result.serverInfo ? data.result.serverInfo.name : 'MCP-Server'; - el.className = 'emcpy-status ok'; - el.innerHTML = '✓ Läuft – ' + name + ' auf Port ' + port + - ' (Endpunkt)'; - }) - .catch(err => { + el.className = 'emcpy-status pending'; + el.textContent = 'Verbinde mit MCP-Server (' + urls.length + ' Kandidaten) …'; + + // Kandidaten nacheinander probieren + const tryNext = (i) => { + if (i >= urls.length) { el.className = 'emcpy-status err'; - el.textContent = '✗ Nicht erreichbar auf Port ' + port + - (err.message === '401' ? ' (API-Key ungültig)' : ' – Port im Docker-Template gemappt?'); + el.innerHTML = '✗ Nicht erreichbar. Probiert: ' + urls.join(', ') + + '
Port im Docker-Template gemappt? Bei Domain/Proxy: MCP-URL oben setzen.'; + return; + } + probeUrl(urls[i], config.ApiKey).then(data => { + const name = data.result && data.result.serverInfo ? data.result.serverInfo.name : 'MCP-Server'; + const ver = data.result && data.result.serverInfo ? data.result.serverInfo.version : ''; + el.className = 'emcpy-status ok'; + el.innerHTML = '✓ Läuft – ' + name + ' v' + ver + ' auf ' + urls[i] + ''; + const pv = view.querySelector('#pluginVersion'); + if (pv) pv.textContent = 'v' + ver; + }).catch(err => { + tryNext(i + 1); }); + }; + tryNext(0); } onResume(options) { diff --git a/src/eMCPy/Mcp/McpToolRegistry.cs b/src/eMCPy/Mcp/McpToolRegistry.cs index 6e6079d..428e31a 100644 --- a/src/eMCPy/Mcp/McpToolRegistry.cs +++ b/src/eMCPy/Mcp/McpToolRegistry.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Collections.Generic; using System.Linq; using System.Text.Json; @@ -60,7 +61,7 @@ namespace eMCPy.Mcp return RpcResult(id, new { protocolVersion = "2024-11-05", - serverInfo = new { name = "eMCPy", version = "1.0.0" }, + serverInfo = new { name = "eMCPy", version = GetVersion() }, capabilities = new { tools = new { listChanged = false } } }); @@ -303,5 +304,14 @@ namespace eMCPy.Mcp private object RpcError(JsonElement id, int code, string message) => new { jsonrpc = "2.0", id = Plain(id), error = new { code, message } }; + + /// + /// Liest die Versionsnummer aus der Assembly (Single Source of Truth: csproj <Version>). + /// + private static string GetVersion() + { + var v = Assembly.GetExecutingAssembly().GetName().Version; + return v != null ? $"{v.Major}.{v.Minor}.{v.Build}" : "0.0.0"; + } } } diff --git a/src/eMCPy/PluginConfiguration.cs b/src/eMCPy/PluginConfiguration.cs index e119a68..bb127e6 100644 --- a/src/eMCPy/PluginConfiguration.cs +++ b/src/eMCPy/PluginConfiguration.cs @@ -7,6 +7,13 @@ namespace eMCPy public bool EnableMcpServer { get; set; } = true; public int McpPort { get; set; } = 8097; public string ListenAddress { get; set; } = "0.0.0.0"; - public string ApiKey { get; set; } = string.Empty; // leer = offen (nur LAN) + public string ApiKey { get; set; } = string.Empty; + + /// + /// Optional: Vollständige URL, über die das Dashboard den MCP-Server erreichen kann + /// (z. B. https://mcp.domain.de/mcp hinter einem Reverse-Proxy). + /// Leer = Status-Check nutzt http://<ServerHost>:<McpPort>/mcp. + /// + public string McpUrl { get; set; } = string.Empty; } } diff --git a/src/eMCPy/eMCPy.csproj b/src/eMCPy/eMCPy.csproj index 4ed08c0..2244782 100644 --- a/src/eMCPy/eMCPy.csproj +++ b/src/eMCPy/eMCPy.csproj @@ -3,8 +3,9 @@ net6.0 eMCPy eMCPy - 1.0.0 - 1.0.0 + 1.1.0 + 1.1.0 + 1.1.0 false CS1591