Skip to content

Commit 64fffaa

Browse files
committed
split up tooling
1 parent ef4b9c8 commit 64fffaa

File tree

4 files changed

+136
-155
lines changed

4 files changed

+136
-155
lines changed

internal/ghmcp/server.go

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

109-
enabledToolsets, invalidToolsets := github.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+
}
110123

111124
if len(invalidToolsets) > 0 {
112125
fmt.Fprintf(os.Stderr, "Invalid toolsets ignored: %s\n", strings.Join(invalidToolsets, ", "))

pkg/github/tools.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,9 @@ func GenerateToolsetsHelp() string {
450450
// - Duplicates are removed from the result
451451
// - Removes whitespaces
452452
// - Validates toolset names and returns invalid ones separately
453-
// - "all": Returns ["all"] immediately, ignoring all other toolsets
454-
// - when dynamicToolsets is true, filters out "all" from the enabled toolsets
455453
// - "default": Replaces with the actual default toolset IDs from GetDefaultToolsetIDs()
456-
// Returns: (validToolsets, invalidToolsets)
457-
func CleanToolsets(enabledToolsets []string, dynamicToolsets bool) ([]string, []string) {
454+
// Returns: (toolsets, invalidToolsets)
455+
func CleanToolsets(enabledToolsets []string) ([]string, []string) {
458456
seen := make(map[string]bool)
459457
result := make([]string, 0, len(enabledToolsets))
460458
invalid := make([]string, 0)
@@ -470,22 +468,15 @@ func CleanToolsets(enabledToolsets []string, dynamicToolsets bool) ([]string, []
470468
seen[trimmed] = true
471469
if trimmed != ToolsetMetadataDefault.ID && trimmed != ToolsetMetadataAll.ID {
472470
// Validate the toolset name
473-
if validIDs[trimmed] {
474-
result = append(result, trimmed)
475-
} else {
471+
result = append(result, trimmed)
472+
if !validIDs[trimmed] {
476473
invalid = append(invalid, trimmed)
477474
}
478475
}
479476
}
480477
}
481478

482479
hasDefault := seen[ToolsetMetadataDefault.ID]
483-
hasAll := seen[ToolsetMetadataAll.ID]
484-
485-
// Handle "all" keyword - return early if not in dynamic mode
486-
if hasAll && !dynamicToolsets {
487-
return []string{ToolsetMetadataAll.ID}, invalid
488-
}
489480

490481
// Expand "default" keyword to actual default toolsets
491482
if hasDefault {
@@ -499,3 +490,22 @@ func CleanToolsets(enabledToolsets []string, dynamicToolsets bool) ([]string, []
499490

500491
return result, invalid
501492
}
493+
494+
func RemoveToolset(tools []string, toRemove string) []string {
495+
result := []string{}
496+
for _, tool := range tools {
497+
if tool != toRemove {
498+
result = append(result, tool)
499+
}
500+
}
501+
return result
502+
}
503+
504+
func ContainsToolset(tools []string, toCheck string) bool {
505+
for _, tool := range tools {
506+
if tool == toCheck {
507+
return true
508+
}
509+
}
510+
return false
511+
}

0 commit comments

Comments
 (0)