v1.1.0: robustes Status-Check (Multi-URL + McpUrl-Proxy-Feld), Versionsanzeige, Version aus Assembly
This commit is contained in:
1 parent
303791c3cb
commit
fb53aac329
5 files changed
+102
-39
No files matched your search
@@ -9,7 +9,7 @@
|
||||
</style>
|
||||
<div class="scrollSlider flex-direction-column padded-left padded-left-page padded-right padded-top-page padded-bottom-page">
|
||||
<div class="readOnlyContent auto-center" style="max-width: 900px;">
|
||||
<h1 class="pageTitle">eMCPy Configuration</h1>
|
||||
<h1 class="pageTitle">eMCPy Configuration <span id="pluginVersion" style="font-size:0.6em;color:#888;font-weight:normal;"></span></h1>
|
||||
<p style="color: #999; margin-top: -0.5em; margin-bottom: 1.5em;">MCP-Server (Model Context Protocol) für AI-Agenten. Läuft eingebettet in Emby auf einem eigenen Port.</p>
|
||||
|
||||
<form id="emcpyConfigForm" class="emcpyConfigForm">
|
||||
@@ -50,6 +50,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="inputContainer" style="margin-top: 1em;">
|
||||
<label class="inputLabel" for="mcpUrl">MCP-URL (optional, für Status-Check)</label>
|
||||
<input is="emby-input" type="text" id="mcpUrl" placeholder="https://mcp.domain.de/mcp" />
|
||||
<div class="fieldDescription">
|
||||
Nur nötig, wenn du das Dashboard über eine <b>Domain/Reverse-Proxy</b> nutzt und der MCP-Port dort nicht direkt erreichbar ist.
|
||||
Leer = Status-Check nutzt <code>http://<ServerHost>:<Port>/mcp</code>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="emcpy-status pending" id="serverStatus">
|
||||
Status wird geladen …
|
||||
</div>
|
||||
|
||||
@@ -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 +
|
||||
' <a href="' + url + '" target="_blank" style="color:#4CAF50;">(Endpunkt)</a>';
|
||||
})
|
||||
.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(', ') +
|
||||
'<br><small>Port im Docker-Template gemappt? Bei Domain/Proxy: MCP-URL oben setzen.</small>';
|
||||
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 <code>' + urls[i] + '</code>';
|
||||
const pv = view.querySelector('#pluginVersion');
|
||||
if (pv) pv.textContent = 'v' + ver;
|
||||
}).catch(err => {
|
||||
tryNext(i + 1);
|
||||
});
|
||||
};
|
||||
tryNext(0);
|
||||
}
|
||||
|
||||
onResume(options) {
|
||||
|
||||
@@ -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 } };
|
||||
|
||||
/// <summary>
|
||||
/// Liest die Versionsnummer aus der Assembly (Single Source of Truth: csproj <Version>).
|
||||
/// </summary>
|
||||
private static string GetVersion()
|
||||
{
|
||||
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
return v != null ? $"{v.Major}.{v.Minor}.{v.Build}" : "0.0.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public string McpUrl { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<AssemblyName>eMCPy</AssemblyName>
|
||||
<RootNamespace>eMCPy</RootNamespace>
|
||||
<AssemblyVersion>1.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0</FileVersion>
|
||||
<Version>1.1.0</Version>
|
||||
<AssemblyVersion>1.1.0</AssemblyVersion>
|
||||
<FileVersion>1.1.0</FileVersion>
|
||||
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||
<NoWarn>CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in new issue
Block a user