From e3cf8c2a8db286c824d4685650ee5bd137e2c204 Mon Sep 17 00:00:00 2001 From: "elvandlie@gmail.com" Date: Tue, 12 May 2026 20:36:27 +0700 Subject: [PATCH 1/2] mcp: fix appendBoolFlag to handle explicit false values appendBoolFlag silently dropped the flag when value was non-nil but false. This meant MCP clients could not explicitly disable boolean flags like --push that may be enabled via func.yaml defaults. When value is non-nil and false, append flag=false (e.g. --push=false) to allow explicit disabling. Signed-off-by: elvandlie@gmail.com --- pkg/mcp/tools.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/mcp/tools.go b/pkg/mcp/tools.go index 0d7ed0fc7d..faea25f0d7 100644 --- a/pkg/mcp/tools.go +++ b/pkg/mcp/tools.go @@ -26,11 +26,15 @@ func appendStringFlag(args []string, flag string, value *string) []string { return args } -// appendBoolFlag adds a boolean flag to args only if the value is non-nil and true. -// This ensures we only pass flags that were explicitly provided by the user. +// appendBoolFlag adds a boolean flag to args only if the value is non-nil. +// When true, appends the flag (e.g. --push). When false, appends +// flag=false (e.g. --push=false) to allow explicit disabling. func appendBoolFlag(args []string, flag string, value *bool) []string { - if value != nil && *value { - return append(args, flag) + if value != nil { + if *value { + return append(args, flag) + } + return append(args, flag+"=false") } return args } From af0ff49ca7be444af862423de9cfc0c8998b40e8 Mon Sep 17 00:00:00 2001 From: "elvandlie@gmail.com" Date: Tue, 12 May 2026 21:56:23 +0700 Subject: [PATCH 2/2] mcp: add tests for appendBoolFlag and appendStringFlag helpers Signed-off-by: elvandlie@gmail.com --- pkg/mcp/mcp_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pkg/mcp/mcp_test.go b/pkg/mcp/mcp_test.go index 0f9c21bce0..4fcfc1eb9c 100644 --- a/pkg/mcp/mcp_test.go +++ b/pkg/mcp/mcp_test.go @@ -221,3 +221,63 @@ func TestWithPrefix_Validation(t *testing.T) { }) } } + +// TestAppendBoolFlag verifies that appendBoolFlag handles nil, true, and false correctly. +func TestAppendBoolFlag(t *testing.T) { + trueVal := true + falseVal := false + + cases := []struct { + name string + value *bool + want []string + }{ + {"nil omits flag", nil, []string{}}, + {"true appends flag", &trueVal, []string{"--push"}}, + {"false appends flag=false", &falseVal, []string{"--push=false"}}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := appendBoolFlag(nil, "--push", tc.value) + if len(got) != len(tc.want) { + t.Fatalf("appendBoolFlag(nil, --push, %v) = %v, want %v", tc.value, got, tc.want) + } + for i := range got { + if got[i] != tc.want[i] { + t.Errorf("result[%d] = %q, want %q", i, got[i], tc.want[i]) + } + } + }) + } +} + +// TestAppendStringFlag verifies that appendStringFlag handles nil, empty, and non-empty values. +func TestAppendStringFlag(t *testing.T) { + empty := "" + val := "prod" + + cases := []struct { + name string + value *string + want []string + }{ + {"nil omits flag", nil, []string{}}, + {"empty omits flag", &empty, []string{}}, + {"non-empty appends flag and value", &val, []string{"--namespace", "prod"}}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := appendStringFlag(nil, "--namespace", tc.value) + if len(got) != len(tc.want) { + t.Fatalf("appendStringFlag(nil, --namespace, %v) = %v, want %v", tc.value, got, tc.want) + } + for i := range got { + if got[i] != tc.want[i] { + t.Errorf("result[%d] = %q, want %q", i, got[i], tc.want[i]) + } + } + }) + } +}