Skip to content

Commit 327e404

Browse files
authored
mcp: adds delete tool and adds remote flag to deploy tool (knative#2863)
* rebases * adds remote flag to deploy tool Signed-off-by: kapil <[email protected]> --------- Signed-off-by: kapil <[email protected]>
1 parent 824911c commit 327e404

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

pkg/mcp/mcp.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func NewServer() *MCPServer {
6161
mcp.Required(),
6262
mcp.Description("Builder to be used to build the function image"),
6363
),
64+
mcp.WithBoolean("remote",
65+
mcp.DefaultBool(false),
66+
mcp.Description("If true, the function will be deployed remotely"),
67+
),
6468
),
6569
handleDeployTool,
6670
)
@@ -91,6 +95,17 @@ func NewServer() *MCPServer {
9195
handleBuildTool,
9296
)
9397

98+
mcpServer.AddTool(
99+
mcp.NewTool("delete",
100+
mcp.WithDescription("Deletes a function from the cluster"),
101+
mcp.WithString("name",
102+
mcp.Required(),
103+
mcp.Description("Name of the function to be deleted"),
104+
),
105+
),
106+
handleDeleteTool,
107+
)
108+
94109
mcpServer.AddResource(mcp.NewResource(
95110
"func://docs",
96111
"Root Help Command",
@@ -196,7 +211,16 @@ func handleDeployTool(
196211
if err != nil {
197212
return mcp.NewToolResultError(err.Error()), nil
198213
}
199-
cmd := exec.Command("func", "deploy", "--registry", registry, "--builder", builder)
214+
remote, err := request.RequireBool("remote")
215+
if err != nil {
216+
return mcp.NewToolResultError(err.Error()), nil
217+
}
218+
var cmd *exec.Cmd
219+
if remote {
220+
cmd = exec.Command("func", "deploy", "--registry", registry, "--builder", builder, "--remote")
221+
} else {
222+
cmd = exec.Command("func", "deploy", "--registry", registry, "--builder", builder)
223+
}
200224
cmd.Dir = cwd
201225
out, err := cmd.Output()
202226
if err != nil {
@@ -245,3 +269,20 @@ func handleBuildTool(
245269
body := []byte(fmt.Sprintf(`{"result": "%s"}`, out))
246270
return mcp.NewToolResultText(string(body)), nil
247271
}
272+
273+
func handleDeleteTool(
274+
ctx context.Context,
275+
request mcp.CallToolRequest,
276+
) (*mcp.CallToolResult, error) {
277+
name, err := request.RequireString("name")
278+
if err != nil {
279+
return mcp.NewToolResultError(err.Error()), nil
280+
}
281+
cmd := exec.Command("func", "delete", name)
282+
out, err := cmd.Output()
283+
if err != nil {
284+
return mcp.NewToolResultError(err.Error()), nil
285+
}
286+
body := []byte(fmt.Sprintf(`{"result": "%s"}`, out))
287+
return mcp.NewToolResultText(string(body)), nil
288+
}

0 commit comments

Comments
 (0)