@@ -44,12 +44,16 @@ var (
44
44
if err != nil {
45
45
stdlog .Fatal ("Failed to initialize logger:" , err )
46
46
}
47
+
48
+ enabledToolsets := viper .GetStringSlice ("toolsets" )
49
+
47
50
logCommands := viper .GetBool ("enable-command-logging" )
48
51
cfg := runConfig {
49
52
readOnly : readOnly ,
50
53
logger : logger ,
51
54
logCommands : logCommands ,
52
55
exportTranslations : exportTranslations ,
56
+ enabledToolsets : enabledToolsets ,
53
57
}
54
58
if err := runStdioServer (cfg ); err != nil {
55
59
stdlog .Fatal ("failed to run stdio server:" , err )
@@ -62,26 +66,30 @@ func init() {
62
66
cobra .OnInitialize (initConfig )
63
67
64
68
// Add global flags that will be shared by all commands
69
+ rootCmd .PersistentFlags ().StringSlice ("toolsets" , github .DefaultTools , "An optional comma separated list of groups of tools to allow, defaults to enabling all" )
70
+ rootCmd .PersistentFlags ().Bool ("dynamic-toolsets" , false , "Enable dynamic toolsets" )
65
71
rootCmd .PersistentFlags ().Bool ("read-only" , false , "Restrict the server to read-only operations" )
66
72
rootCmd .PersistentFlags ().String ("log-file" , "" , "Path to log file" )
67
73
rootCmd .PersistentFlags ().Bool ("enable-command-logging" , false , "When enabled, the server will log all command requests and responses to the log file" )
68
74
rootCmd .PersistentFlags ().Bool ("export-translations" , false , "Save translations to a JSON file" )
69
75
rootCmd .PersistentFlags ().String ("gh-host" , "" , "Specify the GitHub hostname (for GitHub Enterprise etc.)" )
70
76
71
77
// Bind flag to viper
78
+ _ = viper .BindPFlag ("toolsets" , rootCmd .PersistentFlags ().Lookup ("toolsets" ))
79
+ _ = viper .BindPFlag ("dynamic_toolsets" , rootCmd .PersistentFlags ().Lookup ("dynamic-toolsets" ))
72
80
_ = viper .BindPFlag ("read-only" , rootCmd .PersistentFlags ().Lookup ("read-only" ))
73
81
_ = viper .BindPFlag ("log-file" , rootCmd .PersistentFlags ().Lookup ("log-file" ))
74
82
_ = viper .BindPFlag ("enable-command-logging" , rootCmd .PersistentFlags ().Lookup ("enable-command-logging" ))
75
83
_ = viper .BindPFlag ("export-translations" , rootCmd .PersistentFlags ().Lookup ("export-translations" ))
76
- _ = viper .BindPFlag ("gh- host" , rootCmd .PersistentFlags ().Lookup ("gh-host" ))
84
+ _ = viper .BindPFlag ("host" , rootCmd .PersistentFlags ().Lookup ("gh-host" ))
77
85
78
86
// Add subcommands
79
87
rootCmd .AddCommand (stdioCmd )
80
88
}
81
89
82
90
func initConfig () {
83
91
// Initialize Viper configuration
84
- viper .SetEnvPrefix ("APP " )
92
+ viper .SetEnvPrefix ("github " )
85
93
viper .AutomaticEnv ()
86
94
}
87
95
@@ -107,6 +115,7 @@ type runConfig struct {
107
115
logger * log.Logger
108
116
logCommands bool
109
117
exportTranslations bool
118
+ enabledToolsets []string
110
119
}
111
120
112
121
func runStdioServer (cfg runConfig ) error {
@@ -115,18 +124,14 @@ func runStdioServer(cfg runConfig) error {
115
124
defer stop ()
116
125
117
126
// Create GH client
118
- token := os . Getenv ( "GITHUB_PERSONAL_ACCESS_TOKEN " )
127
+ token := viper . GetString ( "personal_access_token " )
119
128
if token == "" {
120
129
cfg .logger .Fatal ("GITHUB_PERSONAL_ACCESS_TOKEN not set" )
121
130
}
122
131
ghClient := gogithub .NewClient (nil ).WithAuthToken (token )
123
132
ghClient .UserAgent = fmt .Sprintf ("github-mcp-server/%s" , version )
124
133
125
- // Check GH_HOST env var first, then fall back to viper config
126
- host := os .Getenv ("GH_HOST" )
127
- if host == "" {
128
- host = viper .GetString ("gh-host" )
129
- }
134
+ host := viper .GetString ("host" )
130
135
131
136
if host != "" {
132
137
var err error
@@ -149,8 +154,40 @@ func runStdioServer(cfg runConfig) error {
149
154
hooks := & server.Hooks {
150
155
OnBeforeInitialize : []server.OnBeforeInitializeFunc {beforeInit },
151
156
}
152
- // Create
153
- ghServer := github .NewServer (getClient , version , cfg .readOnly , t , server .WithHooks (hooks ))
157
+ // Create server
158
+ ghServer := github .NewServer (version , server .WithHooks (hooks ))
159
+
160
+ enabled := cfg .enabledToolsets
161
+ dynamic := viper .GetBool ("dynamic_toolsets" )
162
+ if dynamic {
163
+ // filter "all" from the enabled toolsets
164
+ enabled = make ([]string , 0 , len (cfg .enabledToolsets ))
165
+ for _ , toolset := range cfg .enabledToolsets {
166
+ if toolset != "all" {
167
+ enabled = append (enabled , toolset )
168
+ }
169
+ }
170
+ }
171
+
172
+ // Create default toolsets
173
+ toolsets , err := github .InitToolsets (enabled , cfg .readOnly , getClient , t )
174
+ context := github .InitContextToolset (getClient , t )
175
+
176
+ if err != nil {
177
+ stdlog .Fatal ("Failed to initialize toolsets:" , err )
178
+ }
179
+
180
+ // Register resources with the server
181
+ github .RegisterResources (ghServer , getClient , t )
182
+ // Register the tools with the server
183
+ toolsets .RegisterTools (ghServer )
184
+ context .RegisterTools (ghServer )
185
+
186
+ if dynamic {
187
+ dynamic := github .InitDynamicToolset (ghServer , toolsets , t )
188
+ dynamic .RegisterTools (ghServer )
189
+ }
190
+
154
191
stdioServer := server .NewStdioServer (ghServer )
155
192
156
193
stdLogger := stdlog .New (cfg .logger .Writer (), "stdioserver" , 0 )
0 commit comments