@@ -16,8 +16,9 @@ import (
16
16
17
17
// Parameter represents a tool parameter with a name and type.
18
18
type Parameter struct {
19
- Name string
20
- Type string
19
+ Name string
20
+ Type string
21
+ Required bool
21
22
}
22
23
23
24
// Tool represents a proxy tool that executes a shell script or command.
@@ -157,6 +158,7 @@ func (s *Server) AddTool(name, description, paramStr, scriptPath string, command
157
158
}
158
159
159
160
// parseParameters parses a comma-separated parameter string in the format "name:type,name:type".
161
+ // If a parameter is wrapped in square brackets like [name:type], it's considered optional.
160
162
func parseParameters (paramStr string ) ([]Parameter , error ) {
161
163
if paramStr == "" {
162
164
return []Parameter {}, nil
@@ -166,6 +168,17 @@ func parseParameters(paramStr string) ([]Parameter, error) {
166
168
parameters := make ([]Parameter , 0 , len (params ))
167
169
168
170
for _ , param := range params {
171
+ param = strings .TrimSpace (param )
172
+ required := true
173
+
174
+ // Check if parameter is optional (wrapped in square brackets)
175
+ if strings .HasPrefix (param , "[" ) && strings .HasSuffix (param , "]" ) {
176
+ // Remove the brackets
177
+ param = strings .TrimPrefix (param , "[" )
178
+ param = strings .TrimSuffix (param , "]" )
179
+ required = false
180
+ }
181
+
169
182
parts := strings .Split (strings .TrimSpace (param ), ":" )
170
183
if len (parts ) != 2 {
171
184
return nil , fmt .Errorf ("invalid parameter format: %s, expected name:type" , param )
@@ -189,8 +202,9 @@ func parseParameters(paramStr string) ([]Parameter, error) {
189
202
}
190
203
191
204
parameters = append (parameters , Parameter {
192
- Name : name ,
193
- Type : normalizedType ,
205
+ Name : name ,
206
+ Type : normalizedType ,
207
+ Required : required ,
194
208
})
195
209
}
196
210
@@ -286,7 +300,11 @@ func (s *Server) GetToolSchema(toolName string) (map[string]interface{}, error)
286
300
}
287
301
288
302
properties [param .Name ] = paramSchema
289
- required = append (required , param .Name )
303
+
304
+ // Only add the parameter to required list if it's marked as required
305
+ if param .Required {
306
+ required = append (required , param .Name )
307
+ }
290
308
}
291
309
292
310
schema := map [string ]interface {}{
@@ -435,7 +453,11 @@ func (s *Server) handleToolsList() map[string]interface{} {
435
453
}
436
454
437
455
properties [param .Name ] = paramSchema
438
- required = append (required , param .Name )
456
+
457
+ // Only add to required list if the parameter is required
458
+ if param .Required {
459
+ required = append (required , param .Name )
460
+ }
439
461
}
440
462
441
463
schema := map [string ]interface {}{
@@ -471,7 +493,7 @@ func (s *Server) handleToolCall(params map[string]interface{}) (map[string]inter
471
493
return nil , fmt .Errorf ("'name' parameter must be a string" )
472
494
}
473
495
474
- _ , exists := s .tools [name ]
496
+ tool , exists := s .tools [name ]
475
497
if ! exists {
476
498
return nil , fmt .Errorf ("tool not found: %s" , name )
477
499
}
@@ -487,6 +509,15 @@ func (s *Server) handleToolCall(params map[string]interface{}) (map[string]inter
487
509
return nil , fmt .Errorf ("'arguments' parameter must be an object" )
488
510
}
489
511
512
+ // Check for required parameters
513
+ for _ , param := range tool .Parameters {
514
+ if param .Required {
515
+ if _ , exists := arguments [param .Name ]; ! exists {
516
+ return nil , fmt .Errorf ("missing required parameter: %s" , param .Name )
517
+ }
518
+ }
519
+ }
520
+
490
521
// Log the input parameters
491
522
s .logJSON ("Tool input" , arguments )
492
523
@@ -605,7 +636,11 @@ func RunProxyServer(toolConfigs map[string]map[string]string) error {
605
636
if i > 0 {
606
637
paramStr += ", "
607
638
}
608
- paramStr += param .Name + ":" + param .Type
639
+ if param .Required {
640
+ paramStr += param .Name + ":" + param .Type
641
+ } else {
642
+ paramStr += "[" + param .Name + ":" + param .Type + "]"
643
+ }
609
644
}
610
645
if paramStr != "" {
611
646
fmt .Fprintf (os .Stderr , " Parameters: %s\n " , paramStr )
0 commit comments