HelloWorld returns a simple greeting tool that demonstrates feature flag conditional behavior. This tool is for testing and demonstration purposes only.
(t translations.TranslationHelperFunc)
| 31 | // HelloWorld returns a simple greeting tool that demonstrates feature flag conditional behavior. |
| 32 | // This tool is for testing and demonstration purposes only. |
| 33 | func HelloWorldTool(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 34 | return NewTool( |
| 35 | ToolsetMetadataContext, // Use existing "context" toolset |
| 36 | mcp.Tool{ |
| 37 | Name: "hello_world", |
| 38 | Description: t("TOOL_HELLO_WORLD_DESCRIPTION", "A simple greeting tool that demonstrates feature flag conditional behavior"), |
| 39 | Annotations: &mcp.ToolAnnotations{ |
| 40 | Title: t("TOOL_HELLO_WORLD_TITLE", "Hello World"), |
| 41 | ReadOnlyHint: true, |
| 42 | }, |
| 43 | }, |
| 44 | []scopes.Scope{}, |
| 45 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) { |
| 46 | |
| 47 | // Check feature flag to determine greeting style |
| 48 | greeting := "Hello, world!" |
| 49 | if deps.IsFeatureEnabled(ctx, RemoteMCPEnthusiasticGreeting) { |
| 50 | greeting += " Welcome to the future of MCP! 🎉" |
| 51 | } |
| 52 | |
| 53 | // Build response |
| 54 | response := map[string]any{ |
| 55 | "greeting": greeting, |
| 56 | } |
| 57 | |
| 58 | jsonBytes, err := json.Marshal(response) |
| 59 | if err != nil { |
| 60 | return utils.NewToolResultError("failed to marshal response"), nil, nil |
| 61 | } |
| 62 | |
| 63 | return utils.NewToolResultText(string(jsonBytes)), nil, nil |
| 64 | }, |
| 65 | ) |
| 66 | } |
| 67 | |
| 68 | func TestHelloWorld_ConditionalBehavior_Featureflag(t *testing.T) { |
| 69 | t.Parallel() |
no test coverage detected