MCPcopy Index your code
hub / github.com/github/github-mcp-server / collectToolScopes

Function collectToolScopes

cmd/github-mcp-server/list_scopes.go:143–214  ·  view source on GitHub ↗
(inv *inventory.Inventory, readOnly bool)

Source from the content-addressed store, hash-verified

141}
142
143func collectToolScopes(inv *inventory.Inventory, readOnly bool) ScopesOutput {
144 var tools []ToolScopeInfo
145 scopeSet := make(map[string]bool)
146 scopesByTool := make(map[string][]string)
147 toolsByScope := make(map[string][]string)
148
149 // Get all available tools from the inventory
150 // Use context.Background() for feature flag evaluation
151 availableTools := inv.AvailableTools(context.Background())
152
153 for _, serverTool := range availableTools {
154 tool := serverTool.Tool
155
156 // Get scope information directly from ServerTool
157 requiredScopes := serverTool.RequiredScopes
158 acceptedScopes := serverTool.AcceptedScopes
159
160 // Determine if tool is read-only
161 isReadOnly := serverTool.IsReadOnly()
162
163 toolInfo := ToolScopeInfo{
164 Name: tool.Name,
165 Toolset: string(serverTool.Toolset.ID),
166 ReadOnly: isReadOnly,
167 RequiredScopes: requiredScopes,
168 AcceptedScopes: acceptedScopes,
169 }
170 tools = append(tools, toolInfo)
171
172 // Track unique scopes
173 for _, s := range requiredScopes {
174 scopeSet[s] = true
175 toolsByScope[s] = append(toolsByScope[s], tool.Name)
176 }
177
178 // Track scopes by tool
179 scopesByTool[tool.Name] = requiredScopes
180 }
181
182 // Sort tools by name
183 sort.Slice(tools, func(i, j int) bool {
184 return tools[i].Name < tools[j].Name
185 })
186
187 // Get unique scopes as sorted slice
188 var uniqueScopes []string
189 for s := range scopeSet {
190 uniqueScopes = append(uniqueScopes, s)
191 }
192 sort.Strings(uniqueScopes)
193
194 // Sort tools within each scope
195 for scope := range toolsByScope {
196 sort.Strings(toolsByScope[scope])
197 }
198
199 // Get enabled toolsets as string slice
200 toolsetIDs := inv.ToolsetIDs()

Callers 1

runListScopesFunction · 0.85

Calls 3

AvailableToolsMethod · 0.80
IsReadOnlyMethod · 0.80
ToolsetIDsMethod · 0.80

Tested by

no test coverage detected