Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: local/self-hosted support in MCP URL builder (#38981)

Matt Rossman84601211e6bb
diff --git a/apps/docs/content/guides/getting-started/mcp.mdx b/apps/docs/content/guides/getting-started/mcp.mdx
index 908680fe3d8..e3dbd33fba9 100644
--- a/apps/docs/content/guides/getting-started/mcp.mdx
+++ b/apps/docs/content/guides/getting-started/mcp.mdx
@@ -16,7 +16,7 @@ Before running the MCP server, we recommend you read our [security best practice
### Step 2: Configure your AI tool
-Choose your project and MCP client and follow the installation instructions:
+Choose your Supabase platform, project, and MCP client and follow the installation instructions:
<McpConfigPanel />
diff --git a/apps/docs/features/ui/McpConfigPanel.tsx b/apps/docs/features/ui/McpConfigPanel.tsx
index f13716a3ffd..96411cd9299 100644
--- a/apps/docs/features/ui/McpConfigPanel.tsx
+++ b/apps/docs/features/ui/McpConfigPanel.tsx
@@ -21,6 +21,13 @@ import {
import { McpConfigPanel as McpConfigPanelBase } from 'ui-patterns/McpUrlBuilder'
import { useProjectsQuery } from '~/lib/fetch/projects'
+type PlatformType = (typeof PLATFORMS)[number]['value']
+
+const PLATFORMS = [
+ { value: 'hosted', label: 'Hosted' },
+ { value: 'local', label: 'CLI' },
+] as const satisfies Array<{ value: string; label: string }>
+
function ProjectSelector({
className,
selectedProject,
@@ -108,26 +115,105 @@ function ProjectSelector({
)
}
+function PlatformSelector({
+ className,
+ selectedPlatform,
+ onPlatformSelect,
+}: {
+ className?: string
+ selectedPlatform: PlatformType
+ onPlatformSelect?: (platform: PlatformType) => void
+}) {
+ const [open, setOpen] = useState(false)
+
+ return (
+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>
+ <div className={cn('flex', className)}>
+ <span className="flex items-center text-foreground-lighter px-3 rounded-lg rounded-r-none text-xs border border-button border-r-0">
+ Platform
+ </span>
+
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ size="small"
+ type="default"
+ className="gap-0 rounded-l-none"
+ iconRight={
+ <ChevronDown
+ strokeWidth={1.5}
+ className={cn('transition-transform duration-200', open && 'rotate-180')}
+ />
+ }
+ >
+ <div className="flex items-center gap-2">
+ {PLATFORMS.find((p) => p.value === selectedPlatform)?.label}
+ </div>
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ </div>
+ <PopoverContent_Shadcn_ className="mt-0 p-0 max-w-48" side="bottom" align="start">
+ <Command_Shadcn_>
+ <CommandList_Shadcn_>
+ <CommandGroup_Shadcn_>
+ {PLATFORMS.map((platform) => (
+ <CommandItem_Shadcn_
+ key={platform.value}
+ value={platform.value}
+ onSelect={() => {
+ onPlatformSelect?.(platform.value)
+ setOpen(false)
+ }}
+ className="flex gap-2 items-center"
+ >
+ {platform.label}
+ <Check
+ aria-label={platform.value === selectedPlatform ? 'selected' : undefined}
+ size={15}
+ className={cn(
+ 'ml-auto',
+ platform.value === selectedPlatform ? 'opacity-100' : 'opacity-0'
+ )}
+ />
+ </CommandItem_Shadcn_>
+ ))}
+ </CommandGroup_Shadcn_>
+ </CommandList_Shadcn_>
+ </Command_Shadcn_>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+}
+
export function McpConfigPanel() {
const [selectedProject, setSelectedProject] = useState<{ ref: string; name: string } | null>(null)
+ const [selectedPlatform, setSelectedPlatform] = useState<'hosted' | 'local'>('hosted')
const { theme } = useTheme()
+ const isPlatform = selectedPlatform === 'hosted'
+ const project = isPlatform ? selectedProject : null
+
return (
<div className="not-prose">
- <ProjectSelector
- className="mb-3"
- selectedProject={selectedProject}
- onProjectSelect={setSelectedProject}
- />
+ <div className="flex gap-3 mb-3">
+ <PlatformSelector
+ selectedPlatform={selectedPlatform}
+ onPlatformSelect={setSelectedPlatform}
+ />
+ {isPlatform && (
+ <ProjectSelector selectedProject={project} onProjectSelect={setSelectedProject} />
+ )}
+ </div>
<p className="text-xs text-foreground-lighter">
- Scope the MCP server to a project. If no project is selected, all projects will be
- accessible.
+ {isPlatform
+ ? 'Scope the MCP server to a project. If no project is selected, all projects will be accessible.'
+ : 'Project selection is only available for the hosted platform.'}
</p>
<McpConfigPanelBase
basePath="/docs"
className="mt-6"
- projectRef={selectedProject?.ref}
+ projectRef={project?.ref}
theme={theme as 'light' | 'dark'}
+ isPlatform={isPlatform}
/>
</div>
)
diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsx
index cc9bad797c1..5f207ea614c 100644
--- a/apps/studio/components/interfaces/Connect/Connect.tsx
+++ b/apps/studio/components/interfaces/Connect/Connect.tsx
@@ -5,6 +5,7 @@ import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'
import { useEffect, useMemo, useState } from 'react'
import { DatabaseConnectionString } from 'components/interfaces/Connect/DatabaseConnectionString'
+import { McpTabContent } from 'components/interfaces/Connect/McpTabContent'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import Panel from 'components/ui/Panel'
import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
@@ -34,7 +35,6 @@ import { CONNECTION_TYPES, ConnectionType, FRAMEWORKS, MOBILES, ORMS } from './C
import { getContentFilePath } from './Connect.utils'
import { ConnectDropdown } from './ConnectDropdown'
import { ConnectTabContent } from './ConnectTabContent'
-import { McpTabContent } from 'components/interfaces/Connect/McpTabContent'
export const Connect = () => {
const { ref: projectRef } = useParams()
@@ -365,7 +365,7 @@ export const Connect = () => {
value="mcp"
className={cn(DIALOG_PADDING_X, DIALOG_PADDING_Y, '!mt-0')}
>
- <McpTabContent />
+ <McpTabContent projectKeys={projectKeys} />
</TabsContent_Shadcn_>
)
}
diff --git a/apps/studio/components/interfaces/Connect/McpTabContent.tsx b/apps/studio/components/interfaces/Connect/McpTabContent.tsx
index 4178d58d271..bbb9beeb640 100644
--- a/apps/studio/components/interfaces/Connect/McpTabContent.tsx
+++ b/apps/studio/components/interfaces/Connect/McpTabContent.tsx
@@ -1,17 +1,18 @@
-import { useParams } from 'common'
+import { IS_PLATFORM, useParams } from 'common'
import Panel from 'components/ui/Panel'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { BASE_PATH } from 'lib/constants'
import { useTheme } from 'next-themes'
import { McpConfigPanel } from 'ui-patterns/McpUrlBuilder'
+import type { projectKeys } from './Connect.types'
-export const McpTabContent = () => {
+export const McpTabContent = ({ projectKeys }: { projectKeys: projectKeys }) => {
const { ref: projectRef } = useParams()
return (
<Panel className="bg-inherit border-none shadow-none">
{projectRef ? (
- <McpTabContentInnerLoaded projectRef={projectRef} />
+ <McpTabContentInnerLoaded projectRef={projectRef} projectKeys={projectKeys} />
) : (
<McpTabContentInnerLoading />
)}
@@ -28,7 +29,13 @@ const McpTabContentInnerLoading = () => {
)
}
-const McpTabContentInnerLoaded = ({ projectRef }: { projectRef: string }) => {
+const McpTabContentInnerLoaded = ({
+ projectRef,
+ projectKeys,
+}: {
+ projectRef: string
+ projectKeys: projectKeys
+}) => {
const { resolvedTheme } = useTheme()
return (
@@ -36,6 +43,8 @@ const McpTabContentInnerLoaded = ({ projectRef }: { projectRef: string }) => {
basePath={BASE_PATH}
projectRef={projectRef}
theme={resolvedTheme as 'light' | 'dark'}
+ isPlatform={IS_PLATFORM}
+ apiUrl={projectKeys.apiUrl ?? undefined}
/>
)
}
diff --git a/packages/ui-patterns/src/McpUrlBuilder/McpConfigPanel.tsx b/packages/ui-patterns/src/McpUrlBuilder/McpConfigPanel.tsx
index 680b64d34c1..709130225f3 100644
--- a/packages/ui-patterns/src/McpUrlBuilder/McpConfigPanel.tsx
+++ b/packages/ui-patterns/src/McpUrlBuilder/McpConfigPanel.tsx
@@ -1,14 +1,14 @@
'use client'
-import React, { useState } from 'react'
+import React, { useMemo, useState } from 'react'
import { cn, Separator } from 'ui'
import { ClientSelectDropdown } from './components/ClientSelectDropdown'
import { McpConfigurationDisplay } from './components/McpConfigurationDisplay'
import { McpConfigurationOptions } from './components/McpConfigurationOptions'
-import { FEATURE_GROUPS, MCP_CLIENTS } from './constants'
-import { getMcpUrl } from './utils/getMcpUrl'
+import { FEATURE_GROUPS_PLATFORM, FEATURE_GROUPS_NON_PLATFORM, MCP_CLIENTS } from './constants'
import type { McpClient } from './types'
+import { getMcpUrl } from './utils/getMcpUrl'
export interface McpConfigPanelProps {
basePath: string
@@ -18,26 +18,37 @@ export interface McpConfigPanelProps {
onClientSelect?: (client: McpClient) => void
theme?: 'light' | 'dark'
className?: string
+ isPlatform: boolean // For docs this is controlled by state, for studio by environment variable
+ apiUrl?: string
}
export function McpConfigPanel({
basePath,
- baseUrl,
projectRef,
initialSelectedClient,
onClientSelect,
className,
theme = 'dark',
+ isPlatform,
+ apiUrl,
}: McpConfigPanelProps) {
const [readonly, setReadonly] = useState(false)
const [selectedFeatures, setSelectedFeatures] = useState<string[]>([])
const [selectedClient, setSelectedClient] = useState(initialSelectedClient ?? MCP_CLIENTS[0])
+ const supportedFeatures = isPlatform ? FEATURE_GROUPS_PLATFORM : FEATURE_GROUPS_NON_PLATFORM
+ const selectedFeaturesSupported = useMemo(() => {
+ return selectedFeatures.filter((feature) =>
+ supportedFeatures.some((group) => group.id === feature)
+ )
+ }, [selectedFeatures, supportedFeatures])
+
const { clientConfig } = getMcpUrl({
- baseUrl,
projectRef,
+ isPlatform,
+ apiUrl,
readonly,
- features: selectedFeatures,
+ features: selectedFeaturesSupported,
selectedClient,
})
@@ -60,11 +71,12 @@ export function McpConfigPanel({
<Separator />
<McpConfigurationOptions
className={innerPanelSpacing}
+ isPlatform={isPlatform}
readonly={readonly}
onReadonlyChange={setReadonly}
- selectedFeatures={selectedFeatures}
+ selectedFeatures={selectedFeaturesSupported}
onFeaturesChange={setSelectedFeatures}
- featureGroups={FEATURE_GROUPS}
+ featureGroups={isPlatform ? FEATURE_GROUPS_PLATFORM : FEATURE_GROUPS_NON_PLATFORM}
/>
</div>
<div className="flex flex-col gap-y-3">
diff --git a/packages/ui-patterns/src/McpUrlBuilder/components/McpConfigurationOptions.tsx b/packages/ui-patterns/src/McpUrlBuilder/components/McpConfigurationOptions.tsx
index 93517aafc89..7d71e8a8f91 100644
--- a/packages/ui-patterns/src/McpUrlBuilder/components/McpConfigurationOptions.tsx
+++ b/packages/ui-patterns/src/McpUrlBuilder/components/McpConfigurationOptions.tsx
@@ -13,6 +13,7 @@ import {
import type { McpFeatureGroup } from '../types'
interface McpConfigurationOptionsProps {
+ isPlatform: boolean
readonly: boolean
onReadonlyChange: (readonly: boolean) => void
selectedFeatures: string[]
@@ -22,6 +23,7 @@ interface McpConfigurationOptionsProps {
}
export function McpConfigurationOptions({
+ isPlatform,
readonly,
onReadonlyChange,
selectedFeatures,
@@ -32,17 +34,19 @@ export function McpConfigurationOptions({
return (
<div className={cn('flex flex-col gap-4 lg:flex-row lg:gap-12 lg:items-baseline', className)}>
{/* Readonly Mode */}
- <div className="space-y-3 lg:flex-shrink-0">
- <div className="flex items-center gap-2">
- <Label htmlFor="readonly" className="text-sm">
- Read-only
- </Label>
- <InfoTooltip>Only allow read operations on your database</InfoTooltip>
- </div>
- <div className="flex items-center space-x-2">
- <Switch id="readonly" checked={readonly} onCheckedChange={onReadonlyChange} />
+ {isPlatform && (
+ <div className="space-y-3 lg:flex-shrink-0">
+ <div className="flex items-center gap-2">
+ <Label htmlFor="readonly" className="text-sm">
+ Read-only
+ </Label>
+ <InfoTooltip>Only allow read operations on your database</InfoTooltip>
+ </div>
+ <div className="flex items-center space-x-2">
+ <Switch id="readonly" checked={readonly} onCheckedChange={onReadonlyChange} />
+ </div>
</div>
- </div>
+ )}
{/* Feature Groups */}
<div className="space-y-3 lg:flex-1">
diff --git a/packages/ui-patterns/src/McpUrlBuilder/constants.tsx b/packages/ui-patterns/src/McpUrlBuilder/constants.tsx
index bcd1730f27a..67f6e7c8875 100644
--- a/packages/ui-patterns/src/McpUrlBuilder/constants.tsx
+++ b/packages/ui-patterns/src/McpUrlBuilder/constants.tsx
@@ -8,7 +8,7 @@ import type {
WindsurfMcpConfig,
} from './types'
-export const FEATURE_GROUPS: McpFeatureGroup[] = [
+export const FEATURE_GROUPS_PLATFORM: McpFeatureGroup[] = [
{
id: 'docs',
name: 'Documentation',
@@ -51,6 +51,10 @@ export const FEATURE_GROUPS: McpFeatureGroup[] = [
},
]
+export const FEATURE_GROUPS_NON_PLATFORM = FEATURE_GROUPS_PLATFORM.filter((group) =>
+ ['docs', 'database', 'development'].includes(group.id)
+)
+
export const MCP_CLIENTS: McpClient[] = [
{
key: 'cursor',
@@ -172,4 +176,5 @@ export const MCP_CLIENTS: McpClient[] = [
},
]
-export const MCP_URL = process.env.NEXT_PUBLIC_MCP_URL ?? 'http://localhost:8080/mcp'
+export const DEFAULT_MCP_URL_PLATFORM = 'http://localhost:8080/mcp'
+export const DEFAULT_MCP_URL_NON_PLATFORM = 'http://localhost:54321/mcp'
diff --git a/packages/ui-patterns/src/McpUrlBuilder/index.ts b/packages/ui-patterns/src/McpUrlBuilder/index.ts
index a48c727c2df..a15b032d884 100644
--- a/packages/ui-patterns/src/McpUrlBuilder/index.ts
+++ b/packages/ui-patterns/src/McpUrlBuilder/index.ts
@@ -2,7 +2,13 @@ export { ClientSelectDropdown } from './components/ClientSelectDropdown'
export { ConnectionIcon } from './components/ConnectionIcon'
export { McpConfigurationDisplay } from './components/McpConfigurationDisplay'
export { McpConfigurationOptions } from './components/McpConfigurationOptions'
-export { MCP_URL, FEATURE_GROUPS, MCP_CLIENTS } from './constants'
+export {
+ DEFAULT_MCP_URL_PLATFORM,
+ DEFAULT_MCP_URL_NON_PLATFORM,
+ FEATURE_GROUPS_PLATFORM,
+ FEATURE_GROUPS_NON_PLATFORM,
+ MCP_CLIENTS,
+} from './constants'
export { getMcpUrl } from './utils/getMcpUrl'
export { McpConfigPanel, type McpConfigPanelProps } from './McpConfigPanel'
export type {
diff --git a/packages/ui-patterns/src/McpUrlBuilder/utils/getMcpUrl.ts b/packages/ui-patterns/src/McpUrlBuilder/utils/getMcpUrl.ts
index 4f22c128e5d..94dc41f8cb7 100644
--- a/packages/ui-patterns/src/McpUrlBuilder/utils/getMcpUrl.ts
+++ b/packages/ui-patterns/src/McpUrlBuilder/utils/getMcpUrl.ts
@@ -1,12 +1,13 @@
-import { MCP_URL } from '../constants'
+import { DEFAULT_MCP_URL_NON_PLATFORM, DEFAULT_MCP_URL_PLATFORM } from '../constants'
import type { McpClient, McpClientConfig } from '../types'
interface GetMcpUrlOptions {
projectRef?: string
- baseUrl?: string
readonly?: boolean
features?: string[]
selectedClient?: McpClient
+ isPlatform: boolean
+ apiUrl?: string
}
interface GetMcpUrlReturn {
@@ -16,17 +17,18 @@ interface GetMcpUrlReturn {
export function getMcpUrl({
projectRef,
- baseUrl = MCP_URL,
+ isPlatform,
+ apiUrl,
readonly = false,
features = [],
selectedClient,
}: GetMcpUrlOptions): GetMcpUrlReturn {
// Generate the MCP URL based on current configuration
- const url = new URL(baseUrl)
- if (projectRef) {
+ const url = new URL(getMcpUrlBase({ isPlatform, apiUrl }))
+ if (projectRef && isPlatform) {
url.searchParams.set('project_ref', projectRef)
}
- if (readonly) {
+ if (readonly && isPlatform) {
url.searchParams.set('read_only', 'true')
}
if (features.length > 0) {
@@ -51,3 +53,16 @@ export function getMcpUrl({
clientConfig,
}
}
+
+/**
+ * Assembles base `/mcp` endpoint URL for the given environment
+ */
+function getMcpUrlBase({ isPlatform, apiUrl }: { isPlatform: boolean; apiUrl?: string }) {
+ // Hosted platform uses environment variable with fallback
+ if (isPlatform) {
+ return process.env.NEXT_PUBLIC_MCP_URL ?? DEFAULT_MCP_URL_PLATFORM
+ }
+
+ // Self-hosted uses API URL with fallback
+ return apiUrl ? `${apiUrl}/mcp` : DEFAULT_MCP_URL_NON_PLATFORM
+}