feat(network): centralize proxy settings and add MCP routing (NAN-315) (#6372)

* feat(network): share proxy settings across features and MCP (NAN-315)

* fix(network): address shared proxy review regressions

* test(network): align rebased OAuth fixtures with runtime admission

* fix(webui): configure shared proxy without leaving connection drafts

* feat(webui): add optional shared proxy authentication editor

* fix(webui): align proxy save tests and loading skeleton
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 15:49:27 +08:00
1 parent 872a83340d
commit 084b6bb394
181 files changed
+3740 -807

No files matched your search

@@ -6,6 +6,7 @@ import type { SettingsExitGuard } from "@/components/settings/contracts";
import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts";
import { SettingsFeature } from "@/components/settings/shared/SettingsFeature";
import type { EditCompletion } from "@/components/settings/shared/useEditCompletion";
import { SharedProxySetupDialog } from "@/components/settings/shared/SharedProxySetupDialog";
import { SettingsSectionSkeleton } from "@/components/settings/shared/SettingsSectionSkeleton";
import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings";
@@ -94,6 +95,7 @@ export function SettingsPage({
const [mcpSetupName, setMcpSetupName] = useState<string | null>(null);
const presetDeletedCallback = useRef<(() => void) | null>(null);
const [providerPanel, setProviderPanel] = useState<ProviderSettingsEntry | null>(null);
const [proxySetupOpen, setProxySetupOpen] = useState(false);
const providerSetupOrigin = useRef<{
trigger: HTMLButtonElement | null;
onAdded?: (provider: string) => void;
@@ -129,6 +131,9 @@ export function SettingsPage({
transcriptionDirty,
} = controller;
const { providerOAuthFlow } = modelState;
const configureProxy = settings?.runtime_config && !String(settings.runtime_config["network.proxy"] ?? "").trim()
? () => setProxySetupOpen(true)
: undefined;
const restartInProgress = isRestarting || hostEngineApplying;
const latestExitState = useRef({ requiresRestart: settings?.requires_restart, restartInProgress });
@@ -327,6 +332,7 @@ export function SettingsPage({
}}
/>
{providerPanel ? <ProvidersSettings
onConfigureProxy={configureProxy}
entry={providerPanel}
onClose={() => setProviderPanel(null)}
onProviderAdded={providerSetupOrigin.current?.onAdded
@@ -518,6 +524,7 @@ export function SettingsPage({
return (
<div className="settings-stack">
<AppsCatalogSettings
onConfigureProxy={configureProxy}
setupName={mcpSetupName}
onSetupOpened={() => setMcpSetupName(null)}
cliApps={systemState.cliApps}
@@ -793,6 +800,11 @@ export function SettingsPage({
</div>
</div>
</div>
{proxySetupOpen ? <SharedProxySetupDialog
busy={controller.runtimeConfigState.saving !== null}
onClose={() => setProxySetupOpen(false)}
onSave={controller.runtimeConfigState.saveProxy}
/> : null}
</DialogLayoutContext.Provider>
);
}
@@ -47,6 +47,7 @@ export function channelSetup(
): ChannelConfigField => ({
...localizeField(field.key),
section: field.section,
control: field.control,
});
const presentation: ChannelSetupPresentation = {
...definition,
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import type { ChannelConfigField } from "@/channel-plugins/catalog";
import { ToggleButton } from "@/components/ui/toggle-button";
import { cn } from "@/lib/utils";
function channelFieldValue(field: ChannelConfigField, values: Record<string, string>): string {
@@ -129,6 +130,25 @@ export function CredentialForm({
{error}
</span>
) : null;
if (field.control === "switch" && field.kind === "bool") {
return (
<div key={field.key} className="flex items-center justify-between gap-4 py-2">
<label htmlFor={inputId} className="min-w-0">{header}</label>
<div className="flex shrink-0 items-center gap-2">
{errorMessage}
<ToggleButton
id={inputId}
checked={selectedOption === "true"}
disabled={disabled}
aria-invalid={Boolean(error)}
aria-describedby={describedBy}
label={field.label}
onChange={(checked) => onChange(field.key, String(checked))}
/>
</div>
</div>
);
}
if (field.options?.length) {
return (
<fieldset
@@ -25,6 +25,7 @@ import { ModelAPIControl } from "@/components/settings/models/ModelAPIControl";
import { ProviderAPIControl } from "@/components/settings/models/ProviderAPIControl";
import { Button } from "@/components/ui/button";
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
import { ProxySettingsControl } from "@/components/settings/shared/ProxySettingsControl";
import {
Dialog,
DialogContent,
@@ -107,7 +108,7 @@ const CUSTOM_PROVIDER_ADVANCED_FIELDS: ProviderAdvancedField[] = [
"extra_headers",
"extra_body",
"extra_query",
"proxy",
"use_proxy",
"thinking_style",
];
@@ -381,11 +382,13 @@ function ProviderRequestOptions({
}
function ProviderAdvancedOptions({
onConfigureProxy,
fields,
form,
onChange,
children,
}: {
onConfigureProxy?: () => void;
fields: ProviderAdvancedField[];
form: ProviderForm;
onChange: (value: Partial<ProviderForm>) => void;
@@ -466,22 +469,13 @@ function ProviderAdvancedOptions({
</DropdownMenu>
</label>
) : null}
{enabled.has("proxy") ? (
<label className="block space-y-1.5 md:col-span-2">
<span className="block px-3 text-[12px] font-medium text-muted-foreground">
{tx("settings.providers.proxy", "Network proxy")}
</span>
<Input
value={form.proxy}
onChange={(event) => onChange({ proxy: event.target.value })}
placeholder="http://127.0.0.1:7890"
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
spellCheck={false}
className="h-9 rounded-full font-mono text-[12px]"
/>
</label>
{enabled.has("use_proxy") ? (
<ProxySettingsControl
className="px-3 py-2 md:col-span-2"
checked={form.useProxy}
onChange={(useProxy) => onChange({ useProxy })}
onConfigure={onConfigureProxy}
/>
) : null}
{enabled.has("region") ? (
<label className="block space-y-1.5">
@@ -535,6 +529,7 @@ type ProviderSettingsView =
| { kind: "provider"; name: string; adding: boolean };
export function ProvidersSettings({
onConfigureProxy,
entry,
onClose,
onCloseAutoFocus,
@@ -560,6 +555,7 @@ export function ProvidersSettings({
onProviderOAuthLogout,
}: {
entry: ProviderSettingsEntry;
onConfigureProxy?: () => void;
onClose: () => void;
onCloseAutoFocus: (event: Event) => void;
onProviderAdded?: (provider: string) => void;
@@ -671,7 +667,7 @@ export function ProvidersSettings({
const apiBase = form.apiBase.trim();
const advancedFields = provider.advanced_fields ?? [];
const oauthSettingsDirty = isOauthProvider && (
form.proxy.trim() !== (provider.proxy ?? "").trim()
form.useProxy !== (provider.use_proxy ?? false)
|| form.extraBody.trim() !== providerJsonValue(provider.extra_body).trim()
);
const oauthSettingsSaving = saving && providerOperation?.action === "save";
@@ -680,7 +676,7 @@ export function ProvidersSettings({
const hasOptionalProviderSetting = Boolean(
apiKey
|| apiBase
|| form.proxy.trim()
|| form.useProxy
|| form.extraHeaders.trim()
|| form.extraBody.trim()
|| form.extraQuery.trim()
@@ -787,6 +783,7 @@ export function ProvidersSettings({
/>
{supportsOauthAdvancedSettings ? (
<ProviderAdvancedOptions
onConfigureProxy={onConfigureProxy}
fields={advancedFields}
form={form}
onChange={(value) => onChangeProviderForm(provider.name, value)}
@@ -902,6 +899,7 @@ export function ProvidersSettings({
onChange={(value) => onChangeProviderForm(provider.name, value)}
/>
<ProviderAdvancedOptions
onConfigureProxy={onConfigureProxy}
fields={advancedFields}
form={form}
onChange={(value) => onChangeProviderForm(provider.name, value)}
@@ -1039,6 +1037,7 @@ export function ProvidersSettings({
</div>
</label>
<ProviderAdvancedOptions
onConfigureProxy={onConfigureProxy}
fields={CUSTOM_PROVIDER_ADVANCED_FIELDS}
form={customProviderDraft}
onChange={(value) =>
@@ -8,7 +8,7 @@ export type ProviderForm = {
apiKey: string;
apiBase: string;
api: ModelAPIConfig | null;
proxy: string;
useProxy: boolean;
extraHeaders: string;
extraBody: string;
extraQuery: string;
@@ -43,7 +43,7 @@ export function providerFormFromRow(
apiKey: "",
apiBase: provider.api_base ?? provider.default_api_base ?? "",
api: provider.api ?? null,
proxy: provider.proxy ?? "",
useProxy: provider.use_proxy ?? false,
extraHeaders: providerJsonValue(provider.extra_headers),
extraBody: providerJsonValue(provider.extra_body),
extraQuery: providerJsonValue(provider.extra_query),
@@ -60,7 +60,7 @@ export function emptyCustomProviderDraft(): CustomProviderDraft {
apiKey: "",
apiBase: "",
api: { supported_apis: ["chat_completions"], preferred_api: "chat_completions" },
proxy: "",
useProxy: false,
extraHeaders: "",
extraBody: "",
extraQuery: "",
@@ -456,7 +456,7 @@ export function useModelSettingsActions({
if (provider.provider_api_configurable) update.api = providerForm.api;
}
for (const field of provider.advanced_fields ?? []) {
if (field === "proxy") update.proxy = providerForm.proxy.trim();
if (field === "use_proxy") update.use_proxy = providerForm.useProxy;
if (field === "extra_headers") {
update.extraHeaders = providerForm.extraHeaders.trim();
}
@@ -500,7 +500,7 @@ export function useModelSettingsActions({
apiKey: draft.apiKey.trim() || undefined,
apiBase: draft.apiBase.trim(),
...(settings?.provider_api_configuration_supported ? { api: draft.api } : {}),
proxy: draft.proxy.trim(),
use_proxy: draft.useProxy,
extraHeaders: draft.extraHeaders.trim(),
extraBody: draft.extraBody.trim(),
extraQuery: draft.extraQuery.trim(),
@@ -0,0 +1,31 @@
import { useTranslation } from "react-i18next";
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
import { Button } from "@/components/ui/button";
import { ToggleButton } from "@/components/ui/toggle-button";
import { cn } from "@/lib/utils";
export function ProxySettingsControl({ checked, disabled, onChange, onConfigure, className }: {
checked: boolean;
disabled?: boolean;
onChange: (checked: boolean) => void;
onConfigure?: () => void;
className?: string;
}) {
const { t } = useTranslation();
return (
<div data-proxy-control className={cn("flex items-center justify-between gap-4", className)}>
<SettingsHint description={t("settings.network.useProxyHelp")}>
<span className="block text-[13px] font-medium leading-5 text-foreground">{t("settings.network.useProxy")}</span>
</SettingsHint>
{onConfigure ? (
<Button type="button" variant="outline" size="sm" onClick={onConfigure}
className="h-7 shrink-0 rounded-full px-3 text-[13px] font-medium leading-5">
{t("settings.network.configureProxy")}
</Button>
) : (
<ToggleButton checked={checked} disabled={disabled} onChange={onChange} label={t("settings.network.useProxy")} />
)}
</div>
);
}
@@ -39,9 +39,23 @@ function Group({ controls }: { controls: Control[] }) {
return <section><Title /><SettingsGroup>{controls.map((control, index) => <Row key={index} control={control} />)}</SettingsGroup></section>;
}
function ProxyGroup() {
return <section><Title /><SettingsGroup>
<div className="px-4 py-4 sm:px-5">
<div data-shared-proxy-skeleton className="w-full space-y-3">
<div data-proxy-address-skeleton className={cn(block, "h-10 w-full rounded-control")} />
<div className="flex h-7 items-center justify-between gap-3 py-1">
<div className={cn(block, "h-3 w-40")} /><div className={cn(block, "h-3.5 w-3.5 shrink-0")} />
</div>
</div>
</div>
</SettingsGroup></section>;
}
function RuntimeGroups({ page }: { page: RuntimeConfigPage }) {
return <>{RUNTIME_CONFIG_GROUPS.filter((group) => group.page === page).map((group) => group.id === "chat"
? <Group key={group.id} controls={["switch", "segments"]} />
: group.id === "proxy" ? <ProxyGroup key={group.id} />
: <Group key={group.id} controls={RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group.id && (!field.when || field.when.value === true)).flatMap<Control>((field) =>
field.kind === "idle-compaction" ? ["switch", "idle-timeout"] : [
field.kind === "boolean" || field.kind === "toggle" ? "switch" : field.kind === "list" ? "edit" : field.kind === "duration" ? "duration" : "input",
@@ -0,0 +1,56 @@
import { useState, type ComponentProps, type Ref } from "react";
import { ChevronDown } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Input } from "@/components/ui/input";
import { changeProxyAddress, changeProxyAuthentication, isProxyUrlReference, splitProxyUrl } from "@/lib/proxy-url";
import { cn } from "@/lib/utils";
type AddressProps = Pick<ComponentProps<typeof Input>, "id" | "aria-describedby" | "aria-invalid">;
export function SharedProxyEditor({ value, onChange, disabled, inputRef, addressProps, stackCredentials = false }: {
value: string;
onChange: (value: string) => void;
disabled?: boolean;
inputRef?: Ref<HTMLInputElement>;
addressProps?: AddressProps;
stackCredentials?: boolean;
}) {
const { t } = useTranslation();
const parts = splitProxyUrl(value);
const [expanded, setExpanded] = useState<boolean | null>(null);
const open = expanded ?? parts.userinfo !== null;
const reference = isProxyUrlReference(parts.address);
const credentialsDisabled = disabled || !parts.address.trim() || reference;
return (
<div data-shared-proxy-editor className="w-full space-y-3">
<Input {...addressProps} ref={inputRef} aria-label={t("settings.runtimeConfig.fields.network_proxy.label")}
type="text" value={parts.address} disabled={disabled} autoComplete="off" spellCheck={false}
placeholder="http://127.0.0.1:7890" className="h-10 rounded-control text-[13px]"
onChange={(event) => onChange(changeProxyAddress(value, event.target.value))} />
<button type="button" aria-expanded={open} onClick={() => setExpanded(!open)}
className="flex w-full items-center justify-between gap-3 rounded-sm py-1 text-[13px] font-medium leading-5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
{t("settings.network.authentication")}
<ChevronDown aria-hidden className={cn("h-3.5 w-3.5 shrink-0 transition-transform motion-reduce:transition-none", open && "rotate-180")} />
</button>
{open ? reference ? (
<p className="px-1 text-[12px] leading-5 text-muted-foreground">{t("settings.network.proxyReferenceAuth")}</p>
) : (
<div className={cn("grid gap-4", !stackCredentials && "sm:grid-cols-2")}>
<label className="block space-y-1">
<span className="px-1 text-[13px] leading-5 text-muted-foreground">{t("settings.network.username")}</span>
<Input type="text" value={parts.username} disabled={credentialsDisabled} autoComplete="off" spellCheck={false}
className="h-10 rounded-control text-[13px]"
onChange={(event) => { setExpanded(true); onChange(changeProxyAuthentication(value, event.target.value, parts.password)); }} />
</label>
<label className="block space-y-1">
<span className="px-1 text-[13px] leading-5 text-muted-foreground">{t("settings.network.password")}</span>
<Input type="password" value={parts.password} disabled={credentialsDisabled} autoComplete="new-password"
className="h-10 rounded-control text-[13px]"
onChange={(event) => { setExpanded(true); onChange(changeProxyAuthentication(value, parts.username, event.target.value)); }} />
</label>
</div>
) : null}
</div>
);
}
@@ -0,0 +1,68 @@
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { SharedProxyEditor } from "@/components/settings/shared/SharedProxyEditor";
export function SharedProxySetupDialog({ onClose, onSave, busy }: {
busy: boolean;
onClose: () => void;
onSave: (address: string) => Promise<void>;
}) {
const { t } = useTranslation();
const [address, setAddress] = useState("");
const [saving, setSaving] = useState(false);
const [error, setError] = useState("");
const input = useRef<HTMLInputElement>(null);
const origin = useRef(document.activeElement?.closest("[data-proxy-control]") ?? null);
const title = t("settings.runtimeConfig.fields.network_proxy.label");
useEffect(() => { if (error && !saving) input.current?.focus(); }, [error, saving]);
const save = async () => {
if (saving || busy || !address.trim()) return;
setSaving(true);
setError("");
try {
await onSave(address);
onClose();
} catch (cause) {
setError(cause instanceof Error ? cause.message : String(cause));
} finally {
setSaving(false);
}
};
return (
<Dialog open onOpenChange={(open) => { if (!open && !saving) onClose(); }}>
<DialogContent className="max-w-sm" showCloseButton={!saving}
onOpenAutoFocus={(event) => { event.preventDefault(); input.current?.focus(); }}
onCloseAutoFocus={(event) => {
event.preventDefault();
const row = origin.current;
const target = row?.querySelector<HTMLElement>('[role="switch"]') ?? row?.querySelector<HTMLElement>("button:last-child");
target?.focus();
}}
onEscapeKeyDown={(event) => { if (saving) event.preventDefault(); }}
onPointerDownOutside={(event) => { if (saving) event.preventDefault(); }}>
<form className="space-y-4" onSubmit={(event) => { event.preventDefault(); void save(); }}>
<DialogHeader>
<DialogTitle className="pr-6 text-base">
<SettingsHint description={t("settings.runtimeConfig.fields.network_proxy.help")}>{title}</SettingsHint>
</DialogTitle>
<DialogDescription>{t("settings.network.sharedProxyScope")}</DialogDescription>
</DialogHeader>
<div className="space-y-2">
<SharedProxyEditor value={address} inputRef={input} disabled={saving} stackCredentials
addressProps={{ "aria-invalid": Boolean(error), "aria-describedby": error ? "shared-proxy-setup-error" : undefined }}
onChange={(next) => { setAddress(next); setError(""); }} />
{error ? <p id="shared-proxy-setup-error" role="alert" className="break-words text-[13px] text-destructive">{error}</p> : null}
</div>
<DialogFooter>
<Button type="button" variant="outline" disabled={saving} onClick={onClose}>{t("settings.actions.cancel")}</Button>
<Button type="submit" disabled={saving || busy || !address.trim()}>{saving ? t("settings.actions.saving") : t("settings.actions.save")}</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -32,6 +32,7 @@ import {
import { useTranslation } from "react-i18next";
import { CatalogSkeleton } from "@/components/settings/shared/CatalogSkeleton";
import { ProxySettingsControl } from "@/components/settings/shared/ProxySettingsControl";
import {
DismissibleStatusMessage,
@@ -84,6 +85,7 @@ export interface CustomMcpForm {
env: string;
headers: string;
toolTimeout: string;
useProxy: boolean;
}
export const DEFAULT_CUSTOM_MCP_FORM: CustomMcpForm = {
@@ -96,11 +98,13 @@ export const DEFAULT_CUSTOM_MCP_FORM: CustomMcpForm = {
env: "",
headers: "",
toolTimeout: "30",
useProxy: false,
};
export function AppsCatalogSettings({
setupName,
onSetupOpened,
onConfigureProxy,
cliApps,
mcpPresets,
cliAppsLoading,
@@ -146,6 +150,7 @@ export function AppsCatalogSettings({
}: {
setupName?: string | null;
onSetupOpened?: () => void;
onConfigureProxy?: () => void;
cliApps: CliAppsPayload | null;
mcpPresets: McpPresetsPayload | null;
cliAppsLoading: boolean;
@@ -172,7 +177,7 @@ export function AppsCatalogSettings({
onQueryChange: (value: string) => void;
onFilterChange: (value: AppsKindFilter) => void;
onCliAction: (action: "install" | "update" | "uninstall" | "test", name: string) => void;
onMcpAction: (action: "enable" | "disable" | "remove" | "test" | "reconnect", name: string, values?: Record<string, string>) => void;
onMcpAction: (action: "enable" | "disable" | "remove" | "test" | "reconnect" | "proxy", name: string, values?: Record<string, string>) => void;
onMcpOAuthConnect: (name: string, reset?: boolean, values?: Record<string, string>) => void;
onMcpOAuthCancel: () => void;
onMcpOAuthOpen: () => void;
@@ -325,6 +330,7 @@ export function AppsCatalogSettings({
preset={item.preset}
openConnection={setupName === item.preset.name}
onConnectionOpened={onSetupOpened}
onConfigureProxy={onConfigureProxy}
values={mcpFieldValues[item.preset.name] ?? {}}
actionKey={mcpActionKey}
oauthFlow={mcpOAuthFlow?.name === item.preset.name ? mcpOAuthFlow : null}
@@ -387,6 +393,7 @@ export function AppsCatalogSettings({
{filter === "mcp" ? (
<McpCustomServerPanel
onConfigureProxy={onConfigureProxy}
form={customMcpForm}
configImport={mcpConfigImport}
actionKey={mcpActionKey}
@@ -494,6 +501,7 @@ function CliAppsCatalogRow({
function McpAppsCatalogRow({
openConnection = false,
onConnectionOpened,
onConfigureProxy,
preset,
values,
actionKey,
@@ -515,6 +523,7 @@ function McpAppsCatalogRow({
}: {
openConnection?: boolean;
onConnectionOpened?: () => void;
onConfigureProxy?: () => void;
preset: McpPresetInfo;
values: Record<string, string>;
actionKey: string | null;
@@ -526,7 +535,7 @@ function McpAppsCatalogRow({
showBrandLogos: boolean;
showTypeBadge: boolean;
onFieldChange: (presetName: string, fieldName: string, value: string) => void;
onAction: (action: "enable" | "disable" | "remove" | "test" | "reconnect", name: string, values?: Record<string, string>) => void;
onAction: (action: "enable" | "disable" | "remove" | "test" | "reconnect" | "proxy", name: string, values?: Record<string, string>) => void;
onOAuthConnect: (name: string, reset?: boolean, values?: Record<string, string>) => void;
onOAuthCancel: () => void;
onOAuthOpen: () => void;
@@ -552,7 +561,8 @@ function McpAppsCatalogRow({
const toolsBusy = actionKey === `tools:${preset.name}`;
const oauthBusy = actionKey === `oauth:${preset.name}`;
const anotherOAuthBusy = Boolean(actionKey?.startsWith("oauth:")) && !oauthBusy;
const busy = enableBusy || disableBusy || removeBusy || testBusy || reconnectBusy || toolsBusy || oauthBusy;
const proxyBusy = actionKey === `proxy:${preset.name}`;
const busy = enableBusy || disableBusy || removeBusy || testBusy || reconnectBusy || toolsBusy || oauthBusy || proxyBusy;
const agentPlugin = preset.source === "agent-plugin";
const toggleable = preset.enabled !== undefined;
const isOAuth = preset.auth === "oauth";
@@ -583,7 +593,7 @@ function McpAppsCatalogRow({
const callbackErrorId = `${callbackInputId}-error`;
const enableOrOpenSetup = () => {
if (needsSetupInput || (preset.installed && !preset.configured && hasFields)) {
if (preset.transport !== "stdio" || needsSetupInput || (preset.installed && !preset.configured && hasFields)) {
setManagementTab("connection");
setManagementOpen(true);
return;
@@ -709,7 +719,7 @@ function McpAppsCatalogRow({
defaultValue: "Manage {{name}}",
})}
visibleLabel={tx("settings.mcp.manage", "Manage")}
busy={testBusy || toolsBusy || removeBusy || reconnectBusy}
busy={testBusy || toolsBusy || removeBusy || reconnectBusy || proxyBusy}
disabled={busy}
tone={runtimeConnected ? "installed" : "default"}
onClick={() => openManagement("overview")}
@@ -741,7 +751,7 @@ function McpAppsCatalogRow({
visibleLabel={hasFields ? tx("settings.mcp.configure", "Connect") : tx("settings.mcp.enable", "Enable")}
busy={enableBusy}
onClick={() => {
if (hasFields) openManagement("connection");
if (hasFields || preset.transport !== "stdio") openManagement("connection");
else onAction("enable", preset.name, values);
}}
/>
@@ -873,6 +883,7 @@ function McpAppsCatalogRow({
{managementOpen ? (
<McpManagementDialog
onConfigureProxy={onConfigureProxy}
preset={preset}
values={values}
actionKey={actionKey}
@@ -994,6 +1005,7 @@ function appsSearchText(item: AppsCatalogItem): string {
}
function McpCustomServerPanel({
onConfigureProxy,
form,
configImport,
actionKey,
@@ -1002,6 +1014,7 @@ function McpCustomServerPanel({
onSave,
onImportConfig,
}: {
onConfigureProxy?: () => void;
form: CustomMcpForm;
configImport: string;
actionKey: string | null;
@@ -1160,6 +1173,16 @@ function McpCustomServerPanel({
</div>
) : null}
{remote ? (
<ProxySettingsControl
className="mt-3 rounded-control bg-background/55 px-3 py-3"
checked={form.useProxy}
disabled={customBusy}
onChange={(useProxy) => update("useProxy", useProxy)}
onConfigure={onConfigureProxy}
/>
) : null}
{remote && form.auth === "headers" ? (
<div className="mt-3 min-w-0">
<label
@@ -6,6 +6,7 @@ import { Check, ExternalLink, Loader2, RotateCcw, Search, Server, Trash2, X } fr
import { useTranslation } from "react-i18next";
import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
import { ProxySettingsControl } from "@/components/settings/shared/ProxySettingsControl";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -20,7 +21,7 @@ import { cn } from "@/lib/utils";
export type McpManagementTab = "overview" | "tools" | "connection";
type McpAction = "enable" | "disable" | "remove" | "test" | "reconnect";
type McpAction = "enable" | "disable" | "remove" | "test" | "reconnect" | "proxy";
interface McpManagementDialogProps {
preset: McpPresetInfo;
@@ -36,6 +37,7 @@ interface McpManagementDialogProps {
onAction: (action: McpAction, name: string, values?: Record<string, string>) => void;
onOAuthConnect: (name: string, reset?: boolean, values?: Record<string, string>) => void;
onToolsChange: (name: string, enabledTools: string[]) => void;
onConfigureProxy?: () => void;
}
export function McpManagementDialog({
@@ -52,6 +54,7 @@ export function McpManagementDialog({
onAction,
onOAuthConnect,
onToolsChange,
onConfigureProxy,
}: McpManagementDialogProps) {
const { t } = useTranslation();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
@@ -68,9 +71,14 @@ export function McpManagementDialog({
const enableBusy = actionKey === `enable:${preset.name}`;
const toolsBusy = actionKey === `tools:${preset.name}`;
const oauthBusy = actionKey === `oauth:${preset.name}`;
const busy = testBusy || reconnectBusy || removeBusy || enableBusy || toolsBusy || oauthBusy;
const proxyBusy = actionKey === `proxy:${preset.name}`;
const busy = testBusy || reconnectBusy || removeBusy || enableBusy || toolsBusy || oauthBusy || proxyBusy;
const configuredInstalled = preset.installed && preset.configured;
const isOAuth = preset.auth === "oauth";
const remote = preset.transport !== "stdio";
const useProxy = values.use_proxy ?? String(preset.use_proxy ?? false);
const proxyDirty = remote && useProxy !== String(preset.use_proxy ?? false);
const connectionValues = remote ? { ...values, use_proxy: useProxy } : values;
const inspectionRequestedRef = useRef(false);
const allowAllTools = draftEnabledTools.includes("*");
const selectedTools = new Set(allowAllTools ? toolNames : draftEnabledTools);
@@ -115,10 +123,14 @@ export function McpManagementDialog({
const connect = () => {
onOpenChange(false);
if (isOAuth) {
onOAuthConnect(preset.name, configuredInstalled, values);
onOAuthConnect(preset.name, configuredInstalled, connectionValues);
return;
}
onAction(configuredInstalled ? "reconnect" : "enable", preset.name, values);
if (configuredInstalled && proxyDirty) {
onAction("proxy", preset.name, { use_proxy: useProxy });
return;
}
onAction(configuredInstalled ? "reconnect" : "enable", preset.name, configuredInstalled ? values : connectionValues);
};
const inspectTools = () => {
@@ -219,8 +231,9 @@ export function McpManagementDialog({
/>
) : (
<ConnectionPanel
onConfigureProxy={onConfigureProxy}
preset={preset}
values={values}
values={connectionValues}
busy={busy}
connectBusy={reconnectBusy || enableBusy || oauthBusy}
removeBusy={removeBusy}
@@ -235,6 +248,23 @@ export function McpManagementDialog({
)}
</div>
{tab === "connection" && preset.installed && proxyDirty ? (
<div className="flex shrink-0 items-center justify-end border-t border-border/45 bg-background/95 px-5 py-3 sm:px-6">
<Button
type="button"
disabled={busy}
onClick={() => {
onOpenChange(false);
onAction("proxy", preset.name, { use_proxy: useProxy });
}}
className="h-9 rounded-full px-4 text-[13px] font-semibold"
>
{proxyBusy ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin motion-reduce:animate-none" aria-hidden /> : null}
{tx("settings.mcp.applyChanges", "Apply changes")}
</Button>
</div>
) : null}
{tab === "tools" && toolsDirty ? (
<div className="flex shrink-0 items-center justify-end border-t border-border/45 bg-background/95 px-5 py-3 sm:px-6">
<Button
@@ -503,6 +533,7 @@ function ToolsPanel({
}
function ConnectionPanel({
onConfigureProxy,
preset,
values,
busy,
@@ -519,6 +550,7 @@ function ConnectionPanel({
connectBusy: boolean;
removeBusy: boolean;
requiredFieldsComplete: boolean;
onConfigureProxy?: () => void;
onFieldChange: (presetName: string, fieldName: string, value: string) => void;
onConnect: () => void;
onRemove: () => void;
@@ -599,6 +631,16 @@ function ConnectionPanel({
</div>
) : null}
{preset.transport !== "stdio" ? (
<ProxySettingsControl
className="rounded-control bg-muted/40 px-4 py-3.5"
checked={values.use_proxy === "true"}
disabled={busy}
onChange={(checked) => onFieldChange(preset.name, "use_proxy", String(checked))}
onConfigure={onConfigureProxy}
/>
) : null}
{hasFields ? (
<section>
<h3 className="text-[13px] font-semibold text-foreground">
@@ -6,6 +6,8 @@ import { SettingsGroup, SettingsRow, SettingsSectionTitle, RestartRequiredNotice
import { ProviderPicker } from "@/components/settings/shared/ModelControls";
import { TimezonePicker } from "@/components/settings/shared/TimezonePicker";
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
import { SharedProxyEditor } from "@/components/settings/shared/SharedProxyEditor";
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
import { ShellRuntimeControl } from "@/components/settings/system/ShellRuntimeControl";
import { IdleCompactionControl } from "@/components/settings/system/IdleCompactionControl";
import { Input } from "@/components/ui/input";
@@ -145,7 +147,18 @@ export function useRuntimeConfigSettings(
change(field, next);
void save(field.group, { [field.path]: next });
};
return { value, visible, dirty, discard, change, commit, reject, save, saveList, saving, errors, invalidField, saved };
const saveProxy = async (next: string) => {
setSaving("proxy");
try {
const payload = await updateRuntimeConfigSettings(client, { "network.proxy": next.trim() || null });
applyPayload(payload, { preserveAgentForm: true, preserveCapabilityForms: true });
discard("proxy");
setSaved((prev) => ({ ...prev, proxy: true }));
} finally {
setSaving(null);
}
};
return { value, visible, dirty, discard, change, commit, reject, save, saveList, saveProxy, saving, errors, invalidField, saved };
}
export type RuntimeConfigController = ReturnType<typeof useRuntimeConfigSettings>;
@@ -184,7 +197,9 @@ export function RuntimeConfigSettings({
const inlineError = fields.some((field) => field.kind === "duration" && state.invalidField === field.path);
const section = (
<section key={group.id} aria-label={title}>
<SettingsSectionTitle>{title}</SettingsSectionTitle>
<SettingsSectionTitle>{group.id === "proxy"
? <SettingsHint description={tr("fields.network_proxy.help")}>{title}</SettingsHint>
: title}</SettingsSectionTitle>
<form noValidate onSubmit={(event) => { event.preventDefault(); void state.save(group.id); }}
onBlur={(event) => {
if (event.relatedTarget && event.currentTarget.contains(event.relatedTarget)) return;
@@ -221,6 +236,14 @@ export function RuntimeConfigSettings({
: [...field.options ?? []];
// Keep a configured preset visible if it is no longer available.
if (field.kind === "preset" && current && !options.includes(String(current))) options.push(String(current));
if (field.path === "network.proxy") return (
<div key={field.path} className="px-4 py-4 sm:px-5">
<span id={`${id}-help`} className="sr-only">{help}</span>
<SharedProxyEditor value={String(current)} addressProps={common}
disabled={disabled || state.saving !== null || isRestarting}
onChange={(next) => state.change(field, next)} />
</div>
);
return (
<SettingsRow key={field.path} title={text} description={help}>
<span id={`${id}-help`} className="sr-only">{help}</span>
@@ -306,6 +306,20 @@ export function createSystemSettingsActions({
setAutomations(payload);
};
const retireMcpProxyDrafts = (names: string[]) => {
setMcpFieldValues((prev) => {
const next = { ...prev };
for (const name of names) {
const key = name.trim().toLowerCase();
if (prev[key]?.use_proxy === undefined) continue;
const fields = { ...prev[key] };
delete fields.use_proxy;
next[key] = fields;
}
return next;
});
};
const closeMcpOAuthPopup = () => {
const popup = mcpOAuthPopupRef.current;
mcpOAuthPopupRef.current = null;
@@ -390,6 +404,7 @@ export function createSystemSettingsActions({
try {
const payload = await fetchMcpPresets(getToken());
setMcpPresets(payload);
retireMcpProxyDrafts([flow.name]);
notifyMcpPresetsChanged(payload);
setMcpMessage(null);
setMcpError(null);
@@ -560,7 +575,7 @@ export function createSystemSettingsActions({
};
const handleMcpPresetAction = async (
action: "enable" | "disable" | "remove" | "test" | "reconnect",
action: "enable" | "disable" | "remove" | "test" | "reconnect" | "proxy",
name: string,
values: Record<string, string> = {},
) => {
@@ -578,6 +593,12 @@ export function createSystemSettingsActions({
if (payload.requires_restart) {
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
}
if (
(action === "proxy" || action === "remove")
&& payload.last_action?.ok !== false
) {
retireMcpProxyDrafts([name]);
}
await maybeRestartHostEngine(payload);
if (action === "enable") {
setMcpFieldValues((prev) => ({ ...prev, [name]: {} }));
@@ -615,6 +636,7 @@ export function createSystemSettingsActions({
? customMcpForm.headers
: "",
tool_timeout: customMcpForm.toolTimeout,
...(customMcpForm.transport !== "stdio" ? { use_proxy: String(customMcpForm.useProxy) } : {}),
});
setMcpPresets(payload);
applyMcpActionFeedback(
@@ -622,6 +644,9 @@ export function createSystemSettingsActions({
false,
expectsOAuthAuthorization ? name : undefined,
);
if (payload.last_action?.ok !== false) {
retireMcpProxyDrafts([name]);
}
notifyMcpPresetsChanged(payload);
if (payload.requires_restart) {
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
@@ -643,6 +668,11 @@ export function createSystemSettingsActions({
const payload = await importMcpConfig(client, mcpConfigImport);
setMcpPresets(payload);
applyMcpActionFeedback(payload);
if (payload.last_action?.ok !== false) {
// The accepted import has been validated by the server; its response has no name list.
const config: { mcpServers?: object } = JSON.parse(mcpConfigImport);
retireMcpProxyDrafts(Object.keys(config.mcpServers ?? config));
}
notifyMcpPresetsChanged(payload);
if (payload.requires_restart) {
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
@@ -21,6 +21,7 @@ export const RUNTIME_CONFIG_GROUPS: { id: string; page: RuntimeConfigPage; enabl
{ id: "web", page: "browser" },
{ id: "shell", page: "advanced", enabledBy: "tools.exec.enable" },
{ id: "network", page: "network" },
{ id: "proxy", page: "advanced" },
{ id: "safety", page: "advanced" },
{ id: "cli", page: "advanced", enabledBy: "tools.cli_apps.enable" },
{ id: "gateway", page: "advanced" },
@@ -54,7 +55,8 @@ export const RUNTIME_CONFIG_FIELDS: RuntimeConfigField[] = [
{ group: "shell", path: "tools.exec.allowed_env_keys", kind: "list" },
{ group: "shell", path: "tools.exec.allow_patterns", kind: "list" },
{ group: "shell", path: "tools.exec.deny_patterns", kind: "list" },
{ group: "network", path: "tools.web.proxy", kind: "nullable" },
{ group: "proxy", path: "network.proxy", kind: "nullable", manual: true },
{ group: "network", path: "tools.web.use_proxy", kind: "boolean" },
{ group: "network", path: "tools.web.user_agent", kind: "nullable" },
{ group: "safety", path: "tools.restrict_to_workspace", kind: "boolean" },
{ group: "safety", path: "tools.webui_allow_remote_package_install", kind: "boolean" },