Skip to content

Commit 26951b5

Browse files
committed
Add support for disabling instructions via environment variable
1 parent fc3f378 commit 26951b5

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

pkg/github/instructions.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package github
22

3-
import "strings"
3+
import (
4+
"os"
5+
"strings"
6+
)
47

58
// GenerateInstructions creates server instructions based on enabled toolsets
69
func GenerateInstructions(enabledToolsets []string) string {
10+
// For testing - add a flag to disable instructions
11+
if os.Getenv("DISABLE_INSTRUCTIONS") == "true" {
12+
return "" // Baseline mode
13+
}
14+
715
var instructions []string
816

917
// Core instruction - always included if context toolset enabled

pkg/github/instructions_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package github
22

33
import (
4+
"os"
45
"strings"
56
"testing"
67
)
@@ -104,6 +105,79 @@ func TestGenerateInstructions(t *testing.T) {
104105
}
105106
}
106107

108+
func TestGenerateInstructionsWithDisableFlag(t *testing.T) {
109+
tests := []struct {
110+
name string
111+
disableEnvValue string
112+
enabledToolsets []string
113+
expectedEmpty bool
114+
expectedContains []string
115+
}{
116+
{
117+
name: "DISABLE_INSTRUCTIONS=true returns empty",
118+
disableEnvValue: "true",
119+
enabledToolsets: []string{"context", "issues", "pull_requests"},
120+
expectedEmpty: true,
121+
},
122+
{
123+
name: "DISABLE_INSTRUCTIONS=false returns normal instructions",
124+
disableEnvValue: "false",
125+
enabledToolsets: []string{"context"},
126+
expectedEmpty: false,
127+
expectedContains: []string{
128+
"GitHub MCP Server provides GitHub API tools",
129+
"Always call 'get_me' first",
130+
},
131+
},
132+
{
133+
name: "DISABLE_INSTRUCTIONS unset returns normal instructions",
134+
disableEnvValue: "",
135+
enabledToolsets: []string{"issues"},
136+
expectedEmpty: false,
137+
expectedContains: []string{
138+
"GitHub MCP Server provides GitHub API tools",
139+
"search_issues",
140+
},
141+
},
142+
}
143+
144+
for _, tt := range tests {
145+
t.Run(tt.name, func(t *testing.T) {
146+
// Save original env value
147+
originalValue := os.Getenv("DISABLE_INSTRUCTIONS")
148+
defer func() {
149+
if originalValue == "" {
150+
os.Unsetenv("DISABLE_INSTRUCTIONS")
151+
} else {
152+
os.Setenv("DISABLE_INSTRUCTIONS", originalValue)
153+
}
154+
}()
155+
156+
// Set test env value
157+
if tt.disableEnvValue == "" {
158+
os.Unsetenv("DISABLE_INSTRUCTIONS")
159+
} else {
160+
os.Setenv("DISABLE_INSTRUCTIONS", tt.disableEnvValue)
161+
}
162+
163+
result := GenerateInstructions(tt.enabledToolsets)
164+
165+
if tt.expectedEmpty {
166+
if result != "" {
167+
t.Errorf("Expected empty instructions but got: %s", result)
168+
}
169+
return
170+
}
171+
172+
for _, expectedContent := range tt.expectedContains {
173+
if !strings.Contains(result, expectedContent) {
174+
t.Errorf("Expected instructions to contain '%s', but got: %s", expectedContent, result)
175+
}
176+
}
177+
})
178+
}
179+
}
180+
107181
func TestGetToolsetInstructions(t *testing.T) {
108182
tests := []struct {
109183
toolset string

0 commit comments

Comments
 (0)