Skip to content

Commit 90ed242

Browse files
authored
mcp: adds list tool (knative#2861)
Signed-off-by: kapil <[email protected]>
1 parent e5b34ec commit 90ed242

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/mcp/mcp.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ func NewServer() *MCPServer {
6464
),
6565
handleDeployTool,
6666
)
67+
68+
mcpServer.AddTool(
69+
mcp.NewTool("list",
70+
mcp.WithDescription("Lists all the functions deployed in the cluster"),
71+
),
72+
handleListTool,
73+
)
74+
6775
return &MCPServer{
6876
server: mcpServer,
6977
}
@@ -133,3 +141,16 @@ func handleDeployTool(
133141
body := []byte(fmt.Sprintf(`{"result": "%s"}`, out))
134142
return mcp.NewToolResultText(string(body)), nil
135143
}
144+
145+
func handleListTool(
146+
ctx context.Context,
147+
request mcp.CallToolRequest,
148+
) (*mcp.CallToolResult, error) {
149+
cmd := exec.Command("func", "list")
150+
out, err := cmd.Output()
151+
if err != nil {
152+
return mcp.NewToolResultError(err.Error()), nil
153+
}
154+
body := []byte(fmt.Sprintf(`{"result": "%s"}`, out))
155+
return mcp.NewToolResultText(string(body)), nil
156+
}

0 commit comments

Comments
 (0)