|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, computed, onMounted } from 'vue' |
| 3 | +import { McpCatalogService } from '@/services/mcpCatalogService' |
| 4 | +import { McpInstallationService } from '@/services/mcpInstallationService' |
| 5 | +import { Spinner } from '@/components/ui/spinner' |
| 6 | +import { |
| 7 | + ConfigurationArgs, |
| 8 | + ConfigurationEnv, |
| 9 | + ConfigurationHeaders, |
| 10 | + ConfigurationQueryParams |
| 11 | +} from './config' |
| 12 | +import type { McpInstallation, UserConfiguration } from '@/types/mcp-installations' |
| 13 | +
|
| 14 | +interface Props { |
| 15 | + installation: McpInstallation |
| 16 | + teamId: string |
| 17 | + canEdit?: boolean |
| 18 | + userRole?: 'team_admin' | 'team_user' | null |
| 19 | +} |
| 20 | +
|
| 21 | +const props = withDefaults(defineProps<Props>(), { |
| 22 | + canEdit: true, |
| 23 | + userRole: null |
| 24 | +}) |
| 25 | +
|
| 26 | +const emit = defineEmits<{ |
| 27 | + 'installation-updated': [installation: McpInstallation] |
| 28 | + 'configuration-updated': [config: UserConfiguration] |
| 29 | +}>() |
| 30 | +
|
| 31 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 32 | +const serverData = ref<any>(null) |
| 33 | +const isLoadingServer = ref(true) |
| 34 | +const userConfigurations = ref<UserConfiguration[]>([]) |
| 35 | +const currentUserConfig = ref<UserConfiguration | null>(null) |
| 36 | +const isLoadingUserConfig = ref(true) |
| 37 | +
|
| 38 | +const isTeamAdmin = computed(() => props.userRole === 'team_admin') |
| 39 | +
|
| 40 | +const isStdio = computed(() => { |
| 41 | + const transport = props.installation.server?.transport_type || serverData.value?.transport_type |
| 42 | + return transport === 'stdio' |
| 43 | +}) |
| 44 | +
|
| 45 | +const isRemote = computed(() => { |
| 46 | + const transport = props.installation.server?.transport_type || serverData.value?.transport_type |
| 47 | + return transport === 'http' || transport === 'sse' |
| 48 | +}) |
| 49 | +
|
| 50 | +onMounted(async () => { |
| 51 | + try { |
| 52 | + isLoadingServer.value = true |
| 53 | + isLoadingUserConfig.value = true |
| 54 | +
|
| 55 | + if (props.installation.server_id) { |
| 56 | + serverData.value = await McpCatalogService.getServerById(props.installation.server_id) |
| 57 | + } |
| 58 | +
|
| 59 | + await loadUserConfigurations() |
| 60 | + } catch (error) { |
| 61 | + console.error('Error loading data:', error) |
| 62 | + } finally { |
| 63 | + isLoadingServer.value = false |
| 64 | + isLoadingUserConfig.value = false |
| 65 | + } |
| 66 | +}) |
| 67 | +
|
| 68 | +const loadUserConfigurations = async () => { |
| 69 | + try { |
| 70 | + const configs: UserConfiguration[] = await McpInstallationService.getUserConfigurations( |
| 71 | + props.teamId, |
| 72 | + props.installation.id |
| 73 | + ) |
| 74 | + userConfigurations.value = configs |
| 75 | +
|
| 76 | + if (configs.length > 0 && configs[0]) { |
| 77 | + currentUserConfig.value = configs[0] |
| 78 | + } else { |
| 79 | + currentUserConfig.value = null |
| 80 | + } |
| 81 | + } catch (error) { |
| 82 | + console.error('Error loading user configurations:', error) |
| 83 | + userConfigurations.value = [] |
| 84 | + currentUserConfig.value = null |
| 85 | + } |
| 86 | +} |
| 87 | +
|
| 88 | +const handleInstallationUpdated = (updatedInstallation: McpInstallation) => { |
| 89 | + emit('installation-updated', updatedInstallation) |
| 90 | +} |
| 91 | +
|
| 92 | +const handleConfigurationUpdated = async (config: UserConfiguration) => { |
| 93 | + await loadUserConfigurations() |
| 94 | + emit('configuration-updated', config) |
| 95 | +} |
| 96 | +</script> |
| 97 | + |
| 98 | +<template> |
| 99 | + <div v-if="isLoadingServer || isLoadingUserConfig" class="flex items-center justify-center py-12"> |
| 100 | + <Spinner class="h-8 w-8" /> |
| 101 | + </div> |
| 102 | + |
| 103 | + <div v-else class="space-y-0"> |
| 104 | + <!-- STDIO TRANSPORT: Arguments + Environment Variables --> |
| 105 | + <ConfigurationArgs |
| 106 | + v-if="isStdio" |
| 107 | + :installation="installation" |
| 108 | + :server-data="serverData" |
| 109 | + :current-user-config="currentUserConfig" |
| 110 | + :team-id="teamId" |
| 111 | + :can-edit="canEdit" |
| 112 | + :is-team-admin="isTeamAdmin" |
| 113 | + @installation-updated="handleInstallationUpdated" |
| 114 | + @configuration-updated="handleConfigurationUpdated" |
| 115 | + /> |
| 116 | + |
| 117 | + <ConfigurationEnv |
| 118 | + v-if="isStdio" |
| 119 | + :installation="installation" |
| 120 | + :server-data="serverData" |
| 121 | + :current-user-config="currentUserConfig" |
| 122 | + :team-id="teamId" |
| 123 | + :can-edit="canEdit" |
| 124 | + :is-team-admin="isTeamAdmin" |
| 125 | + @installation-updated="handleInstallationUpdated" |
| 126 | + @configuration-updated="handleConfigurationUpdated" |
| 127 | + /> |
| 128 | + |
| 129 | + <!-- HTTP/SSE TRANSPORT: Headers + URL Query Parameters --> |
| 130 | + <ConfigurationHeaders |
| 131 | + v-if="isRemote" |
| 132 | + :installation="installation" |
| 133 | + :server-data="serverData" |
| 134 | + :current-user-config="currentUserConfig" |
| 135 | + :team-id="teamId" |
| 136 | + :can-edit="canEdit" |
| 137 | + :is-team-admin="isTeamAdmin" |
| 138 | + @installation-updated="handleInstallationUpdated" |
| 139 | + @configuration-updated="handleConfigurationUpdated" |
| 140 | + /> |
| 141 | + |
| 142 | + <ConfigurationQueryParams |
| 143 | + v-if="isRemote" |
| 144 | + :installation="installation" |
| 145 | + :server-data="serverData" |
| 146 | + :current-user-config="currentUserConfig" |
| 147 | + :team-id="teamId" |
| 148 | + :can-edit="canEdit" |
| 149 | + :is-team-admin="isTeamAdmin" |
| 150 | + @installation-updated="handleInstallationUpdated" |
| 151 | + @configuration-updated="handleConfigurationUpdated" |
| 152 | + /> |
| 153 | + </div> |
| 154 | +</template> |
0 commit comments