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

Function GenerateMCPScriptsToolsConfig

pkg/workflow/mcp_scripts_generator.go:37–141  ·  view source on GitHub ↗

GenerateMCPScriptsToolsConfig generates the tools.json configuration for the mcp-scripts MCP server

(mcpScripts *MCPScriptsConfig)

Source from the content-addressed store, hash-verified

35
36// GenerateMCPScriptsToolsConfig generates the tools.json configuration for the mcp-scripts MCP server
37func GenerateMCPScriptsToolsConfig(mcpScripts *MCPScriptsConfig) string {
38 mcpScriptsGeneratorLog.Printf("Generating mcp-scripts tools.json config: tool_count=%d", len(mcpScripts.Tools))
39
40 config := MCPScriptsConfigJSON{
41 ServerName: "mcpscripts",
42 Version: constants.MCPScriptsMCPVersion,
43 LogDir: MCPScriptsDirectory + "/logs",
44 Tools: []MCPScriptsToolJSON{},
45 }
46
47 // Sort tool names for stable output
48 toolNames := sliceutil.SortedKeys(mcpScripts.Tools)
49
50 for _, toolName := range toolNames {
51 toolConfig := mcpScripts.Tools[toolName]
52
53 // Build input schema
54 inputSchema := map[string]any{
55 "type": "object",
56 "properties": make(map[string]any),
57 }
58
59 props, ok := inputSchema["properties"].(map[string]any)
60 if !ok {
61 props = make(map[string]any)
62 inputSchema["properties"] = props
63 }
64 var required []string
65
66 // Sort input names for stable output
67 inputNames := sliceutil.SortedKeys(toolConfig.Inputs)
68
69 for _, paramName := range inputNames {
70 param := toolConfig.Inputs[paramName]
71 propDef := map[string]any{
72 "type": param.Type,
73 "description": param.Description,
74 }
75 if param.Default != nil {
76 propDef["default"] = param.Default
77 }
78 props[paramName] = propDef
79 if param.Required {
80 required = append(required, paramName)
81 }
82 }
83
84 sort.Strings(required)
85 if len(required) > 0 {
86 inputSchema["required"] = required
87 }
88
89 // Determine handler path based on script type
90 var handler string
91 if toolConfig.Script != "" {
92 handler = toolName + ".cjs"
93 } else if toolConfig.Run != "" {
94 handler = toolName + ".sh"

Calls 2

SortedKeysFunction · 0.92
PrintfMethod · 0.45