🙌 OpenHands: AI-Driven Development
feat(mcp): let the install dialog choose between installable library options
Alonaead51b8b83e6
diff --git a/__tests__/components/features/mcp-page/install-server-modal.test.tsx b/__tests__/components/features/mcp-page/install-server-modal.test.tsxindex 5fa478e813..6b918b0333 100644--- a/__tests__/components/features/mcp-page/install-server-modal.test.tsx+++ b/__tests__/components/features/mcp-page/install-server-modal.test.tsx@@ -24,6 +24,9 @@ import {type IntegrationCatalogEntry as MarketplaceEntry,} from "@openhands/extensions/integrations";import { getMcpMarketplaceCatalog } from "#/utils/mcp-marketplace-utils";+// Sentry's entry from OpenHands/extensions#818, which adds the `mcp` and+// `api` options; the released catalog pinned here does not carry it yet.+import sentryWithTokenOption from "../../../fixtures/integrations/sentry.extensions-afb5930.json";function renderWith(ui: React.ReactNode) {return render(ui, {@@ -71,7 +74,13 @@ describe("InstallServerModal", () => {.mockResolvedValue(true);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={slack} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");@@ -113,7 +122,11 @@ describe("InstallServerModal", () => {vi.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);renderWith(- <InstallServerModal existingServers={[]} entry={slack} onClose={vi.fn()} />,+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={vi.fn()}+ />,);await screen.findByTestId("mcp-install-modal");@@ -243,7 +256,13 @@ describe("InstallServerModal", () => {.mockResolvedValue(true);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={tavily} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={tavily}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");@@ -298,7 +317,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");@@ -343,7 +368,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// The add-mcp-server mutation bails when useSettings() hasn't@@ -392,7 +423,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(getSpy).toHaveBeenCalled());fireEvent.click(screen.getByTestId("mcp-install-submit"));@@ -540,6 +577,121 @@ describe("InstallServerModal", () => {expect(saveSpy).not.toHaveBeenCalled();});+ describe("entries with several installable options", () => {+ const sentry = sentryWithTokenOption as MarketplaceEntry;++ it("selects the preferred OAuth option and offers the token option", async () => {+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={sentry}+ onClose={vi.fn()}+ />,+ );++ const tabs = await screen.findAllByRole("tab");+ expect(tabs.map((tab) => tab.textContent)).toEqual([+ "MCP$OPTION_OAUTH",+ "MCP$OPTION_API_KEY",+ ]);+ expect(tabs[0]).toHaveAttribute("aria-selected", "true");+ expect(screen.getByTestId("mcp-install-oauth-info")).toBeInTheDocument();+ expect(+ screen.queryByTestId("mcp-install-field-SENTRY_ACCESS_TOKEN"),+ ).not.toBeInTheDocument();+ });++ it("installs the personal-token option as a stdio server", async () => {+ const saveSpy = vi+ .spyOn(SettingsService, "saveSettings")+ .mockResolvedValue(true);+ const oauthSpy = vi.spyOn(McpService, "authorizeOAuth");+ const onClose = vi.fn();+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={sentry}+ onClose={onClose}+ />,+ );++ fireEvent.click(await screen.findByTestId("mcp-install-option-api"));+ expect(+ screen.queryByTestId("mcp-install-oauth-info"),+ ).not.toBeInTheDocument();+ expect(+ screen.getByTestId("mcp-install-field-command-readonly"),+ ).toHaveValue("npx -y @sentry/mcp-server");++ // The token is required before anything is saved.+ fireEvent.click(screen.getByTestId("mcp-install-submit"));+ await waitFor(() => expect(saveSpy).not.toHaveBeenCalled());++ fireEvent.change(+ screen.getByTestId("mcp-install-field-SENTRY_ACCESS_TOKEN"),+ { target: { value: "sntryu_test" } },+ );+ fireEvent.change(screen.getByTestId("mcp-install-field-SENTRY_HOST"), {+ target: { value: "sentry.example.com" },+ });+ fireEvent.click(screen.getByTestId("mcp-install-submit"));++ await waitFor(() => expect(saveSpy).toHaveBeenCalledTimes(1));+ const [payload] = saveSpy.mock.calls[0];+ const { mcp_config } = (payload as Record<string, unknown>)+ .agent_settings_diff as { mcp_config: Record<string, unknown> };+ expect(mcp_config).toEqual({+ sentry: expect.objectContaining({+ command: "npx",+ args: ["-y", "@sentry/mcp-server"],+ env: {+ SENTRY_ACCESS_TOKEN: "sntryu_test",+ SENTRY_HOST: "sentry.example.com",+ },+ }),+ });+ expect(oauthSpy).not.toHaveBeenCalled();+ await waitFor(() => expect(onClose).toHaveBeenCalled());+ });++ it("starts the chosen option's fields empty when switching back", async () => {+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={sentry}+ onClose={vi.fn()}+ />,+ );++ fireEvent.click(await screen.findByTestId("mcp-install-option-api"));+ fireEvent.change(screen.getByTestId("mcp-install-field-SENTRY_HOST"), {+ target: { value: "sentry.example.com" },+ });+ fireEvent.click(screen.getByTestId("mcp-install-option-mcp"));+ fireEvent.click(screen.getByTestId("mcp-install-option-api"));++ expect(screen.getByTestId("mcp-install-field-SENTRY_HOST")).toHaveValue(+ "",+ );+ });++ it("shows no option picker for an entry with one installable option", async () => {+ const slack = MCP_MARKETPLACE.find((e) => e.id === "slack")!;+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={vi.fn()}+ />,+ );++ await screen.findByTestId("mcp-install-field-SLACK_BOT_TOKEN");+ expect(+ screen.queryByTestId("mcp-install-options"),+ ).not.toBeInTheDocument();+ });+ });+it("styles the OAuth info box with theme surface and text tokens", async () => {const entry: MarketplaceEntry = {id: "synthetic-oauth",@@ -564,7 +716,11 @@ describe("InstallServerModal", () => {};renderWith(- <InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />,+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,);const box = await screen.findByTestId("mcp-install-oauth-info");@@ -615,7 +771,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(SettingsService.getSettings).toHaveBeenCalled());@@ -694,7 +856,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(SettingsService.getSettings).toHaveBeenCalled());@@ -743,7 +911,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);- renderWith(<InstallServerModal existingServers={[]} entry={linear} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={linear}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// Wait for useSettings() so the add-mcp-server mutation doesn't bail.await waitFor(() => expect(getSpy).toHaveBeenCalled());@@ -782,7 +956,13 @@ describe("InstallServerModal", () => {it("closes from the top-right close button", async () => {const onClose = vi.fn();const slack = MCP_MARKETPLACE.find((e) => e.id === "slack")!;- renderWith(<InstallServerModal existingServers={[]} entry={slack} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");fireEvent.click(screen.getByTestId("mcp-install-modal-close"));@@ -792,7 +972,13 @@ describe("InstallServerModal", () => {it("places Cancel before Install in the footer so the dominant action is the last focusable button", async () => {// Arrange: render with any marketplace entry so the footer is mounted.const slack = MCP_MARKETPLACE.find((e) => e.id === "slack")!;- renderWith(<InstallServerModal existingServers={[]} entry={slack} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// Act: locate both footer buttons.@@ -836,7 +1022,13 @@ describe("InstallServerModal", () => {],};- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");// Wait for settings to load so the mutation isn't a no-op.@@ -870,7 +1062,13 @@ describe("InstallServerModal", () => {.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);const time = MCP_MARKETPLACE.find((e) => e.id === "time")!;- renderWith(<InstallServerModal existingServers={[]} entry={time} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={time}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(SettingsService.getSettings).toHaveBeenCalled());@@ -896,7 +1094,13 @@ describe("InstallServerModal", () => {error_kind: "credentials",});- renderWith(<InstallServerModal existingServers={[]} entry={slack} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={slack}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// Act: fill the required fields and install.@@ -947,7 +1151,13 @@ describe("InstallServerModal", () => {],};- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(SettingsService.getSettings).toHaveBeenCalled());@@ -987,7 +1197,13 @@ describe("InstallServerModal", () => {],};- renderWith(<InstallServerModal existingServers={[]} entry={entry} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={entry}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() => expect(SettingsService.getSettings).toHaveBeenCalled());@@ -1085,7 +1301,13 @@ describe("InstallServerModal", () => {});it("pre-checks the toggle for password-type envFields", async () => {- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");const toggle = screen.getByTestId("mcp-install-save-secret-API_KEY");@@ -1093,7 +1315,13 @@ describe("InstallServerModal", () => {});it("leaves non-password envFields unchecked by default", async () => {- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");const toggle = screen.getByTestId("mcp-install-save-secret-USERNAME");@@ -1101,7 +1329,13 @@ describe("InstallServerModal", () => {});it("does not render a toggle for argFields", async () => {- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");expect(@@ -1110,7 +1344,13 @@ describe("InstallServerModal", () => {});it("toggling the checkbox updates its checked state", async () => {- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// USERNAME starts unchecked; clicking it should flip to checked.@@ -1128,7 +1368,13 @@ describe("InstallServerModal", () => {it("setValue preserves savedAsSecret state when a field value changes", async () => {// Before the ...prev bug-fix in setValue, calling onChange on any field// would reset savedAsSecret to {}, unchecking all toggles silently.- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={vi.fn()} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={vi.fn()}+ />,+ );await screen.findByTestId("mcp-install-modal");// API_KEY starts pre-checked. Typing a new value should leave it checked.@@ -1143,7 +1389,13 @@ describe("InstallServerModal", () => {it("calls createSecret for checked envFields after a successful install", async () => {vi.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() =>expect(SettingsService.getSettings).toHaveBeenCalled(),@@ -1174,7 +1426,13 @@ describe("InstallServerModal", () => {it("saves hosted MCP credentials as named secrets when configured", async () => {vi.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={SHTTP_ENTRY} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={SHTTP_ENTRY}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() =>expect(SettingsService.getSettings).toHaveBeenCalled(),@@ -1258,7 +1516,13 @@ describe("InstallServerModal", () => {it("does not call createSecret when all toggles are unchecked before install", async () => {vi.spyOn(SettingsService, "saveSettings").mockResolvedValue(true);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() =>expect(SettingsService.getSettings).toHaveBeenCalled(),@@ -1287,7 +1551,13 @@ describe("InstallServerModal", () => {new Error("forbidden"),);const onClose = vi.fn();- renderWith(<InstallServerModal existingServers={[]} entry={STDIO_ENTRY} onClose={onClose} />);+ renderWith(+ <InstallServerModal+ existingServers={[]}+ entry={STDIO_ENTRY}+ onClose={onClose}+ />,+ );await screen.findByTestId("mcp-install-modal");await waitFor(() =>expect(SettingsService.getSettings).toHaveBeenCalled(),diff --git a/__tests__/fixtures/integrations/sentry.extensions-afb5930.json b/__tests__/fixtures/integrations/sentry.extensions-afb5930.jsonnew file mode 100644index 0000000000..dac140191f--- /dev/null+++ b/__tests__/fixtures/integrations/sentry.extensions-afb5930.json@@ -0,0 +1,111 @@+{+ "id": "sentry",+ "name": "Sentry",+ "description": "Triage issues, inspect events, and run Seer fixes against your Sentry org.",+ "categories": [+ "Observability",+ "Engineering"+ ],+ "appUrl": "https://sentry.io",+ "docsUrl": "https://docs.sentry.io/product/sentry-mcp/",+ "notes": "Natural target for engineering support agents.",+ "popularityRank": 36,+ "connectionOptions": [+ {+ "id": "oauth-mcp",+ "provider": "mcp",+ "transport": {+ "kind": "shttp",+ "url": "https://mcp.sentry.dev/mcp"+ },+ "auth": {+ "strategy": "oauth2",+ "oauth": {+ "authorizationUrl": "https://sentry.io/oauth/authorize",+ "tokenUrl": "https://sentry.io/oauth/token",+ "scopes": [+ "project:read",+ "event:read",+ "org:read"+ ]+ }+ }+ },+ {+ "id": "oauth",+ "provider": "http",+ "auth": {+ "strategy": "oauth2",+ "oauth": {+ "authorizationUrl": "https://sentry.io/oauth/authorize",+ "tokenUrl": "https://sentry.io/oauth/token",+ "scopes": [+ "project:read",+ "event:read",+ "org:read"+ ]+ }+ },+ "http": {+ "apiBaseUrl": "https://sentry.io/api/0",+ "openApiUrl": "https://raw.githubusercontent.com/getsentry/sentry/master/api-docs/openapi.json"+ }+ },+ {+ "id": "mcp",+ "provider": "mcp",+ "transport": {+ "kind": "shttp",+ "url": "https://mcp.sentry.dev/mcp"+ },+ "auth": {+ "strategy": "oauth2",+ "oauth": {+ "clientAuthentication": "none"+ }+ }+ },+ {+ "id": "api",+ "provider": "mcp",+ "transport": {+ "kind": "stdio",+ "serverName": "sentry",+ "command": "npx",+ "args": [+ "-y",+ "@sentry/mcp-server"+ ],+ "envFields": [+ {+ "key": "SENTRY_ACCESS_TOKEN",+ "label": "Personal auth token",+ "type": "password",+ "placeholder": "sntryu_...",+ "required": true,+ "helperText": "Create a [personal auth token](https://docs.sentry.io/account/auth-tokens/) with org:read, project:read, project:write, team:read, team:write, event:read and event:write. With read scopes only, tools that change issues or projects fail. On a self-hosted server, create it there."+ },+ {+ "key": "SENTRY_HOST",+ "label": "Self-hosted Sentry host",+ "type": "text",+ "placeholder": "sentry.example.com",+ "required": false,+ "helperText": "Leave empty for sentry.io. For a self-hosted server, enter its hostname without https://."+ }+ ]+ },+ "auth": {+ "strategy": "api_key"+ }+ }+ ],+ "iconBg": "#362D59",+ "logoUrl": "https://cdn.simpleicons.org/sentry/FFFFFF",+ "keywords": [+ "errors",+ "observability",+ "monitoring",+ "crash"+ ]+}diff --git a/__tests__/utils/mcp-marketplace-utils.test.ts b/__tests__/utils/mcp-marketplace-utils.test.tsindex 38e51bfc8c..b37a65ebe0 100644--- a/__tests__/utils/mcp-marketplace-utils.test.ts+++ b/__tests__/utils/mcp-marketplace-utils.test.ts@@ -6,6 +6,7 @@ import {getDefaultMcpConnectionOption,getDefaultMcpTransport,getInstallableMcpConnectionOption,+ getInstallableMcpConnectionOptions,getMarketplaceEntriesByPopularity,getMarketplaceEntryById,getMcpConnectionOptions,@@ -15,7 +16,13 @@ import {marketplaceEntryMatchesQuery,urlsMatch,} from "#/utils/mcp-marketplace-utils";-import { INTEGRATION_CATALOG as MCP_MARKETPLACE } from "@openhands/extensions/integrations";+import {+ INTEGRATION_CATALOG as MCP_MARKETPLACE,+ type IntegrationCatalogEntry,+} from "@openhands/extensions/integrations";+// Sentry's entry from OpenHands/extensions#818, which adds the `mcp` and+// `api` options; the released catalog pinned here does not carry it yet.+import sentryWithTokenOption from "../fixtures/integrations/sentry.extensions-afb5930.json";const mcpMarketplace = getMcpMarketplaceCatalog(MCP_MARKETPLACE);const slackEntry = mcpMarketplace.find((e) => e.id === "slack")!;@@ -201,6 +208,77 @@ describe("getInstallableMcpConnectionOption", () => {});});+describe("getInstallableMcpConnectionOptions", () => {+ const sentryFixture = sentryWithTokenOption as IntegrationCatalogEntry;++ it("offers Sentry's OAuth and personal-token options, OAuth first", () => {+ const options = getInstallableMcpConnectionOptions(sentryFixture);++ expect(options.map((option) => option.id)).toEqual(["mcp", "api"]);+ expect(options[1].transport).toMatchObject({+ kind: "stdio",+ command: "npx",+ args: ["-y", "@sentry/mcp-server"],+ });+ expect(getInstallableMcpConnectionOption(sentryFixture)).toBe(options[0]);+ });++ it("offers only installable options for Sentry in the real catalog", () => {+ const sentry = MCP_MARKETPLACE.find((e) => e.id === "sentry")!;+ const options = getInstallableMcpConnectionOptions(sentry);++ expect(options[0]).toMatchObject({+ transport: { kind: "shttp", url: "https://mcp.sentry.dev/mcp" },+ auth: { strategy: "oauth2" },+ });+ for (const option of options) {+ expect(option.auth.oauth?.authorizationUrl).toBeUndefined();+ expect(option.auth.oauth?.tokenUrl).toBeUndefined();+ }+ });++ it("keeps a single option for entries with one installable option", () => {+ expect(+ getInstallableMcpConnectionOptions(slackEntry).map((o) => o.id),+ ).toEqual(["api"]);+ });++ it("offers one OAuth fallback when no option is directly installable", () => {+ const entry = {+ ...slackEntry,+ connectionOptions: [+ {+ id: "first",+ provider: "mcp",+ auth: {+ strategy: "oauth2",+ oauth: { authorizationUrl: "https://example.com/authorize" },+ },+ transport: { kind: "shttp", url: "https://example.com/mcp" },+ },+ {+ id: "second",+ provider: "mcp",+ auth: {+ strategy: "oauth2",+ oauth: { tokenUrl: "https://example.com/token" },+ },+ transport: { kind: "shttp", url: "https://example.com/other" },+ },+ ],+ } as typeof slackEntry;++ const options = getInstallableMcpConnectionOptions(entry);++ expect(options).toHaveLength(1);+ expect(options[0]).toMatchObject({+ id: "first",+ auth: { strategy: "oauth2" },+ });+ expect(options[0].auth.oauth).toBeUndefined();+ });+});+describe("marketplaceEntryMatchesQuery", () => {it("matches by name (case-insensitive)", () => {expect(marketplaceEntryMatchesQuery(slackEntry, "slack")).toBe(true);diff --git a/src/components/features/mcp-page/install-server-modal.tsx b/src/components/features/mcp-page/install-server-modal.tsxindex 26ef024631..8300538651 100644--- a/src/components/features/mcp-page/install-server-modal.tsx+++ b/src/components/features/mcp-page/install-server-modal.tsx@@ -28,7 +28,7 @@ import { useTestMcpServer } from "#/hooks/mutation/use-test-mcp-server";import { displaySuccessToast } from "#/utils/custom-toast-handlers";import {getMcpOAuthAuthenticationConfig,- getInstallableMcpConnectionOption,+ getInstallableMcpConnectionOptions,type McpMarketplaceConnectionOption,} from "#/utils/mcp-marketplace-utils";import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message";@@ -121,10 +121,21 @@ function getRemoteHeaderFields(return option.transport.headerFields ?? [];}-function makeInitialState(entry: MarketplaceEntry): FieldState {+function getOptionLabelKey(option: McpMarketplaceConnectionOption): I18nKey {+ if (option.auth.strategy === "oauth2") return I18nKey.MCP$OPTION_OAUTH;+ if (["api_key", "bearer"].includes(option.auth.strategy)) {+ return I18nKey.MCP$OPTION_API_KEY;+ }+ return option.transport.kind === "stdio"+ ? I18nKey.MCP$OPTION_LOCAL+ : I18nKey.MCP$OPTION_REMOTE;+}++function makeInitialState(+ option: McpMarketplaceConnectionOption | undefined,+): FieldState {const values: Record<string, string> = {};const savedAsSecret: Record<string, boolean> = {};- const option = getInstallableMcpConnectionOption(entry);const template = option?.transport;if (template?.kind === "stdio") {for (const field of template.envFields ?? []) {@@ -172,8 +183,17 @@ export function InstallServerModal({const { backend } = useActiveBackend();const isCloudBackend = backend.kind === "cloud";+ // The first installable option is the entry's preferred one; entries with+ // several let the user pick another before filling in its fields.+ const options = React.useMemo(+ () => getInstallableMcpConnectionOptions(entry),+ [entry],+ );+ const [selectedOptionIndex, setSelectedOptionIndex] = React.useState(0);+ const option = options[selectedOptionIndex];+const [state, setState] = React.useState<FieldState>(() =>- makeInitialState(entry),+ makeInitialState(option),);// Always holds the latest state so async callbacks (onSuccess) never read// stale closure values, even under React concurrent-mode scheduling.@@ -183,7 +203,6 @@ export function InstallServerModal({const [globalError, setGlobalError] = React.useState<string | null>(null);const [isFinalizingInstall, setIsFinalizingInstall] = React.useState(false);const [isAuthorizingOAuth, setIsAuthorizingOAuth] = React.useState(false);- const option = getInstallableMcpConnectionOption(entry);const template = option?.transport;// stdio servers on cloud backends get a synthetic test success (they only// run inside the sandbox); never seed card health from it.@@ -223,6 +242,12 @@ export function InstallServerModal({setGlobalError(null);};+ const selectOption = (index: number) => {+ setSelectedOptionIndex(index);+ setState(makeInitialState(options[index]));+ setGlobalError(null);+ };+const toggleSecret = (key: string, value: boolean) => {setState((prev) => ({...prev,@@ -816,6 +841,28 @@ export function InstallServerModal({</a>)}+ {options.length > 1 && (+ <div+ role="tablist"+ aria-label={t(I18nKey.MCP$CONNECTION_METHOD)}+ data-testid="mcp-install-options"+ className="flex flex-wrap border-b border-border"+ >+ {options.map((candidate, index) => (+ <TabButton+ key={candidate.id}+ isActive={index === selectedOptionIndex}+ onClick={() => selectOption(index)}+ disabled={isPending}+ >+ <span data-testid={`mcp-install-option-${candidate.id}`}>+ {t(getOptionLabelKey(candidate))}+ </span>+ </TabButton>+ ))}+ </div>+ )}+<div className="flex flex-col gap-3">{renderFields()}</div>{/* @spec MCP-006 — Library installs never dead-end */}diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex c6c6d1e615..2978498754 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -18521,6 +18521,96 @@"ca": "{{name}} MCP","id": "{{name}} MCP"},+ "MCP$CONNECTION_METHOD": {+ "en": "Connection method",+ "ja": "接続方法",+ "zh-CN": "连接方式",+ "zh-TW": "連線方式",+ "ko-KR": "연결 방법",+ "no": "Tilkoblingsmetode",+ "it": "Metodo di connessione",+ "pt": "Método de conexão",+ "es": "Método de conexión",+ "ar": "طريقة الاتصال",+ "fr": "Méthode de connexion",+ "tr": "Bağlantı yöntemi",+ "de": "Verbindungsmethode",+ "uk": "Спосіб підключення",+ "ca": "Mètode de connexió",+ "id": "Metode koneksi"+ },+ "MCP$OPTION_OAUTH": {+ "en": "OAuth sign-in",+ "ja": "OAuth サインイン",+ "zh-CN": "OAuth 登录",+ "zh-TW": "OAuth 登入",+ "ko-KR": "OAuth 로그인",+ "no": "OAuth-pålogging",+ "it": "Accesso OAuth",+ "pt": "Login OAuth",+ "es": "Inicio de sesión OAuth",+ "ar": "تسجيل الدخول عبر OAuth",+ "fr": "Connexion OAuth",+ "tr": "OAuth ile oturum açma",+ "de": "OAuth-Anmeldung",+ "uk": "Вхід через OAuth",+ "ca": "Inici de sessió OAuth",+ "id": "Masuk dengan OAuth"+ },+ "MCP$OPTION_API_KEY": {+ "en": "API key or token",+ "ja": "API キーまたはトークン",+ "zh-CN": "API 密钥或令牌",+ "zh-TW": "API 金鑰或權杖",+ "ko-KR": "API 키 또는 토큰",+ "no": "API-nøkkel eller token",+ "it": "Chiave API o token",+ "pt": "Chave de API ou token",+ "es": "Clave de API o token",+ "ar": "مفتاح API أو رمز مميز",+ "fr": "Clé API ou jeton",+ "tr": "API anahtarı veya belirteç",+ "de": "API-Schlüssel oder Token",+ "uk": "Ключ API або токен",+ "ca": "Clau d'API o testimoni",+ "id": "Kunci API atau token"+ },+ "MCP$OPTION_REMOTE": {+ "en": "Remote server",+ "ja": "リモートサーバー",+ "zh-CN": "远程服务器",+ "zh-TW": "遠端伺服器",+ "ko-KR": "원격 서버",+ "no": "Ekstern server",+ "it": "Server remoto",+ "pt": "Servidor remoto",+ "es": "Servidor remoto",+ "ar": "خادم بعيد",+ "fr": "Serveur distant",+ "tr": "Uzak sunucu",+ "de": "Remote-Server",+ "uk": "Віддалений сервер",+ "ca": "Servidor remot",+ "id": "Server jarak jauh"+ },+ "MCP$OPTION_LOCAL": {+ "en": "Local server",+ "ja": "ローカルサーバー",+ "zh-CN": "本地服务器",+ "zh-TW": "本機伺服器",+ "ko-KR": "로컬 서버",+ "no": "Lokal server",+ "it": "Server locale",+ "pt": "Servidor local",+ "es": "Servidor local",+ "ar": "خادم محلي",+ "fr": "Serveur local",+ "tr": "Yerel sunucu",+ "de": "Lokaler Server",+ "uk": "Локальний сервер",+ "ca": "Servidor local",+ "id": "Server lokal"+ },"MCP$NATIVE_DESCRIPTION": {"en": "The recommended way to connect. Provides a more seamless, native {{name}} experience with full access to your repositories, issues, and pull requests.","ja": "推奨される接続方法です。リポジトリ、Issue、プルリクエストにフルアクセスできる、よりシームレスなネイティブ {{name}} 体験を提供します。",diff --git a/src/utils/mcp-marketplace-utils.ts b/src/utils/mcp-marketplace-utils.tsindex 01f7feaa5f..d6073823d8 100644--- a/src/utils/mcp-marketplace-utils.ts+++ b/src/utils/mcp-marketplace-utils.ts@@ -79,15 +79,25 @@ function getDiscoveryOAuthOption(return { ...option, auth: { strategy: "oauth2" } };}-export function getInstallableMcpConnectionOption(+/**+ * The options the install dialog can offer, in catalog order. The first one+ * is the entry's preferred option and the dialog's default.+ */+export function getInstallableMcpConnectionOptions(entry: MarketplaceEntry,-): McpMarketplaceConnectionOption | undefined {+): McpMarketplaceConnectionOption[] {const options = getMcpConnectionOptions(entry);+ const installable = options.filter(isLocallyInstallableMcpOption);+ if (installable.length > 0) return installable;// @spec MCP-006 — Library installs never dead-end- return (- options.find(isLocallyInstallableMcpOption) ??- options.map(getDiscoveryOAuthOption).find(Boolean)- );+ const fallback = options.map(getDiscoveryOAuthOption).find(Boolean);+ return fallback ? [fallback] : [];+}++export function getInstallableMcpConnectionOption(+ entry: MarketplaceEntry,+): McpMarketplaceConnectionOption | undefined {+ return getInstallableMcpConnectionOptions(entry)[0];}export function getDefaultMcpTransport(