@@ -12,7 +12,6 @@ import (
12
12
13
13
"github.com/github/github-mcp-server/pkg/github"
14
14
iolog "github.com/github/github-mcp-server/pkg/log"
15
- "github.com/github/github-mcp-server/pkg/toolsets"
16
15
"github.com/github/github-mcp-server/pkg/translations"
17
16
gogithub "github.com/google/go-github/v69/github"
18
17
"github.com/mark3labs/mcp-go/server"
@@ -45,10 +44,16 @@ var (
45
44
if err != nil {
46
45
stdlog .Fatal ("Failed to initialize logger:" , err )
47
46
}
48
- enabledToolsets := viper .GetStringSlice ("features" )
49
- features , err := initToolsets (enabledToolsets )
50
- if err != nil {
51
- stdlog .Fatal ("Failed to initialize features:" , err )
47
+
48
+ enabledToolsets := viper .GetStringSlice ("toolsets" )
49
+
50
+ // Env gets precedence over command line flags
51
+ if envToolsets := os .Getenv ("GITHUB_TOOLSETS" ); envToolsets != "" {
52
+ enabledToolsets = []string {}
53
+ // Split envFeats by comma, trim whitespace, and add to the slice
54
+ for _ , toolset := range strings .Split (envToolsets , "," ) {
55
+ enabledToolsets = append (enabledToolsets , strings .TrimSpace (toolset ))
56
+ }
52
57
}
53
58
54
59
logCommands := viper .GetBool ("enable-command-logging" )
57
62
logger : logger ,
58
63
logCommands : logCommands ,
59
64
exportTranslations : exportTranslations ,
60
- features : features ,
65
+ enabledToolsets : enabledToolsets ,
61
66
}
62
67
if err := runStdioServer (cfg ); err != nil {
63
68
stdlog .Fatal ("failed to run stdio server:" , err )
@@ -66,53 +71,19 @@ var (
66
71
}
67
72
)
68
73
69
- func initToolsets (passedToolsets []string ) (* toolsets.ToolsetGroup , error ) {
70
- // Create a new toolset group
71
- fs := toolsets .NewToolsetGroup ()
72
-
73
- // Define all available features with their default state (disabled)
74
- fs .AddToolset ("repos" , "Repository related tools" , false )
75
- fs .AddToolset ("issues" , "Issues related tools" , false )
76
- fs .AddToolset ("search" , "Search related tools" , false )
77
- fs .AddToolset ("pull_requests" , "Pull request related tools" , false )
78
- fs .AddToolset ("code_security" , "Code security related tools" , false )
79
- fs .AddToolset ("experiments" , "Experimental features that are not considered stable yet" , false )
80
-
81
- // fs.AddFeature("actions", "GitHub Actions related tools", false)
82
- // fs.AddFeature("projects", "GitHub Projects related tools", false)
83
- // fs.AddFeature("secret_protection", "Secret protection related tools", false)
84
- // fs.AddFeature("gists", "Gist related tools", false)
85
-
86
- // Env gets precedence over command line flags
87
- if envFeats := os .Getenv ("GITHUB_TOOLSETS" ); envFeats != "" {
88
- passedToolsets = []string {}
89
- // Split envFeats by comma, trim whitespace, and add to the slice
90
- for _ , feature := range strings .Split (envFeats , "," ) {
91
- passedToolsets = append (passedToolsets , strings .TrimSpace (feature ))
92
- }
93
- }
94
-
95
- // Enable the requested features
96
- if err := fs .EnableToolsets (passedToolsets ); err != nil {
97
- return nil , err
98
- }
99
-
100
- return fs , nil
101
- }
102
-
103
74
func init () {
104
75
cobra .OnInitialize (initConfig )
105
76
106
77
// Add global flags that will be shared by all commands
107
- rootCmd .PersistentFlags ().StringSlice ("features " , []string {"repos" , "issues" , "pull_requests" , "search" }, "A comma separated list of groups of tools to enable, defaults to issues/repos/search" )
78
+ rootCmd .PersistentFlags ().StringSlice ("toolsets " , []string {"repos" , "issues" , "pull_requests" , "search" }, "A comma separated list of groups of tools to enable, defaults to issues/repos/search" )
108
79
rootCmd .PersistentFlags ().Bool ("read-only" , false , "Restrict the server to read-only operations" )
109
80
rootCmd .PersistentFlags ().String ("log-file" , "" , "Path to log file" )
110
81
rootCmd .PersistentFlags ().Bool ("enable-command-logging" , false , "When enabled, the server will log all command requests and responses to the log file" )
111
82
rootCmd .PersistentFlags ().Bool ("export-translations" , false , "Save translations to a JSON file" )
112
83
rootCmd .PersistentFlags ().String ("gh-host" , "" , "Specify the GitHub hostname (for GitHub Enterprise etc.)" )
113
84
114
85
// Bind flag to viper
115
- _ = viper .BindPFlag ("features " , rootCmd .PersistentFlags ().Lookup ("features " ))
86
+ _ = viper .BindPFlag ("toolsets " , rootCmd .PersistentFlags ().Lookup ("toolsets " ))
116
87
_ = viper .BindPFlag ("read-only" , rootCmd .PersistentFlags ().Lookup ("read-only" ))
117
88
_ = viper .BindPFlag ("log-file" , rootCmd .PersistentFlags ().Lookup ("log-file" ))
118
89
_ = viper .BindPFlag ("enable-command-logging" , rootCmd .PersistentFlags ().Lookup ("enable-command-logging" ))
@@ -151,7 +122,7 @@ type runConfig struct {
151
122
logger * log.Logger
152
123
logCommands bool
153
124
exportTranslations bool
154
- features * toolsets. ToolsetGroup
125
+ enabledToolsets [] string
155
126
}
156
127
157
128
func runStdioServer (cfg runConfig ) error {
@@ -186,8 +157,18 @@ func runStdioServer(cfg runConfig) error {
186
157
getClient := func (_ context.Context ) (* gogithub.Client , error ) {
187
158
return ghClient , nil // closing over client
188
159
}
189
- // Create
190
- ghServer := github .NewServer (getClient , cfg .features , version , cfg .readOnly , t )
160
+
161
+ // Create server
162
+ ghServer := github .NewServer (version )
163
+
164
+ // Create toolsets
165
+ toolsets , err := github .InitToolsets (ghServer , cfg .enabledToolsets , cfg .readOnly , getClient , t )
166
+ if err != nil {
167
+ stdlog .Fatal ("Failed to initialize toolsets:" , err )
168
+ }
169
+ // Register the tools with the server
170
+ toolsets .RegisterTools (ghServer )
171
+
191
172
stdioServer := server .NewStdioServer (ghServer )
192
173
193
174
stdLogger := stdlog .New (cfg .logger .Writer (), "stdioserver" , 0 )
0 commit comments