Skip to content

Commit 698d885

Browse files
committed
carry over from #1863
1 parent 238b143 commit 698d885

File tree

9 files changed

+341
-298
lines changed

9 files changed

+341
-298
lines changed

internal/ghmcp/server.go

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,31 @@ func NewMCPServer(cfg MCPServerConfig) (*mcp.Server, error) {
171171

172172
enabledToolsets := resolveEnabledToolsets(cfg)
173173

174-
// For instruction generation, we need actual toolset names (not nil).
175-
// nil means "use defaults" in inventory, so expand it for instructions.
176-
instructionToolsets := enabledToolsets
177-
if instructionToolsets == nil {
178-
instructionToolsets = github.GetDefaultToolsetIDs()
174+
// Create feature checker
175+
featureChecker := createFeatureChecker(cfg.EnabledFeatures)
176+
177+
// Build and register the tool/resource/prompt inventory
178+
inventoryBuilder := github.NewInventory(cfg.Translator).
179+
WithDeprecatedAliases(github.DeprecatedToolAliases).
180+
WithReadOnly(cfg.ReadOnly).
181+
WithToolsets(enabledToolsets).
182+
WithTools(cfg.EnabledTools).
183+
WithFeatureChecker(featureChecker).
184+
WithServerInstructions()
185+
186+
// Apply token scope filtering if scopes are known (for PAT filtering)
187+
if cfg.TokenScopes != nil {
188+
inventoryBuilder = inventoryBuilder.WithFilter(github.CreateToolScopeFilter(cfg.TokenScopes))
189+
}
190+
191+
inventory, err := inventoryBuilder.Build()
192+
if err != nil {
193+
return nil, fmt.Errorf("failed to build inventory: %w", err)
179194
}
180195

181196
// Create the MCP server
182197
serverOpts := &mcp.ServerOptions{
183-
Instructions: github.GenerateInstructions(instructionToolsets),
198+
Instructions: inventory.Instructions(),
184199
Logger: cfg.Logger,
185200
CompletionHandler: github.CompletionsHandler(func(_ context.Context) (*gogithub.Client, error) {
186201
return clients.rest, nil
@@ -203,9 +218,6 @@ func NewMCPServer(cfg MCPServerConfig) (*mcp.Server, error) {
203218
ghServer.AddReceivingMiddleware(addGitHubAPIErrorToContext)
204219
ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, clients.rest, clients.gqlHTTP))
205220

206-
// Create feature checker
207-
featureChecker := createFeatureChecker(cfg.EnabledFeatures)
208-
209221
// Create dependencies for tool handlers
210222
deps := github.NewBaseDeps(
211223
clients.rest,
@@ -228,24 +240,6 @@ func NewMCPServer(cfg MCPServerConfig) (*mcp.Server, error) {
228240
}
229241
})
230242

231-
// Build and register the tool/resource/prompt inventory
232-
inventoryBuilder := github.NewInventory(cfg.Translator).
233-
WithDeprecatedAliases(github.DeprecatedToolAliases).
234-
WithReadOnly(cfg.ReadOnly).
235-
WithToolsets(enabledToolsets).
236-
WithTools(cfg.EnabledTools).
237-
WithFeatureChecker(featureChecker)
238-
239-
// Apply token scope filtering if scopes are known (for PAT filtering)
240-
if cfg.TokenScopes != nil {
241-
inventoryBuilder = inventoryBuilder.WithFilter(github.CreateToolScopeFilter(cfg.TokenScopes))
242-
}
243-
244-
inventory, err := inventoryBuilder.Build()
245-
if err != nil {
246-
return nil, fmt.Errorf("failed to build inventory: %w", err)
247-
}
248-
249243
if unrecognized := inventory.UnrecognizedToolsets(); len(unrecognized) > 0 {
250244
fmt.Fprintf(os.Stderr, "Warning: unrecognized toolsets ignored: %s\n", strings.Join(unrecognized, ", "))
251245
}

pkg/github/instructions_test.go

Lines changed: 0 additions & 186 deletions
This file was deleted.

pkg/github/tools.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ var (
2828
Icon: "check-circle",
2929
}
3030
ToolsetMetadataContext = inventory.ToolsetMetadata{
31-
ID: "context",
32-
Description: "Tools that provide context about the current user and GitHub context you are operating in",
33-
Default: true,
34-
Icon: "person",
31+
ID: "context",
32+
Description: "Tools that provide context about the current user and GitHub context you are operating in",
33+
Default: true,
34+
Icon: "person",
35+
InstructionsFunc: generateContextToolsetInstructions,
3536
}
3637
ToolsetMetadataRepos = inventory.ToolsetMetadata{
3738
ID: "repos",
@@ -45,16 +46,18 @@ var (
4546
Icon: "git-branch",
4647
}
4748
ToolsetMetadataIssues = inventory.ToolsetMetadata{
48-
ID: "issues",
49-
Description: "GitHub Issues related tools",
50-
Default: true,
51-
Icon: "issue-opened",
49+
ID: "issues",
50+
Description: "GitHub Issues related tools",
51+
Default: true,
52+
Icon: "issue-opened",
53+
InstructionsFunc: generateIssuesToolsetInstructions,
5254
}
5355
ToolsetMetadataPullRequests = inventory.ToolsetMetadata{
54-
ID: "pull_requests",
55-
Description: "GitHub Pull Request related tools",
56-
Default: true,
57-
Icon: "git-pull-request",
56+
ID: "pull_requests",
57+
Description: "GitHub Pull Request related tools",
58+
Default: true,
59+
Icon: "git-pull-request",
60+
InstructionsFunc: generatePullRequestsToolsetInstructions,
5861
}
5962
ToolsetMetadataUsers = inventory.ToolsetMetadata{
6063
ID: "users",
@@ -93,9 +96,10 @@ var (
9396
Icon: "bell",
9497
}
9598
ToolsetMetadataDiscussions = inventory.ToolsetMetadata{
96-
ID: "discussions",
97-
Description: "GitHub Discussions related tools",
98-
Icon: "comment-discussion",
99+
ID: "discussions",
100+
Description: "GitHub Discussions related tools",
101+
Icon: "comment-discussion",
102+
InstructionsFunc: generateDiscussionsToolsetInstructions,
99103
}
100104
ToolsetMetadataGists = inventory.ToolsetMetadata{
101105
ID: "gists",
@@ -108,9 +112,10 @@ var (
108112
Icon: "shield",
109113
}
110114
ToolsetMetadataProjects = inventory.ToolsetMetadata{
111-
ID: "projects",
112-
Description: "GitHub Projects related tools",
113-
Icon: "project",
115+
ID: "projects",
116+
Description: "GitHub Projects related tools",
117+
Icon: "project",
118+
InstructionsFunc: generateProjectsToolsetInstructions,
114119
}
115120
ToolsetMetadataStargazers = inventory.ToolsetMetadata{
116121
ID: "stargazers",

0 commit comments

Comments
 (0)