feat(web): manage MCP HTTP access from settings

This commit is contained in:
Hand Sonic authored and GitHub committed 2026-09-26 00:29:23 +08:00
1 parent 705ea7464d
commit fc0d576f6d
29 files changed
+1040 -159

No files matched your search

@@ -140,6 +140,8 @@ import {
mcpHttpServerStatus,
rotateMcpHttpServerToken,
loadWebMcpHttpStatus,
saveWebMcpHttpSettings,
rotateWebMcpToken,
forgetSnippetSavedToken,
forgetWebdavSyncSecretsPassphrase,
forgetWebdavSavedPassword,
@@ -173,6 +175,7 @@ import {
type McpHttpServerSettings,
type McpHttpServerStatus,
type WebMcpHttpStatus,
type WebMcpHttpSettings,
type McpServerStatus,
type SnippetProvider,
type SnippetSyncConfig,
@@ -3303,6 +3306,11 @@ const mcpHttpSettings = ref<McpHttpServerSettings>({
});
const mcpHttpStatus = ref<McpHttpServerStatus | null>(null);
const webMcpHttpStatus = ref<WebMcpHttpStatus | null>(null);
const webMcpEnabledDraft = ref(false);
const webMcpAllowedHostsText = ref("");
const webMcpAllowedOriginsText = ref("");
const webMcpSaving = ref(false);
const webMcpError = ref("");
const mcpHttpLoading = ref(false);
const mcpHttpSaving = ref(false);
const mcpHttpError = ref("");
@@ -3808,7 +3816,12 @@ async function loadMcpHttpSettings() {
mcpHttpError.value = "";
try {
if (isWeb) {
webMcpHttpStatus.value = await loadWebMcpHttpStatus();
const status = await loadWebMcpHttpStatus();
webMcpHttpStatus.value = status;
webMcpEnabledDraft.value = status.enabled;
webMcpAllowedHostsText.value = status.allowedHosts.join("\n");
webMcpAllowedOriginsText.value = status.allowedOrigins.join("\n");
webMcpError.value = "";
return;
}
const [settings, status] = await Promise.all([loadMcpHttpServerSettings(), mcpHttpServerStatus()]);
@@ -3824,6 +3837,41 @@ async function loadMcpHttpSettings() {
}
}
async function saveWebMcpSettings() {
if (webMcpSaving.value || webMcpHttpStatus.value?.deploymentManaged) return;
webMcpSaving.value = true;
webMcpError.value = "";
const settings: WebMcpHttpSettings = {
enabled: webMcpEnabledDraft.value,
allowedHosts: mcpHttpList(webMcpAllowedHostsText.value),
allowedOrigins: mcpHttpList(webMcpAllowedOriginsText.value),
};
try {
const status = await saveWebMcpHttpSettings(settings);
webMcpHttpStatus.value = status;
webMcpEnabledDraft.value = status.enabled;
webMcpAllowedHostsText.value = status.allowedHosts.join("\n");
webMcpAllowedOriginsText.value = status.allowedOrigins.join("\n");
} catch (error: unknown) {
webMcpError.value = formatMcpHttpError(error);
} finally {
webMcpSaving.value = false;
}
}
async function rotateWebMcpAccessToken() {
if (webMcpSaving.value || webMcpHttpStatus.value?.deploymentManaged) return;
webMcpSaving.value = true;
webMcpError.value = "";
try {
webMcpHttpStatus.value = await rotateWebMcpToken();
} catch (error: unknown) {
webMcpError.value = formatMcpHttpError(error);
} finally {
webMcpSaving.value = false;
}
}
async function saveMcpHttpSettings() {
if (mcpHttpSaving.value) return;
mcpHttpSaving.value = true;
@@ -9737,25 +9785,63 @@ LIMIT 100;</pre
</TabsList>
<TabsContent value="http" class="m-0 space-y-4">
<div v-if="isWeb" class="space-y-4">
<div class="rounded-md border bg-muted/20 p-4 space-y-2">
<div class="space-y-3 border-t border-border/60 pt-3">
<div class="flex items-center justify-between gap-3">
<Label class="text-base">{{ t("settings.mcpHttpWebServiceTitle") }}</Label>
<Badge :variant="webMcpHttpStatus?.enabled ? 'default' : 'outline'">{{ webMcpHttpStatus?.enabled ? t("settings.mcpHttpStatusLabelEnabled") : t("settings.mcpHttpStatusLabelDisabled") }}</Badge>
</div>
<p class="text-xs text-muted-foreground">{{ t("settings.mcpHttpWebServiceDescription") }}</p>
<p v-if="mcpHttpError" class="text-xs text-destructive">{{ mcpHttpError }}</p>
<template v-if="webMcpHttpStatus">
<code class="block rounded border bg-background px-2 py-1.5 text-xs">{{ webMcpEndpoint }}</code>
<p v-if="!webMcpHttpStatus.enabled" class="text-xs text-muted-foreground">{{ t("settings.mcpHttpWebDisabledHint") }}</p>
<code v-else class="block overflow-x-auto rounded border bg-background px-2 py-1.5 text-xs">{{ webMcpEndpoint }}</code>
<p class="text-[11px] text-muted-foreground">
{{
t("settings.mcpHttpWebTokenSourceAndHosts", {
tokenSource: webMcpHttpStatus.tokenSource || t("settings.mcpHttpNotConfigured"),
tokenSource: webMcpHttpStatus.tokenSource === "managed" ? t("settings.mcpHttpWebManagedTokenSource") : webMcpHttpStatus.tokenSource || t("settings.mcpHttpNotConfigured"),
hosts: webMcpHttpStatus.allowedHosts.join(", ") || t("settings.mcpHttpNotConfigured"),
})
}}
</p>
<p v-if="webMcpHttpStatus.allowedOrigins.length" class="text-[11px] text-muted-foreground">{{ t("settings.mcpHttpWebAllowedOrigins", { origins: webMcpHttpStatus.allowedOrigins.join(", ") }) }}</p>
<p v-if="webMcpHttpStatus.deploymentManaged" class="text-xs text-muted-foreground">{{ t("settings.mcpHttpWebDeploymentManaged") }}</p>
<p v-else-if="!webMcpHttpStatus.managementAvailable" class="text-xs text-muted-foreground">{{ t("settings.mcpHttpWebPasswordRequired") }}</p>
<template v-else>
<div class="flex items-center justify-between gap-3 border-t border-border/60 pt-3">
<Label for="web-mcp-enabled" class="text-sm">{{ t("settings.mcpHttpWebEnableLabel") }}</Label>
<Switch id="web-mcp-enabled" v-model="webMcpEnabledDraft" :disabled="webMcpSaving" />
</div>
<div class="space-y-1.5">
<Label for="web-mcp-hosts">{{ t("settings.mcpHttpAllowedHostsLabel") }}</Label>
<textarea id="web-mcp-hosts" v-model="webMcpAllowedHostsText" rows="2" :disabled="webMcpSaving" class="min-h-16 w-full rounded-md border bg-background px-3 py-2 font-mono text-xs" placeholder="192.168.0.77:4224" />
<p class="text-[11px] text-muted-foreground">{{ t("settings.mcpHttpHostsHint") }}</p>
</div>
<div class="space-y-1.5">
<Label for="web-mcp-origins">{{ t("settings.mcpHttpAllowedOriginsLabel") }}</Label>
<textarea id="web-mcp-origins" v-model="webMcpAllowedOriginsText" rows="2" :disabled="webMcpSaving" class="min-h-16 w-full rounded-md border bg-background px-3 py-2 font-mono text-xs" placeholder="https://mcp-client.example.com" />
<p class="text-[11px] text-muted-foreground">{{ t("settings.mcpHttpWebOriginsHint") }}</p>
</div>
<div v-if="webMcpHttpStatus.enabled && webMcpHttpStatus.accessToken" class="space-y-1.5">
<div class="flex items-center justify-between gap-2">
<Label>Bearer Token</Label>
<Button type="button" variant="outline" size="sm" :disabled="webMcpSaving" @click="rotateWebMcpAccessToken">{{ t("settings.mcpHttpRotateToken") }}</Button>
</div>
<div class="flex min-w-0 items-center gap-2">
<code class="min-w-0 flex-1 overflow-x-auto rounded border bg-background px-2 py-1.5 text-xs">{{ webMcpHttpStatus.accessToken }}</code>
<Button type="button" variant="outline" size="icon" :title="t('common.copy')" @click="copyMcpText('http-token', webMcpHttpStatus.accessToken || '')">
<CheckCircle2 v-if="mcpCopied === 'http-token'" class="h-3.5 w-3.5 text-green-500" />
<Copy v-else class="h-3.5 w-3.5" />
</Button>
</div>
</div>
<p v-if="webMcpError" class="text-xs text-destructive">{{ webMcpError }}</p>
<div class="flex flex-wrap justify-end gap-2">
<Button type="button" variant="outline" size="sm" :disabled="mcpHttpLoading || webMcpSaving" @click="loadMcpHttpSettings">{{ t("settings.mcpHttpReloadStatus") }}</Button>
<Button type="button" size="sm" :disabled="webMcpSaving || (webMcpEnabledDraft && !mcpHttpList(webMcpAllowedHostsText).length)" @click="saveWebMcpSettings">{{ t("settings.mcpHttpWebSave") }}</Button>
</div>
</template>
</template>
<Button type="button" variant="outline" size="sm" :disabled="mcpHttpLoading" @click="loadMcpHttpSettings">{{ t("settings.mcpHttpReloadStatus") }}</Button>
<Button v-if="!webMcpHttpStatus || webMcpHttpStatus.deploymentManaged" type="button" variant="outline" size="sm" :disabled="mcpHttpLoading" @click="loadMcpHttpSettings">{{ t("settings.mcpHttpReloadStatus") }}</Button>
</div>
</div>