Skip to content

Commit a5ba7ff

Browse files
refactor: remove hardcoded getDefaultOAuthScopes fallback
Remove the hardcoded fallback in favor of deriving OAuth scopes from the canonical inventory. This ensures scopes always match the enabled tools rather than a potentially stale hardcoded list. - Remove getDefaultOAuthScopes() function entirely - Error case now returns nil scopes (error surfaces at server start) - Empty scopes is valid (tools may not require auth) - Scopes are always computed from inventory.AvailableTools()
1 parent 118da77 commit a5ba7ff

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

cmd/github-mcp-server/main.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ type oauthScopesResult struct {
219219
// from the tools that will be enabled based on user configuration
220220
func getOAuthScopes(enabledToolsets, enabledTools, enabledFeatures []string, t translations.TranslationHelperFunc) oauthScopesResult {
221221
// Allow explicit override via --oauth-scopes flag
222-
var scopes []string
222+
var scopeList []string
223223
if viper.IsSet("oauth_scopes") {
224-
if err := viper.UnmarshalKey("oauth_scopes", &scopes); err == nil && len(scopes) > 0 {
224+
if err := viper.UnmarshalKey("oauth_scopes", &scopeList); err == nil && len(scopeList) > 0 {
225225
// When scopes are explicit, don't build inventory (will be built in server)
226-
return oauthScopesResult{scopes: scopes}
226+
return oauthScopesResult{scopes: scopeList}
227227
}
228228
}
229229

@@ -238,33 +238,17 @@ func getOAuthScopes(enabledToolsets, enabledTools, enabledFeatures []string, t t
238238

239239
inv, err := inventoryBuilder.Build()
240240
if err != nil {
241-
// If inventory build fails, fall back to default scopes without inventory
242-
return oauthScopesResult{scopes: getDefaultOAuthScopes()}
241+
// Inventory build only fails if invalid tool names are passed via --tools
242+
// In that case, return empty scopes - the error will surface when server starts
243+
return oauthScopesResult{scopes: nil}
243244
}
244245

245246
// Collect all required scopes from available tools
247+
// This is the canonical source of OAuth scopes for the enabled tools
246248
requiredScopes := collectRequiredScopes(inv)
247-
if len(requiredScopes) == 0 {
248-
// If no tools require scopes, use defaults
249-
return oauthScopesResult{scopes: getDefaultOAuthScopes(), inventory: inv}
250-
}
251-
252249
return oauthScopesResult{scopes: requiredScopes, inventory: inv}
253250
}
254251

255-
// getDefaultOAuthScopes returns the default scopes for GitHub MCP Server
256-
// Based on the protected resource metadata at https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp
257-
func getDefaultOAuthScopes() []string {
258-
return []string{
259-
"repo",
260-
"user",
261-
"gist",
262-
"notifications",
263-
"read:org",
264-
"project",
265-
}
266-
}
267-
268252
// collectRequiredScopes collects all unique required scopes from available tools
269253
// Returns a sorted, deduplicated list of OAuth scopes needed for the enabled tools
270254
func collectRequiredScopes(inv *inventory.Inventory) []string {

0 commit comments

Comments
 (0)