Files
github--github-mcp-server/pkg/github/tool_scopes.go
Sam Morrow 05d9ff132b feat(auth): add OAuth scope policies
Model authorization as alternative paths with conjunctive requirements and
per-requirement scope alternatives. Resolve call-specific policies from tool
arguments for precise PAT filtering and OAuth challenges.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 26e41558-43f9-42b2-8569-8489957c2b0a
2026-08-21 02:17:29 +02:00

45 lines
1.3 KiB
Go

package github
import (
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/scopes"
)
func repositoryOrOrganizationScopePolicy(arguments map[string]any) inventory.ScopePolicy {
if owner, ok := arguments["owner"].(string); !ok || owner == "" {
return scopes.UnscopedScopePolicy()
}
repoValue, hasRepo := arguments["repo"]
if !hasRepo || repoValue == nil || repoValue == "" {
return scopes.AllOfScopePolicy(scopes.ReadOrg)
}
repo, ok := repoValue.(string)
if !ok {
return scopes.UnscopedScopePolicy()
}
if repo != "" {
return scopes.AllOfScopePolicy(scopes.Repo)
}
return scopes.AllOfScopePolicy(scopes.ReadOrg)
}
func uiGetScopePolicy(arguments map[string]any) inventory.ScopePolicy {
if owner, ok := arguments["owner"].(string); !ok || owner == "" {
return scopes.UnscopedScopePolicy()
}
method, ok := arguments["method"].(string)
if !ok {
return scopes.UnscopedScopePolicy()
}
if method == "issue_types" {
return scopes.AllOfScopePolicy(scopes.ReadOrg)
}
switch method {
case "labels", "assignees", "milestones", "branches", "issue_fields", "reviewers":
if repo, ok := arguments["repo"].(string); ok && repo != "" {
return scopes.AllOfScopePolicy(scopes.Repo)
}
}
return scopes.UnscopedScopePolicy()
}