1- package github_test
1+ package github
22
33import (
44 "context"
55 "encoding/json"
66 "testing"
77
8- "github.com/github/github-mcp-server/pkg/github"
98 "github.com/github/github-mcp-server/pkg/translations"
109 "github.com/modelcontextprotocol/go-sdk/mcp"
1110 "github.com/stretchr/testify/assert"
1211 "github.com/stretchr/testify/require"
12+
13+ "github.com/github/github-mcp-server/pkg/inventory"
14+ "github.com/github/github-mcp-server/pkg/scopes"
15+ "github.com/github/github-mcp-server/pkg/utils"
16+ "github.com/google/jsonschema-go/jsonschema"
1317)
1418
19+ // RemoteMCPExperimental is a long-lived feature flag for experimental remote MCP features.
20+ // This flag enables experimental behaviors in tools that are being tested for remote server deployment.
21+ const RemoteMCPEnthusiasticGreeting = "remote_mcp_enthusiastic_greeting"
22+
23+ // HelloWorld returns a simple greeting tool that demonstrates feature flag conditional behavior.
24+ // This tool is for testing and demonstration purposes only.
25+ func HelloWorld (t translations.TranslationHelperFunc ) inventory.ServerTool {
26+ return NewTool (
27+ ToolsetMetadataContext , // Use existing "context" toolset
28+ mcp.Tool {
29+ Name : "hello_world" ,
30+ Description : t ("TOOL_HELLO_WORLD_DESCRIPTION" , "A simple greeting tool that demonstrates feature flag conditional behavior" ),
31+ Annotations : & mcp.ToolAnnotations {
32+ Title : t ("TOOL_HELLO_WORLD_TITLE" , "Hello World" ),
33+ ReadOnlyHint : true ,
34+ },
35+ InputSchema : & jsonschema.Schema {
36+ Type : "object" ,
37+ Properties : map [string ]* jsonschema.Schema {
38+ "name" : {
39+ Type : "string" ,
40+ Description : "Name to greet (optional, defaults to 'World')" ,
41+ },
42+ },
43+ },
44+ },
45+ []scopes.Scope {},
46+ func (ctx context.Context , deps ToolDependencies , _ * mcp.CallToolRequest , args map [string ]any ) (* mcp.CallToolResult , any , error ) {
47+ // Extract name parameter (optional)
48+ name := "World"
49+ if nameArg , ok := args ["name" ].(string ); ok && nameArg != "" {
50+ name = nameArg
51+ }
52+
53+ // Check feature flag to determine greeting style
54+ var greeting string
55+ if deps .IsFeatureEnabled (ctx , RemoteMCPEnthusiasticGreeting ) {
56+ // Experimental: More enthusiastic greeting
57+ greeting = "🚀 Hello, " + name + "! Welcome to the EXPERIMENTAL future of MCP! 🎉"
58+ } else {
59+ // Default: Simple greeting
60+ greeting = "Hello, " + name + "!"
61+ }
62+
63+ // Build response
64+ response := map [string ]any {
65+ "greeting" : greeting ,
66+ "experimental_mode" : deps .IsFeatureEnabled (ctx , RemoteMCPEnthusiasticGreeting ),
67+ "timestamp" : "2026-01-12" , // Static for demonstration
68+ }
69+
70+ jsonBytes , err := json .Marshal (response )
71+ if err != nil {
72+ return utils .NewToolResultError ("failed to marshal response" ), nil , nil
73+ }
74+
75+ return utils .NewToolResultText (string (jsonBytes )), nil , nil
76+ },
77+ )
78+ }
79+
1580func TestHelloWorld_ToolDefinition (t * testing.T ) {
1681 t .Parallel ()
1782
1883 // Create tool
19- tool := github . HelloWorld (translations .NullTranslationHelper )
84+ tool := HelloWorld (translations .NullTranslationHelper )
2085
2186 // Verify tool definition
2287 assert .Equal (t , "hello_world" , tool .Tool .Name )
@@ -68,23 +133,23 @@ func TestHelloWorld_ConditionalBehavior(t *testing.T) {
68133
69134 // Create feature checker based on test case
70135 checker := func (_ context.Context , flagName string ) (bool , error ) {
71- if flagName == github . RemoteMCPExperimental {
136+ if flagName == RemoteMCPEnthusiasticGreeting {
72137 return tt .featureFlagEnabled , nil
73138 }
74139 return false , nil
75140 }
76141
77142 // Create deps with the checker
78- deps := github . NewBaseDeps (
143+ deps := NewBaseDeps (
79144 nil , nil , nil , nil ,
80145 translations .NullTranslationHelper ,
81- github. FeatureFlags {},
146+ FeatureFlags {},
82147 0 ,
83148 checker ,
84149 )
85150
86151 // Get the tool and its handler
87- tool := github . HelloWorld (translations .NullTranslationHelper )
152+ tool := HelloWorld (translations .NullTranslationHelper )
88153 handler := tool .Handler (deps )
89154
90155 // Create request
@@ -102,7 +167,7 @@ func TestHelloWorld_ConditionalBehavior(t *testing.T) {
102167 }
103168
104169 // Call the handler with deps in context
105- ctx := github . ContextWithDeps (context .Background (), deps )
170+ ctx := ContextWithDeps (context .Background (), deps )
106171 result , err := handler (ctx , & request )
107172 require .NoError (t , err )
108173 require .NotNil (t , result )
0 commit comments