useMcpUrl.ts34 lines · main
| 1 | import { useParams } from 'common' |
| 2 | import { useMemo } from 'react' |
| 3 | import { |
| 4 | FEATURE_GROUPS_NON_PLATFORM, |
| 5 | FEATURE_GROUPS_PLATFORM, |
| 6 | getMcpUrl, |
| 7 | } from 'ui-patterns/McpUrlBuilder' |
| 8 | |
| 9 | import { StepContentProps } from './Connect.types' |
| 10 | import { IS_PLATFORM } from '@/lib/constants' |
| 11 | |
| 12 | export function useMcpUrl( |
| 13 | state: StepContentProps['state'], |
| 14 | projectKeys: StepContentProps['projectKeys'] |
| 15 | ): string { |
| 16 | const { ref: projectRef } = useParams() |
| 17 | const readonly = Boolean(state.mcpReadonly) |
| 18 | |
| 19 | return useMemo(() => { |
| 20 | const selectedFeatures = Array.isArray(state.mcpFeatures) ? state.mcpFeatures : [] |
| 21 | const supportedFeatures = IS_PLATFORM ? FEATURE_GROUPS_PLATFORM : FEATURE_GROUPS_NON_PLATFORM |
| 22 | const validFeatures = selectedFeatures.filter((f) => |
| 23 | supportedFeatures.some((group) => group.id === f) |
| 24 | ) |
| 25 | |
| 26 | return getMcpUrl({ |
| 27 | projectRef, |
| 28 | isPlatform: IS_PLATFORM, |
| 29 | apiUrl: projectKeys.apiUrl ?? undefined, |
| 30 | readonly, |
| 31 | features: validFeatures, |
| 32 | }).mcpUrl |
| 33 | }, [projectKeys.apiUrl, projectRef, readonly, state.mcpFeatures]) |
| 34 | } |