The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add cursor deeplink button in admin UI for MCP setup (#72890)
Timofey Kachalov02d588d3fcdf
diff --git a/e2e/test/scenarios/metabot/mcp-apps-settings.cy.spec.ts b/e2e/test/scenarios/metabot/mcp-apps-settings.cy.spec.tsnew file mode 100644index 00000000000..1cccc612f6a--- /dev/null+++ b/e2e/test/scenarios/metabot/mcp-apps-settings.cy.spec.ts@@ -0,0 +1,55 @@+const { H } = cy;++describe("admin > MCP apps settings > Cursor install link", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("shows 'Install in Cursor' link only when the Cursor and VS Code switch is enabled", () => {+ cy.visit("/admin/metabot");++ H.main().within(() => {+ cy.findByText("Supported MCP clients").scrollIntoView();++ cy.log("link is hidden by default");+ cy.findByRole("link", { name: "Install in Cursor" }).should("not.exist");++ cy.log("enable Cursor and VS Code");+ cy.findByRole("switch", { name: /cursor and vs code/i }).click({+ force: true,+ });++ cy.log("link appears with a valid Cursor deeplink");+ cy.findByRole("link", { name: "Install in Cursor" })+ .should("be.visible")+ .invoke("attr", "href")+ .should((href) => {+ expect(href).to.be.a("string");+ expect(href).to.match(+ /^cursor:\/\/anysphere\.cursor-deeplink\/mcp\/install\?/,+ );++ const query = (href as string).split("?", 2)[1];+ const params = new URLSearchParams(query);++ expect(params.get("name")).to.eq("Metabase");+ const config = params.get("config");++ expect(config).to.be.a("string");++ const decoded = JSON.parse(atob(config as string));++ expect(decoded.url).to.eq(`${Cypress.config("baseUrl")}/api/mcp`);+ });++ cy.log("disable Cursor and VS Code");+ cy.findByRole("switch", { name: /cursor and vs code/i }).click({+ force: true,+ });++ cy.log("link is hidden again");+ cy.findByRole("link", { name: "Install in Cursor" }).should("not.exist");+ });+ });+});diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/CursorInstallLink.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/CursorInstallLink.tsxnew file mode 100644index 00000000000..28f26ccbcbd--- /dev/null+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/CursorInstallLink.tsx@@ -0,0 +1,39 @@+import { t } from "ttag";++import { Anchor } from "metabase/ui";++import { useMCPServerURL } from "./utils";++const CURSOR_DEEPLINK = {+ url: "cursor://anysphere.cursor-deeplink/mcp/install",+ // eslint-disable-next-line metabase/no-literal-metabase-strings -- Cursor MCP registration name, not user-facing+ mcpName: "Metabase",+} as const;++const buildCursorInstallUrl = (mcpUrl: string): string => {+ const params = new URLSearchParams({+ name: CURSOR_DEEPLINK.mcpName,+ config: window.btoa(JSON.stringify({ url: mcpUrl })),+ });++ return `${CURSOR_DEEPLINK.url}?${params.toString()}`;+};++export const CursorInstallLink = () => {+ const mcpUrl = useMCPServerURL();++ if (!mcpUrl) {+ return null;+ }++ return (+ <Anchor+ href={buildCursorInstallUrl(mcpUrl)}+ fz="sm"+ w="fit-content"+ onClick={(event) => event.stopPropagation()}+ >+ {t`Install in Cursor`}+ </Anchor>+ );+};diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsxindex c1222a43cd6..3f246da1777 100644--- a/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx@@ -8,9 +8,10 @@ import { ExternalLink } from "metabase/common/components/ExternalLink";import { useDocsUrl } from "metabase/common/hooks";import { Box, Flex, Stack, Switch, Text, TextInput } from "metabase/ui";+import { CursorInstallLink } from "./CursorInstallLink";import { McpServerUrlSection } from "./MCPServerUrlSection";-const getMcpClients = () =>+const getMcpClients = (enabledClients: string[]) =>[{key: "claude",@@ -18,7 +19,13 @@ const getMcpClients = () =>},{key: "cursor-vscode",- label: t`Cursor and VS Code`,+ label: (+ <Stack gap="xs">+ <span>{t`Cursor and VS Code`}</span>++ {enabledClients.includes("cursor-vscode") && <CursorInstallLink />}+ </Stack>+ ),},{key: "chatgpt",@@ -80,8 +87,6 @@ export const McpAppsSettings = ({ id }: { id?: string }) => {};function CommonMcpClientsSection() {- const mcpClients = getMcpClients();-const { value: savedValue, updateSetting } = useAdminSetting("mcp-apps-cors-enabled-clients",);@@ -90,6 +95,8 @@ function CommonMcpClientsSection() {savedValue ?? [],);+ const mcpClients = getMcpClients(enabledClients);+const handleToggle = useCallback((clientKey: string, checked: boolean) => {const updated = checked