Skip to content

Commit 38f804e

Browse files
authored
fix: MCP use "kn func" not "func" cmd (#1380)
Signed-off-by: Matej Vašek <[email protected]>
1 parent 5036ed5 commit 38f804e

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

pkg/mcp/help.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9-
"os/exec"
109
"strings"
1110

1211
"github.com/mark3labs/mcp-go/mcp"
@@ -72,7 +71,7 @@ func parseGitHubURL(url string) (owner, repo string) {
7271
}
7372

7473
func handleRootHelpResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
75-
content, err := exec.Command("func", "--help").Output()
74+
content, err := funcCmd("--help").Output()
7675
if err != nil {
7776
return nil, err
7877
}
@@ -88,7 +87,7 @@ func handleRootHelpResource(ctx context.Context, request mcp.ReadResourceRequest
8887

8988
func runHelpCommand(args []string, uri string) ([]mcp.ResourceContents, error) {
9089
args = append(args, "--help")
91-
content, err := exec.Command("func", args...).Output()
90+
content, err := funcCmd(args...).Output()
9291
if err != nil {
9392
return nil, err
9493
}

pkg/mcp/tools.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func handleCreateTool(
5252
// `name` is passed as a positional argument (directory to create in)
5353
args = append(args, name)
5454

55-
cmd := exec.Command("func", args...)
55+
cmd := funcCmd(args...)
5656
cmd.Dir = cwd
5757

5858
out, err := cmd.CombinedOutput()
@@ -143,7 +143,7 @@ func handleDeployTool(
143143
args = append(args, "--remote")
144144
}
145145

146-
cmd := exec.Command("func", args...)
146+
cmd := funcCmd(args...)
147147
cmd.Dir = cwd
148148
out, err := cmd.CombinedOutput()
149149
if err != nil {
@@ -173,7 +173,7 @@ func handleListTool(
173173
args = append(args, "--verbose")
174174
}
175175

176-
cmd := exec.Command("func", args...)
176+
cmd := funcCmd(args...)
177177
out, err := cmd.CombinedOutput()
178178
if err != nil {
179179
return mcp.NewToolResultError(fmt.Sprintf("func list failed: %s", out)), nil
@@ -231,7 +231,7 @@ func handleBuildTool(
231231
args = append(args, "--build-timestamp")
232232
}
233233

234-
cmd := exec.Command("func", args...)
234+
cmd := funcCmd(args...)
235235
cmd.Dir = cwd
236236
out, err := cmd.CombinedOutput()
237237
if err != nil {
@@ -270,7 +270,7 @@ func handleDeleteTool(
270270
args = append(args, "--verbose")
271271
}
272272

273-
cmd := exec.Command("func", args...)
273+
cmd := funcCmd(args...)
274274
out, err := cmd.CombinedOutput()
275275
if err != nil {
276276
return mcp.NewToolResultError(fmt.Sprintf("func delete failed: %s", out)), nil
@@ -298,7 +298,7 @@ func handleConfigVolumesTool(
298298
args = append(args, "--verbose")
299299
}
300300

301-
cmd := exec.Command("func", args...)
301+
cmd := funcCmd(args...)
302302
out, err := cmd.CombinedOutput()
303303
if err != nil {
304304
return mcp.NewToolResultError(fmt.Sprintf("func config volumes list failed: %s", out)), nil
@@ -339,7 +339,7 @@ func handleConfigVolumesTool(
339339
args = append(args, "--verbose")
340340
}
341341

342-
cmd := exec.Command("func", args...)
342+
cmd := funcCmd(args...)
343343
out, err := cmd.CombinedOutput()
344344
if err != nil {
345345
return mcp.NewToolResultError(fmt.Sprintf("func config volumes failed: %s", out)), nil
@@ -368,7 +368,7 @@ func handleConfigLabelsTool(
368368
args = append(args, "--verbose")
369369
}
370370

371-
cmd := exec.Command("func", args...)
371+
cmd := funcCmd(args...)
372372
out, err := cmd.CombinedOutput()
373373
if err != nil {
374374
return mcp.NewToolResultError(fmt.Sprintf("func config labels list failed: %s", out)), nil
@@ -390,7 +390,7 @@ func handleConfigLabelsTool(
390390
args = append(args, "--verbose")
391391
}
392392

393-
cmd := exec.Command("func", args...)
393+
cmd := funcCmd(args...)
394394
out, err := cmd.CombinedOutput()
395395
if err != nil {
396396
return mcp.NewToolResultError(fmt.Sprintf("func config labels %s failed: %s", action, out)), nil
@@ -420,7 +420,7 @@ func handleConfigEnvsTool(
420420
args = append(args, "--verbose")
421421
}
422422

423-
cmd := exec.Command("func", args...)
423+
cmd := funcCmd(args...)
424424
out, err := cmd.CombinedOutput()
425425
if err != nil {
426426
return mcp.NewToolResultError(fmt.Sprintf("func config envs list failed: %s", out)), nil
@@ -443,7 +443,7 @@ func handleConfigEnvsTool(
443443
args = append(args, "--verbose")
444444
}
445445

446-
cmd := exec.Command("func", args...)
446+
cmd := funcCmd(args...)
447447
out, err := cmd.CombinedOutput()
448448
if err != nil {
449449
return mcp.NewToolResultError(fmt.Sprintf("func config envs %s failed: %s", action, out)), nil
@@ -452,3 +452,10 @@ func handleConfigEnvsTool(
452452
body := []byte(fmt.Sprintf(`{"result": "%s"}`, out))
453453
return mcp.NewToolResultText(string(body)), nil
454454
}
455+
456+
func funcCmd(arg ...string) *exec.Cmd {
457+
a := make([]string, 1, len(arg)+1)
458+
a[0] = "func"
459+
a = append(a, arg...)
460+
return exec.Command("kn", a...)
461+
}

0 commit comments

Comments
 (0)