@@ -3,6 +3,7 @@ package mcp
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os/exec"
6
7
7
8
"github.com/mark3labs/mcp-go/mcp"
8
9
"github.com/mark3labs/mcp-go/server"
@@ -18,13 +19,51 @@ func NewServer() *MCPServer {
18
19
"1.0.0" ,
19
20
server .WithToolCapabilities (true ),
20
21
)
22
+
21
23
mcpServer .AddTool (
22
24
mcp .NewTool ("healthcheck" ,
23
25
mcp .WithDescription ("Checks if the server is running" ),
24
26
),
25
27
handleHealthCheckTool ,
26
28
)
27
29
30
+ mcpServer .AddTool (
31
+ mcp .NewTool ("create" ,
32
+ mcp .WithDescription ("Creates a knative function in the current directory" ),
33
+ mcp .WithString ("name" ,
34
+ mcp .Required (),
35
+ mcp .Description ("Name of the function to be created" ),
36
+ ),
37
+ mcp .WithString ("language" ,
38
+ mcp .Required (),
39
+ mcp .Description ("Language/Runtime of the function to be created" ),
40
+ ),
41
+ mcp .WithString ("cwd" ,
42
+ mcp .Required (),
43
+ mcp .Description ("Current working directory of the MCP client" ),
44
+ ),
45
+ ),
46
+ handleCreateTool ,
47
+ )
48
+
49
+ mcpServer .AddTool (
50
+ mcp .NewTool ("deploy" ,
51
+ mcp .WithDescription ("Deploys the function to the cluster" ),
52
+ mcp .WithString ("registry" ,
53
+ mcp .Required (),
54
+ mcp .Description ("Name of the registry to be used to push the function image" ),
55
+ ),
56
+ mcp .WithString ("cwd" ,
57
+ mcp .Required (),
58
+ mcp .Description ("Full path of the function to be deployed" ),
59
+ ),
60
+ mcp .WithString ("builder" ,
61
+ mcp .Required (),
62
+ mcp .Description ("Builder to be used to build the function image" ),
63
+ ),
64
+ ),
65
+ handleDeployTool ,
66
+ )
28
67
return & MCPServer {
29
68
server : mcpServer ,
30
69
}
@@ -41,3 +80,56 @@ func handleHealthCheckTool(
41
80
body := []byte (fmt .Sprintf (`{"message": "%s"}` , "The MCP server is running!" ))
42
81
return mcp .NewToolResultText (string (body )), nil
43
82
}
83
+
84
+ func handleCreateTool (
85
+ ctx context.Context ,
86
+ request mcp.CallToolRequest ,
87
+ ) (* mcp.CallToolResult , error ) {
88
+ cwd , err := request .RequireString ("cwd" )
89
+ if err != nil {
90
+ return mcp .NewToolResultError (err .Error ()), nil
91
+ }
92
+ name , err := request .RequireString ("name" )
93
+ if err != nil {
94
+ return mcp .NewToolResultError (err .Error ()), nil
95
+ }
96
+ language , err := request .RequireString ("language" )
97
+ if err != nil {
98
+ return mcp .NewToolResultError (err .Error ()), nil
99
+ }
100
+
101
+ cmd := exec .Command ("func" , "create" , "-l" , language , name )
102
+ cmd .Dir = cwd
103
+ out , err := cmd .Output ()
104
+ if err != nil {
105
+ return mcp .NewToolResultError (err .Error ()), nil
106
+ }
107
+ body := []byte (fmt .Sprintf (`{"result": "%s"}` , out ))
108
+ return mcp .NewToolResultText (string (body )), nil
109
+ }
110
+
111
+ func handleDeployTool (
112
+ ctx context.Context ,
113
+ request mcp.CallToolRequest ,
114
+ ) (* mcp.CallToolResult , error ) {
115
+ cwd , err := request .RequireString ("cwd" )
116
+ if err != nil {
117
+ return mcp .NewToolResultError (err .Error ()), nil
118
+ }
119
+ registry , err := request .RequireString ("registry" )
120
+ if err != nil {
121
+ return mcp .NewToolResultError (err .Error ()), nil
122
+ }
123
+ builder , err := request .RequireString ("builder" )
124
+ if err != nil {
125
+ return mcp .NewToolResultError (err .Error ()), nil
126
+ }
127
+ cmd := exec .Command ("func" , "deploy" , "--registry" , registry , "--builder" , builder )
128
+ cmd .Dir = cwd
129
+ out , err := cmd .Output ()
130
+ if err != nil {
131
+ return mcp .NewToolResultError (err .Error ()), nil
132
+ }
133
+ body := []byte (fmt .Sprintf (`{"result": "%s"}` , out ))
134
+ return mcp .NewToolResultText (string (body )), nil
135
+ }
0 commit comments