MCPcopy Index your code
hub / github.com/github/github-mcp-server / buildArgumentsMap

Function buildArgumentsMap

cmd/mcpcurl/main.go:311–355  ·  view source on GitHub ↗

buildArgumentsMap extracts flag values into a map of arguments

(cmd *cobra.Command, tool *Tool)

Source from the content-addressed store, hash-verified

309
310// buildArgumentsMap extracts flag values into a map of arguments
311func buildArgumentsMap(cmd *cobra.Command, tool *Tool) (map[string]any, error) {
312 arguments := make(map[string]any)
313
314 for name, prop := range tool.InputSchema.Properties {
315 switch prop.Type {
316 case "string":
317 if value, _ := cmd.Flags().GetString(name); value != "" {
318 arguments[name] = value
319 }
320 case "number":
321 if value, _ := cmd.Flags().GetFloat64(name); value != 0 {
322 arguments[name] = value
323 }
324 case "integer":
325 if value, _ := cmd.Flags().GetInt64(name); value != 0 {
326 arguments[name] = value
327 }
328 case "boolean":
329 // For boolean, we need to check if it was explicitly set
330 if cmd.Flags().Changed(name) {
331 value, _ := cmd.Flags().GetBool(name)
332 arguments[name] = value
333 }
334 case "array":
335 if prop.Items != nil {
336 switch prop.Items.Type {
337 case "string":
338 if values, _ := cmd.Flags().GetStringSlice(name); len(values) > 0 {
339 arguments[name] = values
340 }
341 case "object":
342 if jsonStr, _ := cmd.Flags().GetString(name + "-json"); jsonStr != "" {
343 var jsonArray []any
344 if err := json.Unmarshal([]byte(jsonStr), &jsonArray); err != nil {
345 return nil, fmt.Errorf("error parsing JSON for %s: %w", name, err)
346 }
347 arguments[name] = jsonArray
348 }
349 }
350 }
351 }
352 }
353
354 return arguments, nil
355}
356
357// buildJSONRPCRequest creates a JSON-RPC request with the given tool name and arguments
358func buildJSONRPCRequest(method, toolName string, arguments map[string]any) (string, error) {

Callers 1

addCommandFromToolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected