@@ -147,59 +147,75 @@ func (g *Gateway) ActivateProfile(ctx context.Context, ws workingset.WorkingSet)
147147 serverConfigMap := profileConfig .config [serverName ]
148148
149149 for _ , configItem := range serverConfig .Config {
150- // Config items should be schema objects with a "name" property
150+ // Config items are object schemas with a "properties" map.
151+ // The "name" field is just an identifier, not a key in serverConfigMap.
151152 schemaMap , ok := configItem .(map [string ]any )
152153 if ! ok {
153154 continue
154155 }
155156
156- // Get the name field - this identifies which config to validate
157- configName , ok := schemaMap ["name" ].(string )
158- if ! ok || configName == "" {
157+ properties , ok := schemaMap ["properties" ].(map [string ]any )
158+ if ! ok {
159159 continue
160160 }
161161
162- // Get the actual config value to validate
163- if serverConfigMap == nil {
164- validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (missing)" , configName ))
165- continue
162+ // Build a set of required property names
163+ requiredProps := make (map [string ]bool )
164+ if requiredList , ok := schemaMap ["required" ].([]any ); ok {
165+ for _ , r := range requiredList {
166+ if s , ok := r .(string ); ok {
167+ requiredProps [s ] = true
168+ }
169+ }
166170 }
167171
168- // Extract the specific config value for this schema, not the entire map
169- configValue , exists := serverConfigMap [ configName ]
170- if ! exists {
171- validation . missingConfig = append ( validation . missingConfig , fmt . Sprintf ( "%s (missing)" , configName ))
172- continue
173- }
172+ // Validate each property individually
173+ for propName , propSchema := range properties {
174+ propSchemaMap , ok := propSchema .( map [ string ] any )
175+ if ! ok {
176+ continue
177+ }
174178
175- // Convert the schema map to a jsonschema.Schema for validation
176- schemaBytes , err := json .Marshal (schemaMap )
177- if err != nil {
178- validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (invalid schema)" , configName ))
179- continue
180- }
179+ // Get the value from the user-provided config
180+ configValue , exists := serverConfigMap [propName ]
181+ if ! exists {
182+ // If the property has a default, the server will use it
183+ if _ , hasDefault := propSchemaMap ["default" ]; hasDefault {
184+ continue
185+ }
186+ // Only flag as missing if explicitly required
187+ if requiredProps [propName ] {
188+ validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (missing)" , propName ))
189+ }
190+ continue
191+ }
181192
182- var schema jsonschema.Schema
183- if err := json .Unmarshal (schemaBytes , & schema ); err != nil {
184- validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (invalid schema)" , configName ))
185- continue
186- }
193+ // Validate the value against the property schema
194+ schemaBytes , err := json .Marshal (propSchemaMap )
195+ if err != nil {
196+ validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (invalid schema)" , propName ))
197+ continue
198+ }
187199
188- // Resolve the schema
189- resolved , err := schema .Resolve (nil )
190- if err != nil {
191- validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (schema resolution failed)" , configName ))
192- continue
193- }
200+ var propSchemaObj jsonschema.Schema
201+ if err := json .Unmarshal (schemaBytes , & propSchemaObj ); err != nil {
202+ validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (invalid schema)" , propName ))
203+ continue
204+ }
205+
206+ resolved , err := propSchemaObj .Resolve (nil )
207+ if err != nil {
208+ validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (schema resolution failed)" , propName ))
209+ continue
210+ }
194211
195- // Validate the config value against the schema
196- if err := resolved . Validate ( configValue ); err != nil {
197- // Extract a helpful error message
198- errMsg := err . Error ()
199- if len ( errMsg ) > 100 {
200- errMsg = errMsg [: 97 ] + "..."
212+ if err := resolved . Validate ( configValue ); err != nil {
213+ errMsg := err . Error ()
214+ if len ( errMsg ) > 100 {
215+ errMsg = errMsg [: 97 ] + "..."
216+ }
217+ validation . missingConfig = append ( validation . missingConfig , fmt . Sprintf ( "%s (%s)" , propName , errMsg ))
201218 }
202- validation .missingConfig = append (validation .missingConfig , fmt .Sprintf ("%s (%s)" , configName , errMsg ))
203219 }
204220 }
205221 }
0 commit comments