Skip to content

Commit c304637

Browse files
olaservoalmaleksia
authored andcommitted
Refactor instruction generation to always include base and context management instructions
1 parent 5ec44fb commit c304637

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

internal/ghmcp/server.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
118118

119119
// Generate instructions based on enabled toolsets
120120
instructions := github.GenerateInstructions(enabledToolsets)
121-
var serverOpts []server.ServerOption
122-
if instructions != "" {
123-
serverOpts = append(serverOpts, server.WithInstructions(instructions))
124-
}
125-
serverOpts = append(serverOpts, server.WithHooks(hooks))
126-
127-
ghServer := github.NewServer(cfg.Version, serverOpts...)
121+
122+
ghServer := github.NewServer(cfg.Version,
123+
server.WithInstructions(instructions),
124+
server.WithHooks(hooks),
125+
)
128126

129127
getClient := func(_ context.Context) (*gogithub.Client, error) {
130128
return restClient, nil // closing over client

pkg/github/instructions.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ func GenerateInstructions(enabledToolsets []string) string {
3535
instructions = append(instructions, "For repository operations: Check workflow status before major changes using 'list_workflow_runs'.")
3636
}
3737

38-
// Only add base instruction if we have specific instructions
39-
if len(instructions) > 0 {
40-
baseInstruction := "GitHub MCP Server provides GitHub API tools. Common parameters: 'owner' (repo owner), 'repo' (repo name), 'page'/'perPage' (pagination)."
41-
instructions = append([]string{baseInstruction}, instructions...)
42-
}
38+
// Always add base instructions - they provide universal value
39+
baseInstruction := "GitHub MCP Server provides GitHub API tools. Common parameters: 'owner' (repo owner), 'repo' (repo name), 'page'/'perPage' (pagination)."
40+
41+
// Add context management instruction for all configurations
42+
contextInstruction := "GitHub API responses can overflow context windows. Strategy: 1) Always prefer 'search_*' tools over 'list_*' tools when possible - search tools return filtered results, 2) Process large datasets in batches rather than all at once, 3) For summarization tasks, fetch minimal data first, then drill down into specifics, 4) When analyzing multiple items (issues, PRs, etc), process in groups of 5-10 to manage context."
43+
44+
allInstructions := []string{baseInstruction, contextInstruction}
45+
allInstructions = append(allInstructions, instructions...)
4346

44-
return strings.Join(instructions, " ")
47+
return strings.Join(allInstructions, " ")
4548
}
4649

4750
// getToolsetInstructions returns specific instructions for individual toolsets

pkg/github/instructions_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ func TestGenerateInstructions(t *testing.T) {
1515
{
1616
name: "empty toolsets",
1717
enabledToolsets: []string{},
18-
expectedEmpty: true,
18+
expectedContains: []string{
19+
"GitHub MCP Server provides GitHub API tools",
20+
"prefer 'search_*' tools over 'list_*' tools",
21+
"context windows",
22+
},
1923
},
2024
{
2125
name: "only context toolset",

0 commit comments

Comments
 (0)