Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
github-mcp-server/cmd/github-mcp-server/list_scopes.go at main · github/github-mcp-server · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
github-mcp-server
Repository navigation
Code
Issues
205
(205)
Pull requests
196
(196)
Discussions
Actions
Security and quality
2
(2)
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
github-mcp-server
/
cmd
/
github-mcp-server
/
list_scopes.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
289 lines (237 loc) · 7.91 KB
main
Breadcrumbs
github-mcp-server
/
cmd
/
github-mcp-server
/
list_scopes.go
Copy path
Top
File metadata and controls
Code
Blame
289 lines (237 loc) · 7.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package
main
import
(
"context"
"encoding/json"
"fmt"
"os"
"sort"
"strings"
"github.com/github/github-mcp-server/v2/pkg/github"
"github.com/github/github-mcp-server/v2/pkg/inventory"
"github.com/github/github-mcp-server/v2/pkg/translations"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// ToolScopeInfo contains scope information for a single tool.
type
ToolScopeInfo
struct
{
Name
string
`json:"name"`
Toolset
string
`json:"toolset"`
ReadOnly
bool
`json:"read_only"`
ChallengeScopes
[]
string
`json:"challenge_scopes,omitempty"`
}
// ScopesOutput is the full output structure for the list-scopes command.
type
ScopesOutput
struct
{
Tools
[]
ToolScopeInfo
`json:"tools"`
UniqueScopes
[]
string
`json:"unique_scopes"`
ScopesByTool
map
[
string
][]
string
`json:"scopes_by_tool"`
ToolsByScope
map
[
string
][]
string
`json:"tools_by_scope"`
EnabledToolsets
[]
string
`json:"enabled_toolsets"`
ReadOnly
bool
`json:"read_only"`
}
var
listScopesCmd
=
&
cobra.
Command
{
Use
:
"list-scopes"
,
Short
:
"List OAuth scope policies for enabled tools"
,
Long
:
`List the OAuth challenge scopes for all enabled tools.
This command creates an inventory based on the same flags as the stdio command
and outputs the scopes each enabled tool may request in an OAuth challenge.
The output format can be controlled with the --output flag:
- text (default): Human-readable text output
- json: JSON output for programmatic use
- summary: Just the unique scopes needed
Examples:
# List scopes for default toolsets
github-mcp-server list-scopes
# List scopes for specific toolsets
github-mcp-server list-scopes --toolsets=repos,issues,pull_requests
# List scopes for all toolsets
github-mcp-server list-scopes --toolsets=all
# Output as JSON
github-mcp-server list-scopes --output=json
# Just show unique scopes needed
github-mcp-server list-scopes --output=summary`
,
RunE
:
func
(
_
*
cobra.
Command
,
_
[]
string
)
error
{
return
runListScopes
()
},
}
func
init
() {
listScopesCmd
.
Flags
().
StringP
(
"output"
,
"o"
,
"text"
,
"Output format: text, json, or summary"
)
_
=
viper
.
BindPFlag
(
"list-scopes-output"
,
listScopesCmd
.
Flags
().
Lookup
(
"output"
))
rootCmd
.
AddCommand
(
listScopesCmd
)
}
// formatScopeDisplay formats a scope string for display, handling empty scopes.
func
formatScopeDisplay
(
scope
string
)
string
{
if
scope
==
""
{
return
"(no scope required for public read access)"
}
return
scope
}
func
runListScopes
()
error
{
// Get toolsets configuration (same logic as stdio command)
var
enabledToolsets
[]
string
if
viper
.
IsSet
(
"toolsets"
) {
if
err
:=
viper
.
UnmarshalKey
(
"toolsets"
,
&
enabledToolsets
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to unmarshal toolsets: %w"
,
err
)
}
}
// else: enabledToolsets stays nil, meaning "use defaults"
// Get specific tools (similar to toolsets)
var
enabledTools
[]
string
if
viper
.
IsSet
(
"tools"
) {
if
err
:=
viper
.
UnmarshalKey
(
"tools"
,
&
enabledTools
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to unmarshal tools: %w"
,
err
)
}
}
readOnly
:=
viper
.
GetBool
(
"read-only"
)
outputFormat
:=
viper
.
GetString
(
"list-scopes-output"
)
// Create translation helper
t
,
_
:=
translations
.
TranslationHelper
()
// Build inventory using the same logic as the stdio server
inventoryBuilder
:=
github
.
NewInventory
(
t
).
WithReadOnly
(
readOnly
)
// Configure toolsets (same as stdio)
if
enabledToolsets
!=
nil
{
inventoryBuilder
=
inventoryBuilder
.
WithToolsets
(
enabledToolsets
)
}
// Configure specific tools
if
len
(
enabledTools
)
>
0
{
inventoryBuilder
=
inventoryBuilder
.
WithTools
(
enabledTools
)
}
inv
,
err
:=
inventoryBuilder
.
Build
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to build inventory: %w"
,
err
)
}
// Collect all tools and their scopes
output
:=
collectToolScopes
(
inv
,
readOnly
)
// Output based on format
switch
outputFormat
{
case
"json"
:
return
outputJSON
(
output
)
case
"summary"
:
return
outputSummary
(
output
)
default
:
return
outputText
(
output
)
}
}
func
collectToolScopes
(
inv
*
inventory.
Inventory
,
readOnly
bool
)
ScopesOutput
{
var
tools
[]
ToolScopeInfo
scopeSet
:=
make
(
map
[
string
]
bool
)
scopesByTool
:=
make
(
map
[
string
][]
string
)
toolsByScope
:=
make
(
map
[
string
][]
string
)
// Get all available tools from the inventory
// Use context.Background() for feature flag evaluation
availableTools
:=
inv
.
AvailableTools
(
context
.
Background
())
for
_
,
serverTool
:=
range
availableTools
{
tool
:=
serverTool
.
Tool
challengeScopes
:=
serverTool
.
ScopeAccess
.
Scopes
// Determine if tool is read-only
isReadOnly
:=
serverTool
.
IsReadOnly
()
toolInfo
:=
ToolScopeInfo
{
Name
:
tool
.
Name
,
Toolset
:
string
(
serverTool
.
Toolset
.
ID
),
ReadOnly
:
isReadOnly
,
ChallengeScopes
:
challengeScopes
,
}
tools
=
append
(
tools
,
toolInfo
)
// Track unique scopes
for
_
,
s
:=
range
challengeScopes
{
scopeSet
[
s
]
=
true
toolsByScope
[
s
]
=
append
(
toolsByScope
[
s
],
tool
.
Name
)
}
// Track scopes by tool
scopesByTool
[
tool
.
Name
]
=
challengeScopes
}
// Sort tools by name
sort
.
Slice
(
tools
,
func
(
i
,
j
int
)
bool
{
return
tools
[
i
].
Name
<
tools
[
j
].
Name
})
// Get unique scopes as sorted slice
var
uniqueScopes
[]
string
for
s
:=
range
scopeSet
{
uniqueScopes
=
append
(
uniqueScopes
,
s
)
}
sort
.
Strings
(
uniqueScopes
)
// Sort tools within each scope
for
scope
:=
range
toolsByScope
{
sort
.
Strings
(
toolsByScope
[
scope
])
}
// Get enabled toolsets as string slice
toolsetIDs
:=
inv
.
ToolsetIDs
()
toolsetIDStrs
:=
make
([]
string
,
len
(
toolsetIDs
))
for
i
,
id
:=
range
toolsetIDs
{
toolsetIDStrs
[
i
]
=
string
(
id
)
}
return
ScopesOutput
{
Tools
:
tools
,
UniqueScopes
:
uniqueScopes
,
ScopesByTool
:
scopesByTool
,
ToolsByScope
:
toolsByScope
,
EnabledToolsets
:
toolsetIDStrs
,
ReadOnly
:
readOnly
,
}
}
func
outputJSON
(
output
ScopesOutput
)
error
{
encoder
:=
json
.
NewEncoder
(
os
.
Stdout
)
encoder
.
SetIndent
(
""
,
" "
)
return
encoder
.
Encode
(
output
)
}
func
outputSummary
(
output
ScopesOutput
)
error
{
if
len
(
output
.
UniqueScopes
)
==
0
{
fmt
.
Println
(
"No OAuth scopes required for enabled tools."
)
return
nil
}
fmt
.
Println
(
"OAuth scope policies for enabled tools:"
)
fmt
.
Println
()
for
_
,
scope
:=
range
output
.
UniqueScopes
{
fmt
.
Printf
(
" %s
\n
"
,
formatScopeDisplay
(
scope
))
}
fmt
.
Printf
(
"
\n
Total: %d unique scope(s)
\n
"
,
len
(
output
.
UniqueScopes
))
return
nil
}
func
outputText
(
output
ScopesOutput
)
error
{
fmt
.
Printf
(
"OAuth Challenge Scopes for Enabled Tools
\n
"
)
fmt
.
Printf
(
"========================================
\n
\n
"
)
fmt
.
Printf
(
"Enabled Toolsets: %s
\n
"
,
strings
.
Join
(
output
.
EnabledToolsets
,
", "
))
fmt
.
Printf
(
"Read-Only Mode: %v
\n
\n
"
,
output
.
ReadOnly
)
// Group tools by toolset
toolsByToolset
:=
make
(
map
[
string
][]
ToolScopeInfo
)
for
_
,
tool
:=
range
output
.
Tools
{
toolsByToolset
[
tool
.
Toolset
]
=
append
(
toolsByToolset
[
tool
.
Toolset
],
tool
)
}
// Get sorted toolset names
var
toolsetNames
[]
string
for
name
:=
range
toolsByToolset
{
toolsetNames
=
append
(
toolsetNames
,
name
)
}
sort
.
Strings
(
toolsetNames
)
for
_
,
toolsetName
:=
range
toolsetNames
{
tools
:=
toolsByToolset
[
toolsetName
]
fmt
.
Printf
(
"## %s
\n
\n
"
,
formatToolsetName
(
toolsetName
))
for
_
,
tool
:=
range
tools
{
rwIndicator
:=
"📝"
if
tool
.
ReadOnly
{
rwIndicator
=
"👁"
}
scopeStr
:=
"(no scope required)"
if
len
(
tool
.
ChallengeScopes
)
>
0
{
scopeStr
=
strings
.
Join
(
tool
.
ChallengeScopes
,
", "
)
}
fmt
.
Printf
(
" %s %s: %s
\n
"
,
rwIndicator
,
tool
.
Name
,
scopeStr
)
}
fmt
.
Println
()
}
// Summary
fmt
.
Println
(
"## Summary"
)
fmt
.
Println
()
if
len
(
output
.
UniqueScopes
)
==
0
{
fmt
.
Println
(
"No OAuth scopes are used by enabled tools."
)
}
else
{
fmt
.
Println
(
"Unique challenge scopes:"
)
for
_
,
scope
:=
range
output
.
UniqueScopes
{
fmt
.
Printf
(
" • %s
\n
"
,
formatScopeDisplay
(
scope
))
}
}
fmt
.
Printf
(
"
\n
Total: %d tools, %d unique scopes
\n
"
,
len
(
output
.
Tools
),
len
(
output
.
UniqueScopes
))
// Legend
fmt
.
Println
(
"
\n
Legend: 👁 = read-only, 📝 = read-write"
)
return
nil
}
You can’t perform that action at this time.