MCPcopy Create free account
hub / github.com/github/gh-aw / buildInputSchema

Function buildInputSchema

pkg/workflow/build_input_schema.go:17–87  ·  view source on GitHub ↗

buildInputSchema converts GitHub Actions input definitions (workflow_dispatch, workflow_call, or dispatch_repository inputs) into JSON Schema properties and a required field list suitable for MCP tool inputSchema. descriptionFn is called to produce the fallback description when an input definition

(inputs map[string]any, descriptionFn func(inputName string) string)

Source from the content-addressed store, hash-verified

15// Choice inputs with options are mapped to a string enum. Unknown types default
16// to string.
17func buildInputSchema(inputs map[string]any, descriptionFn func(inputName string) string) (properties map[string]any, required []string) {
18 buildInputSchemaLog.Printf("Building input schema for %d inputs", len(inputs))
19 properties = make(map[string]any)
20 required = []string{}
21
22 for inputName, inputDef := range inputs {
23 inputDefMap, ok := inputDef.(map[string]any)
24 if !ok {
25 buildInputSchemaLog.Printf("Skipping input %q: expected map, got %T", inputName, inputDef)
26 continue
27 }
28
29 inputType := "string"
30 inputDescription := descriptionFn(inputName)
31 inputRequired := false
32
33 if desc, ok := inputDefMap["description"].(string); ok && desc != "" {
34 inputDescription = desc
35 }
36
37 if req, ok := inputDefMap["required"].(bool); ok {
38 inputRequired = req
39 }
40
41 // Map GitHub Actions input types to JSON Schema types.
42 if typeStr, ok := inputDefMap["type"].(string); ok {
43 switch typeStr {
44 case "number":
45 inputType = "number"
46 case "boolean":
47 inputType = "boolean"
48 case "choice":
49 inputType = "string"
50 if options, ok := inputDefMap["options"].([]any); ok && len(options) > 0 {
51 prop := map[string]any{
52 "type": inputType,
53 "description": inputDescription,
54 "enum": options,
55 }
56 if defaultVal, ok := inputDefMap["default"]; ok {
57 prop["default"] = defaultVal
58 }
59 properties[inputName] = prop
60 if inputRequired {
61 required = append(required, inputName)
62 }
63 continue
64 }
65 case "environment":
66 inputType = "string"
67 }
68 }
69
70 prop := map[string]any{
71 "type": inputType,
72 "description": inputDescription,
73 }
74 if defaultVal, ok := inputDefMap["default"]; ok {

Calls 1

PrintfMethod · 0.45