🙌 OpenHands: AI-Driven Development
feat: enable/disable an installed MCP server from its card (#16171)
Hiep Lefe693b29b0f4
diff --git a/__tests__/api/settings-service.test.ts b/__tests__/api/settings-service.test.tsindex 6ad14a4e18..68c328ba80 100644--- a/__tests__/api/settings-service.test.ts+++ b/__tests__/api/settings-service.test.ts@@ -458,6 +458,10 @@ describe("SettingsService", () => {integrations_hub: {url: "https://integrations.staging.all-hands.dev/api/mcp",headers: { Authorization: "Bearer new-key" },+ // This is the one write that skips the pre-clear, so it lands as+ // an RFC 7386 merge — `enabled` has to be spelled out because a+ // merge cannot clear a persisted `enabled: false` by omission.+ enabled: true,},},},diff --git a/__tests__/components/automations/recommended-automations.test.tsx b/__tests__/components/automations/recommended-automations.test.tsxindex 87a597fc59..89acc81350 100644--- a/__tests__/components/automations/recommended-automations.test.tsx+++ b/__tests__/components/automations/recommended-automations.test.tsx@@ -405,6 +405,30 @@ describe("recommended automations", () => {expect(draft).toBeTruthy();});+ it("prompts to install when the required MCP server is disabled", async () => {+ // A disabled server is withheld from the agent, so treating it as+ // installed would launch an automation that then fails at runtime.+ mockUseSettings.mockReturnValue({+ data: settingsWithMcpConfig({+ github: {+ url: GITHUB_HOSTED_MCP_URL,+ auth: { strategy: "bearer", value: "github-token" },+ enabled: false,+ },+ }),+ });++ renderLauncher();++ fireEvent.click(+ screen.getByTestId("recommended-automation-card-github-pr-reviewer"),+ );+ fireEvent.click(screen.getByTestId("responder-deployment-continue-local"));++ await screen.findByTestId("mcp-install-modal");+ expect(mockCreateConversationMutate).not.toHaveBeenCalled();+ });+it("ignores repeated launches once a responder deployment choice is in flight", () => {mockUseSettings.mockReturnValue({data: settingsWithGithubMcp(),diff --git a/__tests__/components/features/mcp-page/mcp-server-health.test.tsx b/__tests__/components/features/mcp-page/mcp-server-health.test.tsxindex 4373dab31b..25303df24a 100644--- a/__tests__/components/features/mcp-page/mcp-server-health.test.tsx+++ b/__tests__/components/features/mcp-page/mcp-server-health.test.tsx@@ -41,10 +41,14 @@ const OAUTH_SERVER: MCPServerConfig = {function renderCard(server: MCPServerConfig,- { onEdit = vi.fn(), onDelete = vi.fn() } = {},+ { onEdit = vi.fn(), onToggleEnabled = vi.fn() } = {},) {render(- <InstalledServerCard server={server} onEdit={onEdit} onDelete={onDelete} />,+ <InstalledServerCard+ server={server}+ onEdit={onEdit}+ onToggleEnabled={onToggleEnabled}+ />,{wrapper: ({ children }) => (<QueryClientProvider@@ -57,7 +61,7 @@ function renderCard(),},);- return { onEdit, onDelete };+ return { onEdit, onToggleEnabled };}const healthDot = () => screen.getByTestId("mcp-health-dot");diff --git a/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx b/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsxindex 82cd10f9ca..6d6530c125 100644--- a/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx+++ b/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx@@ -288,6 +288,39 @@ describe("MCPServerForm validation", () => {});});+ it("keeps a disabled server disabled when its configuration is edited", () => {+ const onSubmit = vi.fn();++ render(+ <MCPServerForm+ mode="edit"+ server={{+ id: "stdio-0",+ type: "stdio",+ name: "github",+ command: "docker",+ enabled: false,+ }}+ existingServers={[]}+ onSubmit={onSubmit}+ onCancel={noop}+ />,+ );++ fireEvent.change(screen.getByTestId("command-input"), {+ target: { value: "podman" },+ });+ fireEvent.click(screen.getByTestId("submit-button"));++ // Enable/disable lives on the card, not in this form, so an edit must+ // carry the existing state forward instead of switching the server on.+ expect(onSubmit).toHaveBeenCalledTimes(1);+ expect(onSubmit.mock.calls[0][0]).toMatchObject({+ command: "podman",+ enabled: false,+ });+ });+it("rejects duplicate URLs across sse/shttp types", () => {const onSubmit = vi.fn();diff --git a/__tests__/routes/mcp-page.test.tsx b/__tests__/routes/mcp-page.test.tsxindex d20c9f7701..d3936aa54e 100644--- a/__tests__/routes/mcp-page.test.tsx+++ b/__tests__/routes/mcp-page.test.tsx@@ -236,7 +236,7 @@ describe("MCPPage", () => {expect(await screen.findByTestId("mcp-custom-editor")).toBeInTheDocument();});- it("deletes an installed stdio server through the confirmation modal", async () => {+ it("deletes an installed stdio server through the editor", async () => {// Pre-install a Slack stdio server via the SDK-shaped mcp_config// the route reads from agent_settings.mcp_config.const settingsWithSlack = buildSettings({@@ -260,8 +260,10 @@ describe("MCPPage", () => {renderPage();- const deleteBtn = await screen.findByTestId("mcp-installed-toggle-stdio-0");- fireEvent.click(deleteBtn);+ // The card toggle is enable/disable now — removing goes through the+ // editor, opened by clicking the card itself.+ fireEvent.click(await screen.findByTestId("mcp-server-item"));+ fireEvent.click(await screen.findByTestId("mcp-custom-editor-delete"));const confirmBtn = await screen.findByTestId("confirm-button");fireEvent.click(confirmBtn);@@ -274,6 +276,88 @@ describe("MCPPage", () => {expect(sent.mcp_config).toBeNull();});+ it("disables an installed server from its card, keeping its credentials", async () => {+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue(+ buildSettings({+ agent_settings: {+ ...MOCK_DEFAULT_USER_SETTINGS.agent_settings,+ mcp_config: {+ slack: {+ command: "npx",+ args: ["-y", "@zencoderai/slack-mcp-server"],+ env: { SLACK_BOT_TOKEN: "xoxb-abc" },+ },+ acme_internal: {+ command: "npx",+ args: ["-y", "@acme/internal-mcp-server"],+ enabled: false,+ },+ },+ },+ }),+ );+ const saveSpy = vi+ .spyOn(SettingsService, "saveSettings")+ .mockResolvedValue(true);++ renderPage();++ fireEvent.click(await screen.findByTestId("mcp-installed-toggle-stdio-0"));++ await waitFor(() => expect(saveSpy).toHaveBeenCalledTimes(1));+ const sent = (saveSpy.mock.calls[0][0] as Record<string, unknown>)+ .agent_settings_diff as { mcp_config: unknown };+ // Disabling is not deleting: the entry keeps its command and secrets, and+ // the already-disabled sibling is not touched on the way through.+ expect(sent.mcp_config).toEqual({+ slack: {+ command: "npx",+ args: ["-y", "@zencoderai/slack-mcp-server"],+ env: { SLACK_BOT_TOKEN: "xoxb-abc" },+ enabled: false,+ },+ acme_internal: {+ command: "npx",+ args: ["-y", "@acme/internal-mcp-server"],+ enabled: false,+ },+ });+ });++ it("re-enables a disabled server from its card, clearing the stored flag", async () => {+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue(+ buildSettings({+ agent_settings: {+ ...MOCK_DEFAULT_USER_SETTINGS.agent_settings,+ mcp_config: {+ acme_internal: {+ command: "npx",+ args: ["-y", "@acme/internal-mcp-server"],+ enabled: false,+ },+ },+ },+ }),+ );+ const saveSpy = vi+ .spyOn(SettingsService, "saveSettings")+ .mockResolvedValue(true);++ renderPage();++ fireEvent.click(await screen.findByTestId("mcp-installed-toggle-stdio-0"));++ await waitFor(() => expect(saveSpy).toHaveBeenCalledTimes(1));+ const sent = (saveSpy.mock.calls[0][0] as Record<string, unknown>)+ .agent_settings_diff as { mcp_config: unknown };+ expect(sent.mcp_config).toEqual({+ acme_internal: {+ command: "npx",+ args: ["-y", "@acme/internal-mcp-server"],+ },+ });+ });+it("shows the catalog description and URL on installed server cards", async () => {vi.spyOn(SettingsService, "getSettings").mockResolvedValue(buildSettings({diff --git a/__tests__/utils/mcp-config.test.ts b/__tests__/utils/mcp-config.test.tsindex 828e743205..cafb71804f 100644--- a/__tests__/utils/mcp-config.test.ts+++ b/__tests__/utils/mcp-config.test.ts@@ -323,6 +323,32 @@ describe("toSdkMcpConfig", () => {});});+describe("parseMcpConfig / toSdkMcpConfig — enabled flag", () => {+ it("round-trips a disabled server without flagging its enabled siblings", () => {+ // Every mutation re-serializes the whole map, so a disabled server has to+ // survive edits made to unrelated entries. An *enabled* server must come+ // back out with no flag at all — the SDK defaults `enabled` to true, and+ // omitting it is what clears a previously persisted `enabled: false`.+ const persisted = {+ off_remote: { url: "https://off.example/mcp", enabled: false },+ on_remote: { url: "https://on.example/mcp" },+ off_stdio: { command: "/bin/off", enabled: false },+ };++ const roundTripped = toSdkMcpConfig(parseMcpConfig(persisted));++ expect(roundTripped).toEqual({+ off_remote: {+ url: "https://off.example/mcp",+ transport: "http",+ enabled: false,+ },+ on_remote: { url: "https://on.example/mcp", transport: "http" },+ off_stdio: { command: "/bin/off", enabled: false },+ });+ });+});+describe("parseMcpConfig / toSdkMcpConfig — auth: oauth round-trip", () => {it("round-trips auth metadata and state for remote OAuth servers", () => {const persisted = {diff --git a/src/api/settings-service/settings-service.api.ts b/src/api/settings-service/settings-service.api.tsindex 719c658a5f..d01ddda79a 100644--- a/src/api/settings-service/settings-service.api.ts+++ b/src/api/settings-service/settings-service.api.ts@@ -259,6 +259,35 @@ const cloudCompatibleMcpConfig = (value: unknown): unknown => {return hasWrapper ? { ...value, mcpServers: converted } : converted;};+/**+ * Spell out every server's `enabled` flag.+ *+ * `toSdkMcpConfig` omits the flag while a server is enabled and relies on the+ * pre-clear below to drop a previously persisted `enabled: false`. The one+ * write that skips the pre-clear — a cloud update carrying redacted secrets —+ * lands as an RFC 7386 merge instead, and a merge cannot clear a key by+ * omitting it. Without this, re-enabling a server on cloud would silently do+ * nothing.+ */+const withExplicitMcpEnabled = (value: unknown): unknown => {+ if (!isRecord(value)) return value;++ const hasWrapper = isRecord(value.mcpServers);+ const serverMap: Record<string, unknown> = hasWrapper+ ? (value.mcpServers as Record<string, unknown>)+ : value;++ const converted = Object.fromEntries(+ Object.entries(serverMap).map(([name, server]) =>+ isRecord(server)+ ? [name, { ...server, enabled: server.enabled !== false }]+ : [name, server],+ ),+ );++ return hasWrapper ? { ...value, mcpServers: converted } : converted;+};+const hasRedactedMcpSecrets = (mcpConfig: unknown): boolean => {const servers = getSdkMcpServerMap(mcpConfig);if (!servers) return false;@@ -628,10 +657,14 @@ class SettingsService {if (payload.agent_settings_diff) {cloudPayload.agent_settings_diff = { ...payload.agent_settings_diff };if ("mcp_config" in cloudPayload.agent_settings_diff) {- cloudPayload.agent_settings_diff.mcp_config =- cloudCompatibleMcpConfig(- cloudPayload.agent_settings_diff.mcp_config,- ) as SettingsValue;+ const mcpConfig = cloudCompatibleMcpConfig(+ cloudPayload.agent_settings_diff.mcp_config,+ );+ cloudPayload.agent_settings_diff.mcp_config = (+ shouldUseCloudMergePatchForRedactedMcpSecrets+ ? withExplicitMcpEnabled(mcpConfig)+ : mcpConfig+ ) as SettingsValue;}}if (payload.conversation_settings_diff) {diff --git a/src/components/features/automations/recommended-automations-launcher.tsx b/src/components/features/automations/recommended-automations-launcher.tsxindex 4c3c391cef..2489e865d7 100644--- a/src/components/features/automations/recommended-automations-launcher.tsx+++ b/src/components/features/automations/recommended-automations-launcher.tsx@@ -73,9 +73,13 @@ export function RecommendedAutomationsLauncher({const completedInstallRef = useRef(false);const launchInFlightRef = useRef(false);+ // A disabled server is withheld from the agent, so treating it as installed+ // would show "Connected" for an automation that then fails at runtime.const installedMcpConfig = useMemo(() =>- flattenMcpConfig(parseMcpConfig(settings?.agent_settings?.mcp_config)),+ flattenMcpConfig(+ parseMcpConfig(settings?.agent_settings?.mcp_config),+ ).filter((server) => server.enabled !== false),[settings?.agent_settings?.mcp_config],);diff --git a/src/components/features/mcp-page/installed-server-card.tsx b/src/components/features/mcp-page/installed-server-card.tsxindex 885a842c66..960e169d20 100644--- a/src/components/features/mcp-page/installed-server-card.tsx+++ b/src/components/features/mcp-page/installed-server-card.tsx@@ -21,7 +21,7 @@ import { McpServerHealthSection } from "./mcp-server-health";interface InstalledServerCardProps {server: MCPServerConfig;onEdit: () => void;- onDelete: () => void;+ onToggleEnabled: (enabled: boolean) => void;}function getServerTransportLabel(type: MCPServerConfig["type"]) {@@ -49,7 +49,7 @@ function getServerDetailLine(server: MCPServerConfig): string {export function InstalledServerCard({server,onEdit,- onDelete,+ onToggleEnabled,}: InstalledServerCardProps) {const { t } = useTranslation("openhands");const catalog = findCatalogEntryForServer(@@ -97,16 +97,17 @@ export function InstalledServerCard({</h3><p className="mt-0.5 text-xs text-tertiary-alt">{transport}</p></div>+ {/* Enable/disable, not remove: a disabled server keeps its full+ configuration (secrets included) and is simply withheld from+ the agent. Removing lives in the editor, reached by clicking+ the card. */}<CirclePlusCheckToggletestId={`mcp-installed-toggle-${server.id}`}- isSelected- onToggle={(selected) => {- if (!selected) {- onDelete();- }- }}- enableLabelKey={I18nKey.MCP$TOGGLE_ADD_SERVER}- disableLabelKey={I18nKey.MCP$TOGGLE_REMOVE_SERVER}+ isSelected={server.enabled !== false}+ onToggle={onToggleEnabled}+ enableLabelKey={I18nKey.MCP$TOGGLE_ENABLE_SERVER}+ disableLabelKey={I18nKey.MCP$TOGGLE_DISABLE_SERVER}+ disableTooltipKey={I18nKey.COMMON$DISABLE}/></header>diff --git a/src/components/features/mcp-page/installed-servers-section.tsx b/src/components/features/mcp-page/installed-servers-section.tsxindex 4e949ed2dd..bf06b49f6d 100644--- a/src/components/features/mcp-page/installed-servers-section.tsx+++ b/src/components/features/mcp-page/installed-servers-section.tsx@@ -21,7 +21,7 @@ interface InstalledServersSectionProps {/** Current search query — empty string means no filter applied. */query?: string;onEdit: (server: MCPServerConfig) => void;- onDelete: (serverId: string) => void;+ onToggleEnabled: (server: MCPServerConfig, enabled: boolean) => void;}export function InstalledServersSection({@@ -29,7 +29,7 @@ export function InstalledServersSection({hasAnyInstalled,query = "",onEdit,- onDelete,+ onToggleEnabled,}: InstalledServersSectionProps) {const { t } = useTranslation("openhands");@@ -76,7 +76,7 @@ export function InstalledServersSection({key={server.id}server={server}onEdit={() => onEdit(server)}- onDelete={() => onDelete(server.id)}+ onToggleEnabled={(enabled) => onToggleEnabled(server, enabled)}/>))}</div>diff --git a/src/components/features/settings/mcp-settings/mcp-server-form.tsx b/src/components/features/settings/mcp-settings/mcp-server-form.tsxindex 536baa09b4..4bf30b26ff 100644--- a/src/components/features/settings/mcp-settings/mcp-server-form.tsx+++ b/src/components/features/settings/mcp-settings/mcp-server-form.tsx@@ -356,6 +356,10 @@ export function MCPServerForm({const baseConfig = {id: server?.id || `${serverType}-${Date.now()}`,type: serverType,+ // The form has no enable/disable control (that lives on the card), so+ // carry the existing state forward — otherwise saving an edit to a+ // disabled server would silently switch it back on.+ ...(server?.enabled === false && { enabled: false }),};if (serverType === "sse" || serverType === "shttp") {diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex edc12fc28f..f27e27ec22 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -15197,6 +15197,40 @@"uk": "Видалити сервер","ca": "Elimina el servidor"},+ "MCP$TOGGLE_ENABLE_SERVER": {+ "en": "Enable server",+ "ja": "サーバーを有効化",+ "zh-CN": "启用服务器",+ "zh-TW": "啟用伺服器",+ "ko-KR": "서버 사용",+ "no": "Aktiver server",+ "it": "Abilita server",+ "pt": "Ativar servidor",+ "es": "Activar servidor",+ "ar": "تفعيل الخادم",+ "fr": "Activer le serveur",+ "tr": "Sunucuyu etkinleştir",+ "de": "Server aktivieren",+ "uk": "Увімкнути сервер",+ "ca": "Activa el servidor"+ },+ "MCP$TOGGLE_DISABLE_SERVER": {+ "en": "Disable server",+ "ja": "サーバーを無効化",+ "zh-CN": "禁用服务器",+ "zh-TW": "停用伺服器",+ "ko-KR": "서버 사용 안 함",+ "no": "Deaktiver server",+ "it": "Disabilita server",+ "pt": "Desativar servidor",+ "es": "Desactivar servidor",+ "ar": "تعطيل الخادم",+ "fr": "Désactiver le serveur",+ "tr": "Sunucuyu devre dışı bırak",+ "de": "Server deaktivieren",+ "uk": "Вимкнути сервер",+ "ca": "Desactiva el servidor"+ },"MCP$INSTALL_BUTTON": {"en": "Install","ja": "インストール",diff --git a/src/routes/mcp.tsx b/src/routes/mcp.tsxindex 394fe82180..3f0c8fdb7a 100644--- a/src/routes/mcp.tsx+++ b/src/routes/mcp.tsx@@ -4,14 +4,10 @@ import { ExtensionsNavigation } from "#/components/features/skills/extensions-naimport { useTranslation } from "react-i18next";import { I18nKey } from "#/i18n/declaration";import { BrandButton } from "#/components/features/settings/brand-button";-import { ConfirmationModal } from "#/components/shared/modals/confirmation-modal";import { useSettings } from "#/hooks/query/use-settings";-import { useDeleteMcpServer } from "#/hooks/mutation/use-delete-mcp-server";+import { useUpdateMcpServer } from "#/hooks/mutation/use-update-mcp-server";import { parseMcpConfig } from "#/utils/mcp-config";-import {- displayErrorToast,- displaySuccessToast,-} from "#/utils/custom-toast-handlers";+import { displayErrorToast } from "#/utils/custom-toast-handlers";import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message";import { settingsLikeMainScrollClassName } from "#/utils/settings-like-page-layout-classes";import {@@ -43,15 +39,12 @@ import {export default function MCPPage() {const { t } = useTranslation("openhands");const { data: settings, isLoading } = useSettings();- const { mutate: deleteMcpServer, isPending: isDeleting } =- useDeleteMcpServer();+ const { mutate: updateMcpServer } = useUpdateMcpServer();const [installEntry, setInstallEntry] =React.useState<MarketplaceEntry | null>(null);const [editingServer, setEditingServer] =React.useState<MCPServerConfig | null>(null);- const [serverToDelete, setServerToDelete] =- React.useState<MCPServerConfig | null>(null);const [searchQuery, setSearchQuery] = React.useState("");const [sectionFilter, setSectionFilter] =React.useState<McpSectionFilter>("all");@@ -80,28 +73,20 @@ export default function MCPPage() {setEditingServer(server);};- const handleDeleteClick = (serverId: string) => {- const target = allServers.find((s) => s.id === serverId);- if (target) setServerToDelete(target);- };-- const handleConfirmDelete = () => {- if (!serverToDelete) return;- // Pass the full server config — useDeleteMcpServer re-resolves its- // position against the fresh settings at mutation time, so a- // background refresh between this click and confirm cannot point- // us at the wrong index.- deleteMcpServer(serverToDelete, {- onSuccess: () => {- displaySuccessToast(t(I18nKey.MCP$REMOVE_SUCCESS));- setServerToDelete(null);- },- onError: (err) => {- const message = retrieveAxiosErrorMessage(err as AxiosError);- displayErrorToast(message || t(I18nKey.ERROR$GENERIC));- setServerToDelete(null);+ // Disabling withholds the server from the agent while leaving its entry —+ // and its secrets — in `mcp_config`. `useUpdateMcpServer` is reused rather+ // than given a bespoke hook because it already substitutes redacted+ // credentials, without which the save would drop them.+ const handleToggleEnabled = (server: MCPServerConfig, enabled: boolean) => {+ updateMcpServer(+ { serverId: server.id, server: { ...server, enabled } },+ {+ onError: (err) => {+ const message = retrieveAxiosErrorMessage(err as AxiosError);+ displayErrorToast(message || t(I18nKey.ERROR$GENERIC));+ },},- });+ );};if (isLoading || !settings) {@@ -165,7 +150,7 @@ export default function MCPPage() {hasAnyInstalled={allServers.length > 0}query={searchQuery}onEdit={handleEdit}- onDelete={handleDeleteClick}+ onToggleEnabled={handleToggleEnabled}/></section>) : null}@@ -196,15 +181,6 @@ export default function MCPPage() {onClose={() => setEditingServer(null)}/>)}-- {serverToDelete && (- <ConfirmationModal- text={t(I18nKey.SETTINGS$MCP_CONFIRM_DELETE)}- onCancel={() => setServerToDelete(null)}- onConfirm={handleConfirmDelete}- isConfirming={isDeleting}- />- )}</main></div>);diff --git a/src/types/mcp-server.ts b/src/types/mcp-server.tsindex 712de2d0a7..1c2ad1f88b 100644--- a/src/types/mcp-server.ts+++ b/src/types/mcp-server.ts@@ -14,6 +14,11 @@ export interface MCPServerConfig {args?: string[];env?: Record<string, string>;auth?: MCPAuthCredential;+ /**+ * Whether the agent may use this server. Absent means enabled — only an+ * explicit `false` disables, so existing configs stay untouched.+ */+ enabled?: boolean;}export interface MCPTestToolCall {diff --git a/src/types/settings.ts b/src/types/settings.tsindex 9a3a307cc6..cd761712f1 100644--- a/src/types/settings.ts+++ b/src/types/settings.ts@@ -21,6 +21,7 @@ export type MCPSSEServer = {url: string;headers?: Record<string, string>;auth?: MCPAuthCredential;+ enabled?: boolean;};export type MCPStdioServer = {@@ -28,6 +29,7 @@ export type MCPStdioServer = {command: string;args?: string[];env?: Record<string, string>;+ enabled?: boolean;};export type MCPSHTTPServer = {@@ -36,6 +38,7 @@ export type MCPSHTTPServer = {headers?: Record<string, string>;timeout?: number;auth?: MCPAuthCredential;+ enabled?: boolean;};export type MCPConfig = {diff --git a/src/utils/mcp-config.ts b/src/utils/mcp-config.tsindex 7167e40b2d..ee1034d621 100644--- a/src/utils/mcp-config.ts+++ b/src/utils/mcp-config.ts@@ -169,12 +169,22 @@ function getRemoteSecretFields(entry: {return fields;}+/**+ * Only an explicit ``false`` is carried. Every mutation round-trips the whole+ * server map through these converters, so preserving the flag here is what+ * stops adding or deleting one server from silently re-enabling another.+ */+function disabledField(server: { enabled?: boolean }) {+ return server.enabled === false ? { enabled: false as const } : {};+}+function getRemoteServerFields(server: MCPServerConfig) {return {...(server.name && { name: server.name }),url: server.url!,...(server.headers && { headers: server.headers }),...(server.auth && { auth: server.auth }),+ ...disabledField(server),};}@@ -195,6 +205,7 @@ export function toMcpStdioServer(server: MCPServerConfig): MCPStdioServer {command: server.command!,...(server.args && { args: server.args }),...(server.env && { env: server.env }),+ ...disabledField(server),};}@@ -263,6 +274,10 @@ export function parseMcpConfig(value: unknown): MCPConfig {const url = serverConfig.url as string | undefined;+ // The SDK omits ``enabled`` while it holds its default (true), so only an+ // explicit ``false`` marks a server as switched off.+ const disabled = serverConfig.enabled === false;+if (url) {const transport = serverConfig.transport as string | undefined;const auth = authCredentialFromServerConfig(serverConfig);@@ -274,6 +289,7 @@ export function parseMcpConfig(value: unknown): MCPConfig {if (name) server.name = name;if (auth) server.auth = auth;if (headers) server.headers = headers;+ if (disabled) server.enabled = false;sseServers.push(server);} else {const name = userGivenServerName(serverName, "shttp");@@ -284,6 +300,7 @@ export function parseMcpConfig(value: unknown): MCPConfig {}if (auth) server.auth = auth;if (headers) server.headers = headers;+ if (disabled) server.enabled = false;shttpServers.push(server);}} else {@@ -298,6 +315,7 @@ export function parseMcpConfig(value: unknown): MCPConfig {if (serverConfig.env) {stdioServer.env = serverConfig.env as Record<string, string>;}+ if (disabled) stdioServer.enabled = false;stdioServers.push(stdioServer);}}@@ -320,6 +338,14 @@ export function parseMcpConfig(value: unknown): MCPConfig {* persisted ahead of it, and shift the suffix on every save as the count* of other server types changes. With per-base collision suffixing,* unrelated entries keep their human-meaningful names stable across edits.+ *+ * ``enabled`` is only emitted when a server is switched off — the SDK defaults+ * it to true. Omitting it is what *clears* a previously persisted+ * ``enabled: false``, and that only works because ``saveSettings`` pre-clears+ * ``mcp_config`` to null before every write (see+ * ``settings-service.api.ts``), turning the backend's RFC 7386 merge into a+ * full replace. If that pre-clear is ever removed, re-enabling a server+ * becomes a silent no-op.*/export function toSdkMcpConfig(config: MCPConfig): SdkMcpConfig | null {const mcpConfig: SdkMcpConfig = {};@@ -340,7 +366,7 @@ export function toSdkMcpConfig(config: MCPConfig): SdkMcpConfig | null {} else {name = entry.name;server.url = entry.url;- Object.assign(server, getRemoteSecretFields(entry));+ Object.assign(server, getRemoteSecretFields(entry), disabledField(entry));}server.transport = "sse";mcpConfig[reserve(name || "sse")] = server;@@ -354,7 +380,7 @@ export function toSdkMcpConfig(config: MCPConfig): SdkMcpConfig | null {} else {name = entry.name;server.url = entry.url;- Object.assign(server, getRemoteSecretFields(entry));+ Object.assign(server, getRemoteSecretFields(entry), disabledField(entry));if (entry.timeout != null) server.timeout = entry.timeout;}mcpConfig[reserve(name || "shttp")] = server;@@ -366,6 +392,7 @@ export function toSdkMcpConfig(config: MCPConfig): SdkMcpConfig | null {};if (entry.args) server.args = entry.args;if (entry.env) server.env = entry.env;+ Object.assign(server, disabledField(entry));mcpConfig[reserve(entry.name || "stdio")] = server;}diff --git a/src/utils/mcp-installed-servers.ts b/src/utils/mcp-installed-servers.tsindex 75da45659c..0cdfb2a700 100644--- a/src/utils/mcp-installed-servers.ts+++ b/src/utils/mcp-installed-servers.ts@@ -10,6 +10,7 @@ export function flattenMcpConfig(config: MCPConfig): MCPServerConfig[] {url: typeof server === "string" ? server : server.url,headers: typeof server === "object" ? server.headers : undefined,auth: typeof server === "object" ? server.auth : undefined,+ enabled: typeof server === "object" ? server.enabled : undefined,})),...config.stdio_servers.map((server, index) => ({id: `stdio-${index}`,@@ -18,6 +19,7 @@ export function flattenMcpConfig(config: MCPConfig): MCPServerConfig[] {command: server.command,args: server.args,env: server.env,+ enabled: server.enabled,})),...config.shttp_servers.map((server, index) => ({id: `shttp-${index}`,@@ -27,6 +29,7 @@ export function flattenMcpConfig(config: MCPConfig): MCPServerConfig[] {headers: typeof server === "object" ? server.headers : undefined,timeout: typeof server === "object" ? server.timeout : undefined,auth: typeof server === "object" ? server.auth : undefined,+ enabled: typeof server === "object" ? server.enabled : undefined,})),];}