@@ -158,6 +158,40 @@ func (r *RegistryEntry) SetDefaults() {
158158 }
159159}
160160
161+ // extendedFields contains fields for YAML parsing that are not part of the standard schema
162+ type extendedFields struct {
163+ Examples []Example `yaml:"examples,omitempty"`
164+ License string `yaml:"license,omitempty"`
165+ // OAuth configuration in simplified YAML format
166+ OAuth * struct {
167+ Issuer string `yaml:"issuer,omitempty"`
168+ AuthorizeURL string `yaml:"authorize_url,omitempty"`
169+ TokenURL string `yaml:"token_url,omitempty"`
170+ ClientID string `yaml:"client_id,omitempty"`
171+ Scopes []string `yaml:"scopes,omitempty"`
172+ UsePKCE * bool `yaml:"use_pkce,omitempty"`
173+ OAuthParams map [string ]string `yaml:"oauth_params,omitempty"`
174+ CallbackPort int `yaml:"callback_port,omitempty"`
175+ } `yaml:"oauth,omitempty"`
176+ // Headers for remote server authentication
177+ Headers []struct {
178+ Name string `yaml:"name"`
179+ Description string `yaml:"description"`
180+ Required bool `yaml:"required"`
181+ Default string `yaml:"default,omitempty"`
182+ Secret bool `yaml:"secret,omitempty"`
183+ Choices []string `yaml:"choices,omitempty"`
184+ } `yaml:"headers,omitempty"`
185+ // Environment variables for server configuration
186+ EnvVars []struct {
187+ Name string `yaml:"name"`
188+ Description string `yaml:"description"`
189+ Required bool `yaml:"required"`
190+ Default string `yaml:"default,omitempty"`
191+ Secret bool `yaml:"secret,omitempty"`
192+ } `yaml:"env_vars,omitempty"`
193+ }
194+
161195// UnmarshalYAML implements custom YAML unmarshaling to determine server type
162196func (r * RegistryEntry ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
163197 // First unmarshal into a map to check which fields are present
@@ -193,38 +227,6 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
193227 }
194228
195229 // Unmarshal extended fields (examples, license, oauth, headers, env_vars) separately
196- type extendedFields struct {
197- Examples []Example `yaml:"examples,omitempty"`
198- License string `yaml:"license,omitempty"`
199- // OAuth configuration in simplified YAML format
200- OAuth * struct {
201- Issuer string `yaml:"issuer,omitempty"`
202- AuthorizeURL string `yaml:"authorize_url,omitempty"`
203- TokenURL string `yaml:"token_url,omitempty"`
204- ClientID string `yaml:"client_id,omitempty"`
205- Scopes []string `yaml:"scopes,omitempty"`
206- UsePKCE * bool `yaml:"use_pkce,omitempty"`
207- OAuthParams map [string ]string `yaml:"oauth_params,omitempty"`
208- CallbackPort int `yaml:"callback_port,omitempty"`
209- } `yaml:"oauth,omitempty"`
210- // Headers for remote server authentication
211- Headers []struct {
212- Name string `yaml:"name"`
213- Description string `yaml:"description"`
214- Required bool `yaml:"required"`
215- Default string `yaml:"default,omitempty"`
216- Secret bool `yaml:"secret,omitempty"`
217- Choices []string `yaml:"choices,omitempty"`
218- } `yaml:"headers,omitempty"`
219- // Environment variables for server configuration
220- EnvVars []struct {
221- Name string `yaml:"name"`
222- Description string `yaml:"description"`
223- Required bool `yaml:"required"`
224- Default string `yaml:"default,omitempty"`
225- Secret bool `yaml:"secret,omitempty"`
226- } `yaml:"env_vars,omitempty"`
227- }
228230 var extended extendedFields
229231 if err := unmarshal (& extended ); err != nil {
230232 return err
@@ -234,7 +236,7 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
234236
235237 // Handle OAuth configuration transformation for remote servers
236238 if r .RemoteServerMetadata != nil && extended .OAuth != nil {
237- r .RemoteServerMetadata . OAuthConfig = & registry.OAuthConfig {
239+ r .OAuthConfig = & registry.OAuthConfig {
238240 Issuer : extended .OAuth .Issuer ,
239241 AuthorizeURL : extended .OAuth .AuthorizeURL ,
240242 TokenURL : extended .OAuth .TokenURL ,
@@ -245,17 +247,27 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
245247 }
246248 // Set UsePKCE default or explicit value
247249 if extended .OAuth .UsePKCE != nil {
248- r .RemoteServerMetadata . OAuthConfig .UsePKCE = * extended .OAuth .UsePKCE
250+ r .OAuthConfig .UsePKCE = * extended .OAuth .UsePKCE
249251 } else {
250- r .RemoteServerMetadata . OAuthConfig .UsePKCE = true // default to true
252+ r .OAuthConfig .UsePKCE = true // default to true
251253 }
252254 }
253255
254- // Handle Headers transformation for remote servers
255- if r .RemoteServerMetadata != nil && len (extended .Headers ) > 0 {
256- r .RemoteServerMetadata .Headers = make ([]* registry.Header , len (extended .Headers ))
256+ // Handle additional fields for remote servers
257+ if r .RemoteServerMetadata != nil {
258+ r .handleRemoteServerFields (& extended , raw )
259+ }
260+
261+ return nil
262+ }
263+
264+ // handleRemoteServerFields handles headers, env vars, and custom metadata for remote servers
265+ func (r * RegistryEntry ) handleRemoteServerFields (extended * extendedFields , raw map [string ]interface {}) {
266+ // Handle Headers transformation
267+ if len (extended .Headers ) > 0 {
268+ r .Headers = make ([]* registry.Header , len (extended .Headers ))
257269 for i , h := range extended .Headers {
258- r .RemoteServerMetadata . Headers [i ] = & registry.Header {
270+ r .Headers [i ] = & registry.Header {
259271 Name : h .Name ,
260272 Description : h .Description ,
261273 Required : h .Required ,
@@ -266,8 +278,8 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
266278 }
267279 }
268280
269- // Handle EnvVars transformation for remote servers
270- if r . RemoteServerMetadata != nil && len (extended .EnvVars ) > 0 {
281+ // Handle EnvVars transformation (only for RemoteServerMetadata)
282+ if len (extended .EnvVars ) > 0 {
271283 r .RemoteServerMetadata .EnvVars = make ([]* registry.EnvVar , len (extended .EnvVars ))
272284 for i , e := range extended .EnvVars {
273285 r .RemoteServerMetadata .EnvVars [i ] = & registry.EnvVar {
@@ -280,27 +292,22 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
280292 }
281293 }
282294
283- // Handle custom metadata fields for remote servers (homepage, license, author, etc.)
284- if r .RemoteServerMetadata != nil {
285- // Extract custom fields from the raw YAML that aren't part of the standard schema
286- customFields := make (map [string ]interface {})
287-
288- // Check for common custom fields
289- if val , exists := raw ["homepage" ]; exists {
290- customFields ["homepage" ] = val
291- }
292- if val , exists := raw ["license" ]; exists {
293- customFields ["license" ] = val
294- }
295- if val , exists := raw ["author" ]; exists {
296- customFields ["author" ] = val
297- }
298-
299- // Set custom metadata if we found any custom fields
300- if len (customFields ) > 0 {
301- r .RemoteServerMetadata .CustomMetadata = customFields
302- }
295+ // Handle custom metadata fields (homepage, license, author, etc.)
296+ customFields := make (map [string ]interface {})
297+
298+ // Check for common custom fields
299+ if val , exists := raw ["homepage" ]; exists {
300+ customFields ["homepage" ] = val
301+ }
302+ if val , exists := raw ["license" ]; exists {
303+ customFields ["license" ] = val
304+ }
305+ if val , exists := raw ["author" ]; exists {
306+ customFields ["author" ] = val
303307 }
304308
305- return nil
309+ // Set custom metadata if we found any custom fields
310+ if len (customFields ) > 0 {
311+ r .RemoteServerMetadata .CustomMetadata = customFields
312+ }
306313}
0 commit comments