Skip to content

Commit c019595

Browse files
tonytrgCopilot
andauthored
Split up tooling utility (#1273)
* split up functionality for reusability * Update pkg/github/tools.go Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 3ddf649 commit c019595

File tree

4 files changed

+374
-333
lines changed

4 files changed

+374
-333
lines changed

internal/ghmcp/server.go

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,24 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
106106
},
107107
}
108108

109-
enabledToolsets, invalidToolsets := cleanToolsets(cfg.EnabledToolsets, cfg.DynamicToolsets)
109+
enabledToolsets := cfg.EnabledToolsets
110+
111+
// If dynamic toolsets are enabled, remove "all" from the enabled toolsets
112+
if cfg.DynamicToolsets {
113+
enabledToolsets = github.RemoveToolset(enabledToolsets, github.ToolsetMetadataAll.ID)
114+
}
115+
116+
// Clean up the passed toolsets
117+
enabledToolsets, invalidToolsets := github.CleanToolsets(enabledToolsets)
118+
119+
// If "all" is present, override all other toolsets
120+
if github.ContainsToolset(enabledToolsets, github.ToolsetMetadataAll.ID) {
121+
enabledToolsets = []string{github.ToolsetMetadataAll.ID}
122+
}
123+
// If "default" is present, expand to real toolset IDs
124+
if github.ContainsToolset(enabledToolsets, github.ToolsetMetadataDefault.ID) {
125+
enabledToolsets = github.AddDefaultToolset(enabledToolsets)
126+
}
110127

111128
if len(invalidToolsets) > 0 {
112129
fmt.Fprintf(os.Stderr, "Invalid toolsets ignored: %s\n", strings.Join(invalidToolsets, ", "))
@@ -465,57 +482,3 @@ func (t *bearerAuthTransport) RoundTrip(req *http.Request) (*http.Response, erro
465482
req.Header.Set("Authorization", "Bearer "+t.token)
466483
return t.transport.RoundTrip(req)
467484
}
468-
469-
// cleanToolsets cleans and handles special toolset keywords:
470-
// - Duplicates are removed from the result
471-
// - Removes whitespaces
472-
// - Validates toolset names and returns invalid ones separately
473-
// - "all": Returns ["all"] immediately, ignoring all other toolsets
474-
// - when dynamicToolsets is true, filters out "all" from the enabled toolsets
475-
// - "default": Replaces with the actual default toolset IDs from GetDefaultToolsetIDs()
476-
// Returns: (validToolsets, invalidToolsets)
477-
func cleanToolsets(enabledToolsets []string, dynamicToolsets bool) ([]string, []string) {
478-
seen := make(map[string]bool)
479-
result := make([]string, 0, len(enabledToolsets))
480-
invalid := make([]string, 0)
481-
validIDs := github.GetValidToolsetIDs()
482-
483-
// Add non-default toolsets, removing duplicates and trimming whitespace
484-
for _, toolset := range enabledToolsets {
485-
trimmed := strings.TrimSpace(toolset)
486-
if trimmed == "" {
487-
continue
488-
}
489-
if !seen[trimmed] {
490-
seen[trimmed] = true
491-
if trimmed != github.ToolsetMetadataDefault.ID && trimmed != github.ToolsetMetadataAll.ID {
492-
// Validate the toolset name
493-
if validIDs[trimmed] {
494-
result = append(result, trimmed)
495-
} else {
496-
invalid = append(invalid, trimmed)
497-
}
498-
}
499-
}
500-
}
501-
502-
hasDefault := seen[github.ToolsetMetadataDefault.ID]
503-
hasAll := seen[github.ToolsetMetadataAll.ID]
504-
505-
// Handle "all" keyword - return early if not in dynamic mode
506-
if hasAll && !dynamicToolsets {
507-
return []string{github.ToolsetMetadataAll.ID}, invalid
508-
}
509-
510-
// Expand "default" keyword to actual default toolsets
511-
if hasDefault {
512-
for _, defaultToolset := range github.GetDefaultToolsetIDs() {
513-
if !seen[defaultToolset] {
514-
result = append(result, defaultToolset)
515-
seen[defaultToolset] = true
516-
}
517-
}
518-
}
519-
520-
return result, invalid
521-
}

internal/ghmcp/server_test.go

Lines changed: 0 additions & 278 deletions
This file was deleted.

0 commit comments

Comments
 (0)