Skip to content

Commit 37affd3

Browse files
author
Lasim
committed
refactor: enhance validation logic for required environment variables and improve server selection handling
1 parent 1cb9634 commit 37affd3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

services/frontend/src/components/mcp-server/EnvironmentVariableCard.vue

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ const optionalVariables = computed(() => {
6262
})
6363
6464
const allRequiredFilled = computed(() => {
65+
if (requiredVariables.value.length === 0) {
66+
return true // No required variables, so validation passes
67+
}
68+
6569
return requiredVariables.value.every((env: any) => {
6670
const value = modelValue.value[env.name]
6771
// Check if value exists, is not empty, and is not a placeholder
@@ -86,7 +90,7 @@ const missingRequiredFields = computed(() => {
8690
const isPlaceholderValue = (value: string, env: any) => {
8791
if (!value || value.trim().length === 0) return true
8892
89-
const trimmedValue = value.trim()
93+
const trimmedValue = value.trim().toLowerCase()
9094
9195
// Check against common placeholder patterns that users might manually enter
9296
const placeholderPatterns = [
@@ -95,11 +99,17 @@ const isPlaceholderValue = (value: string, env: any) => {
9599
`<${env.name.toLowerCase()}>`,
96100
'your-api-key-here',
97101
'your-token-here',
98-
'your-secret-here'
102+
'your-secret-here',
103+
'enter-your-key',
104+
'api-key-here',
105+
'token-here',
106+
'secret-here',
107+
// Also check against the actual placeholder if it exists
108+
...(env.placeholder ? [env.placeholder.toLowerCase().trim()] : [])
99109
]
100110
101111
return placeholderPatterns.some(pattern =>
102-
pattern && trimmedValue === pattern.trim()
112+
pattern && (trimmedValue === pattern.trim().toLowerCase() || trimmedValue.includes(pattern.trim().toLowerCase()))
103113
)
104114
}
105115
@@ -142,12 +152,12 @@ const updateValue = (envName: string, value: string) => {
142152
// Watch for validation state changes and emit to parent
143153
watch(validationState, (newState) => {
144154
emit('validation-change', newState.isValid, newState.missingFields)
145-
}, { immediate: true })
155+
}, { immediate: true, deep: true })
146156
147157
// Watch for model value changes to trigger validation
148158
watch(modelValue, () => {
149159
// Validation will be triggered by the validationState watcher
150-
}, { deep: true })
160+
}, { deep: true, immediate: true })
151161
152162
// Watch for environment variables changes to initialize form values
153163
watch(() => environmentVariables.value, (newVariables) => {

services/frontend/src/components/mcp-server/wizard/McpServerInstallWizard.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ const canProceedFromServer = computed(() => {
140140
})
141141
142142
const canProceedFromEnvironment = computed(() => {
143+
// If no server is selected, can't proceed
144+
if (!formData.value.server.server_id) {
145+
return false
146+
}
147+
143148
// Use the validation state from the EnvironmentVariablesStep component
144149
return environmentValidation.value.isValid
145150
})
@@ -270,6 +275,12 @@ const handleServerSelected = (serverData: any) => {
270275
// Reset touched state when server changes
271276
environmentStepTouched.value = false
272277
278+
// Reset validation state when server changes
279+
environmentValidation.value = {
280+
isValid: true, // Will be updated by the component
281+
missingFields: []
282+
}
283+
273284
// Pre-populate environment variables with default values
274285
if (serverData.environment_variables) {
275286
serverData.environment_variables.forEach((env: any) => {

0 commit comments

Comments
 (0)