Add read-only MCP server with token access
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8328f6998
commit
49a8fa1154
34 files changed
+1625
No files matched your search
@@ -0,0 +1,109 @@
|
||||
@using Flypaper.Storage.Entities
|
||||
@using Flypaper.Storage.Settings
|
||||
@using Flypaper.Web.Mcp
|
||||
@inject McpTokenService Tokens
|
||||
@inject McpTokenStore Store
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<section class="card form" id="mcp">
|
||||
<h2>MCP-Zugriff</h2>
|
||||
<p class="muted">
|
||||
KI-Assistenten wie Claude lesen die Fänge über <code>@Endpoint</code> (nur lesend, nur im LAN).
|
||||
Jeder Zugriff braucht einen Token im Header <code>Authorization: Bearer …</code>.
|
||||
</p>
|
||||
|
||||
@if (Revoked == "revoked")
|
||||
{
|
||||
<div class="banner ok">Token widerrufen.</div>
|
||||
}
|
||||
|
||||
@if (_newToken is not null)
|
||||
{
|
||||
<div class="banner ok">
|
||||
<strong>Token für „@_newTokenName“ erstellt.</strong> Jetzt kopieren, er wird nicht noch einmal angezeigt:
|
||||
<code class="token">@_newToken</code>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Tokens.UsesEnvironmentToken)
|
||||
{
|
||||
<p class="muted">Zusätzlich gilt ein fester Token aus der Umgebungsvariable <code>Flypaper__Mcp__Token</code>.</p>
|
||||
}
|
||||
|
||||
@if (_tokens.Count > 0)
|
||||
{
|
||||
<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="secondary">Widerrufen</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="muted">Noch keine Tokens.</p>
|
||||
}
|
||||
|
||||
<EditForm Model="Model" FormName="mcp-create" OnSubmit="CreateAsync" action="/settings" class="danger-zone">
|
||||
<label for="mcp-token-name">Neuer Token <span class="muted">(Name, z. B. Claude Desktop)</span></label>
|
||||
<InputText id="mcp-token-name" @bind-Value="Model!.Name" autocomplete="off" maxlength="100" />
|
||||
<FieldError Errors="_errors" Field="@nameof(McpTokenModel.Name)" />
|
||||
<div class="actions">
|
||||
<button type="submit">Token erzeugen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</section>
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Flypaper.Web.Components.Pages.Settings;
|
||||
|
||||
public sealed class McpTokenModel
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -92,6 +92,8 @@ else if (Saved == "reset")
|
||||
|
||||
<PasswordSection />
|
||||
|
||||
<McpSection />
|
||||
|
||||
<section class="card">
|
||||
<h2>Nur per Umgebungsvariable</h2>
|
||||
<p class="muted">Gelten ab Containerstart und lassen sich hier nicht ändern.</p>
|
||||
|
||||
Reference in new issue
Block a user