112 lines
4.1 KiB
Plaintext
112 lines
4.1 KiB
Plaintext
@using Flypaper.Storage.Entities
|
|
@using Flypaper.Storage.Settings
|
|
@using Flypaper.Web.Mcp
|
|
@inject McpTokenService Tokens
|
|
@inject McpTokenStore Store
|
|
@inject NavigationManager Navigation
|
|
|
|
<SettingsSection Id="mcp" Title="MCP-Zugriff" Description="KI-Assistenten wie Claude lesen die Fänge über das Model Context Protocol. Nur lesend und nur im LAN.">
|
|
@if (Revoked == "revoked")
|
|
{
|
|
<Notice>Token widerrufen.</Notice>
|
|
}
|
|
|
|
@if (_newToken is not null)
|
|
{
|
|
<Notice>
|
|
<strong>Token für „@_newTokenName“ erstellt.</strong> Jetzt kopieren, er wird nicht noch einmal angezeigt.
|
|
<code class="token">@_newToken</code>
|
|
</Notice>
|
|
}
|
|
|
|
<div class="s-body">
|
|
<dl class="kv">
|
|
<div><dt>Endpunkt</dt><dd class="mono">@Endpoint</dd></div>
|
|
<div><dt>Header</dt><dd class="mono">Authorization: Bearer <Token></dd></div>
|
|
@if (Tokens.UsesEnvironmentToken)
|
|
{
|
|
<div><dt>Fester Token</dt><dd>per Umgebungsvariable <code>Flypaper__Mcp__Token</code></dd></div>
|
|
}
|
|
</dl>
|
|
|
|
@if (_tokens.Count > 0)
|
|
{
|
|
<table class="s-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Erstellt</th>
|
|
<th>Zuletzt genutzt</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var token in _tokens)
|
|
{
|
|
<tr>
|
|
<td>@token.Name</td>
|
|
<td class="nowrap">@token.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</td>
|
|
<td class="nowrap">@(token.LastUsedAt?.ToLocalTime().ToString("dd.MM.yyyy HH:mm") ?? "nie")</td>
|
|
<td class="num">
|
|
<form method="post" action="/mcp-tokens/@token.Id/revoke" onsubmit="return confirm('Token „@token.Name“ widerrufen?')">
|
|
<AntiforgeryToken />
|
|
<button type="submit" class="ghost danger-text">Widerrufen</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}
|
|
else
|
|
{
|
|
<p class="empty">Noch keine Tokens.</p>
|
|
}
|
|
</div>
|
|
|
|
<EditForm Model="Model" FormName="mcp-create" OnSubmit="CreateAsync" action="/settings#mcp" class="s-foot">
|
|
<div class="inline-field">
|
|
<InputText id="mcp-token-name" @bind-Value="Model!.Name" autocomplete="off" maxlength="100" placeholder="Name, z. B. Claude Code" aria-label="Name des neuen Tokens" />
|
|
@if (_errors.TryGetValue(nameof(McpTokenModel.Name), out var nameError))
|
|
{
|
|
<span class="field-error">@nameError</span>
|
|
}
|
|
</div>
|
|
<button type="submit">Token erzeugen</button>
|
|
</EditForm>
|
|
</SettingsSection>
|
|
|
|
@code {
|
|
private IReadOnlyList<McpTokenEntity> _tokens = [];
|
|
private readonly Dictionary<string, string> _errors = [];
|
|
private string? _newToken;
|
|
private string? _newTokenName;
|
|
|
|
[SupplyParameterFromForm(FormName = "mcp-create")] private McpTokenModel? Model { get; set; }
|
|
|
|
[SupplyParameterFromQuery(Name = "mcp")] private string? Revoked { get; set; }
|
|
|
|
private string Endpoint => Navigation.BaseUri.TrimEnd('/') + McpExtensions.Path;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Model ??= new McpTokenModel();
|
|
_tokens = await Store.ListAsync();
|
|
}
|
|
|
|
private async Task CreateAsync()
|
|
{
|
|
var name = Model!.Name?.Trim();
|
|
if (string.IsNullOrEmpty(name) || name.Length > 100)
|
|
{
|
|
_errors[nameof(McpTokenModel.Name)] = "Bitte einen Namen mit höchstens 100 Zeichen angeben.";
|
|
return;
|
|
}
|
|
|
|
_newToken = await Tokens.CreateAsync(name);
|
|
_newTokenName = name;
|
|
Model.Name = null;
|
|
_tokens = await Store.ListAsync();
|
|
}
|
|
}
|