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

@@ -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" },