Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Show the MCP URL in the admin panel (#72737)

Anderson6539732003ea
diff --git a/frontend/src/metabase/common/components/CopyButton/CopyButton.tsx b/frontend/src/metabase/common/components/CopyButton/CopyButton.tsx
index 4ec14b97c06..21db04b9dfe 100644
--- a/frontend/src/metabase/common/components/CopyButton/CopyButton.tsx
+++ b/frontend/src/metabase/common/components/CopyButton/CopyButton.tsx
@@ -46,14 +46,18 @@ export const CopyButton = ({
);
return (
- <div className={className} style={style} data-testid="copy-button">
+ <div
+ className={className}
+ data-testid="copy-button"
+ onClick={onCopyValue}
+ onKeyDown={copyOnEnter}
+ style={style}
+ >
<Tooltip
label={<Text fw={700} c="inherit">{t`Copied!`}</Text>}
opened={clipboard.copied}
>
- <span onClick={onCopyValue} onKeyDown={copyOnEnter}>
- {target}
- </span>
+ <span>{target}</span>
</Tooltip>
</div>
);
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.module.css b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.module.css
new file mode 100644
index 00000000000..6ea662dff5b
--- /dev/null
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.module.css
@@ -0,0 +1,4 @@
+.input {
+ font-family: monospace;
+ font-size: 0.75rem;
+}
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.tsx
new file mode 100644
index 00000000000..4d0a034d943
--- /dev/null
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.tsx
@@ -0,0 +1,35 @@
+import { t } from "ttag";
+
+import { SettingHeader } from "metabase/admin/settings/components/SettingHeader";
+import { CopyTextInput } from "metabase/common/components/CopyTextInput";
+import { Box } from "metabase/ui";
+
+import S from "./MCPServerUrlSection.module.css";
+import { useMCPServerURL } from "./utils";
+
+export function McpServerUrlSection() {
+ const mcpServerUrl = useMCPServerURL();
+
+ if (!mcpServerUrl) {
+ return null;
+ }
+
+ return (
+ <Box>
+ <SettingHeader
+ id="custom-mcp-origins"
+ title={t`MCP server URL`}
+ description={t`This is the MCP server URL you can use to connect.`}
+ />
+ <CopyTextInput
+ value={mcpServerUrl}
+ classNames={{
+ input: S.input,
+ }}
+ readOnly
+ mt="md"
+ c="text-primary"
+ />
+ </Box>
+ );
+}
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.unit.spec.tsx
new file mode 100644
index 00000000000..0d48b727fb9
--- /dev/null
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MCPServerUrlSection.unit.spec.tsx
@@ -0,0 +1,57 @@
+import userEvent from "@testing-library/user-event";
+
+import {
+ setupPropertiesEndpoints,
+ setupSettingsEndpoints,
+ setupUpdateSettingEndpoint,
+} from "__support__/server-mocks";
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen } from "__support__/ui";
+import { UndoListing } from "metabase/common/components/UndoListing";
+import { createMockState } from "metabase/redux/store/mocks";
+import { createMockSettings } from "metabase-types/api/mocks";
+
+import { McpServerUrlSection } from "./MCPServerUrlSection";
+
+const SITE_URL = "https://metabase.example.com";
+const MCP_URL = `${SITE_URL}/api/mcp`;
+
+function setup({ siteUrl = SITE_URL }: { siteUrl?: string | undefined } = {}) {
+ const settings = createMockSettings({ "site-url": siteUrl });
+
+ setupPropertiesEndpoints(settings);
+ setupSettingsEndpoints([]);
+ setupUpdateSettingEndpoint();
+
+ renderWithProviders(
+ <div>
+ <McpServerUrlSection />
+ <UndoListing />
+ </div>,
+ {
+ storeInitialState: createMockState({
+ settings: mockSettings(settings),
+ }),
+ },
+ );
+}
+
+describe("McpServerUrlSection", () => {
+ it("uses site-url to construct and display the MCP server URL", async () => {
+ setup();
+ expect(await screen.findByDisplayValue(MCP_URL)).toBeInTheDocument();
+ });
+
+ it("renders nothing when site-url is not set", () => {
+ setup({ siteUrl: undefined });
+ expect(screen.queryByDisplayValue(MCP_URL)).not.toBeInTheDocument();
+ });
+
+ it("can copy the MCP server URL to the clipboard", async () => {
+ setup();
+ await userEvent.click(
+ await screen.findByRole("img", { name: /copy icon/i }),
+ );
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(MCP_URL);
+ });
+});
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx
index 7758317af3c..c1222a43cd6 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/McpAppsSettings.tsx
@@ -8,6 +8,8 @@ import { ExternalLink } from "metabase/common/components/ExternalLink";
import { useDocsUrl } from "metabase/common/hooks";
import { Box, Flex, Stack, Switch, Text, TextInput } from "metabase/ui";
+import { McpServerUrlSection } from "./MCPServerUrlSection";
+
const getMcpClients = () =>
[
{
@@ -65,15 +67,14 @@ export const McpAppsSettings = ({ id }: { id?: string }) => {
)}`
}
>
- {isEnabled ? (
+ {isEnabled && (
<Stack gap="lg">
<CommonMcpClientsSection />
<CustomMcpOriginsSection />
</Stack>
- ) : (
- <></>
)}
+ <McpServerUrlSection />
</SettingsSection>
);
};
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/utils.ts b/frontend/src/metabase/metabot/components/MetabotAdmin/utils.ts
index 7eb2e1e91e7..0803c3d4cc5 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/utils.ts
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/utils.ts
@@ -2,6 +2,7 @@ import type { FetchBaseQueryError } from "@reduxjs/toolkit/query";
import type { FormikErrors } from "formik";
import { P, isMatching } from "ts-pattern";
+import { useAdminSetting } from "metabase/api/utils";
import { getLocation } from "metabase/selectors/routing";
import { useSelector } from "metabase/utils/redux";
import type { MetabotProvider } from "metabase-types/api";
@@ -160,3 +161,13 @@ export const handleFieldError = <Values>(
throw { data: error };
}
};
+
+export function useMCPServerURL() {
+ const { value: siteUrl } = useAdminSetting("site-url");
+
+ if (!siteUrl) {
+ return null;
+ }
+
+ return `${siteUrl}/api/mcp`;
+}