@@ -84,12 +84,11 @@ func (r *VirtualMCPCompositeToolDefinition) Validate() error {
8484 // Validate failure mode
8585 if r .Spec .FailureMode != "" {
8686 validModes := map [string ]bool {
87- "abort" : true ,
88- "continue" : true ,
89- "best_effort" : true ,
87+ "abort" : true ,
88+ "continue" : true ,
9089 }
9190 if ! validModes [r .Spec .FailureMode ] {
92- errors = append (errors , "spec.failureMode must be one of: abort, continue, best_effort " )
91+ errors = append (errors , "spec.failureMode must be one of: abort, continue" )
9392 }
9493 }
9594
@@ -102,59 +101,36 @@ func (r *VirtualMCPCompositeToolDefinition) Validate() error {
102101
103102// validateParameters validates the parameter schema using JSON Schema validation
104103func (r * VirtualMCPCompositeToolDefinition ) validateParameters () error {
105- if len (r .Spec .Parameters ) == 0 {
104+ if r . Spec . Parameters == nil || len (r .Spec .Parameters . Raw ) == 0 {
106105 return nil // No parameters to validate
107106 }
108107
109- // Build a JSON Schema object from the parameters
110- // Parameters map to a JSON Schema "properties" object
111- properties := make (map [string ]interface {})
112- var required []string
113-
114- for paramName , param := range r .Spec .Parameters {
115- if param .Type == "" {
116- return fmt .Errorf ("spec.parameters[%s].type is required" , paramName )
117- }
118-
119- // Build a JSON Schema property definition
120- property := map [string ]interface {}{
121- "type" : param .Type ,
122- }
123-
124- if param .Description != "" {
125- property ["description" ] = param .Description
126- }
127-
128- if param .Default != "" {
129- // Parse default value based on type
130- property ["default" ] = param .Default
131- }
132-
133- if param .Required {
134- required = append (required , paramName )
135- }
136-
137- properties [paramName ] = property
108+ // Parameters should be a JSON Schema object in RawExtension format
109+ // Unmarshal to validate structure
110+ var params map [string ]interface {}
111+ if err := json .Unmarshal (r .Spec .Parameters .Raw , & params ); err != nil {
112+ return fmt .Errorf ("spec.parameters: invalid JSON: %v" , err )
138113 }
139114
140- // Construct a full JSON Schema document
141- schemaDoc := map [ string ] interface {}{
142- "type" : "object" ,
143- "properties" : properties ,
115+ // Validate that it has "type" field
116+ typeVal , hasType := params [ "type" ]
117+ if ! hasType {
118+ return fmt . Errorf ( "spec.parameters: must have 'type' field (should be 'object' for JSON Schema)" )
144119 }
145120
146- if len (required ) > 0 {
147- schemaDoc ["required" ] = required
121+ // Type must be a string
122+ typeStr , ok := typeVal .(string )
123+ if ! ok {
124+ return fmt .Errorf ("spec.parameters: 'type' field must be a string" )
148125 }
149126
150- // Marshal to JSON
151- schemaJSON , err := json .Marshal (schemaDoc )
152- if err != nil {
153- return fmt .Errorf ("spec.parameters: failed to marshal schema: %v" , err )
127+ // Type should be "object" for parameter schemas
128+ if typeStr != "object" {
129+ return fmt .Errorf ("spec.parameters: 'type' must be 'object' (got '%s')" , typeStr )
154130 }
155131
156132 // Validate using JSON Schema validator
157- if err := validateJSONSchema (schemaJSON ); err != nil {
133+ if err := validateJSONSchema (r . Spec . Parameters . Raw ); err != nil {
158134 return fmt .Errorf ("spec.parameters: invalid JSON Schema: %v" , err )
159135 }
160136
0 commit comments