Skip to content

Commit 133aa11

Browse files
committed
mcp: adds func mcp command
Signed-off-by: KapilSareen <[email protected]>
1 parent a062cd2 commit 133aa11

File tree

7 files changed

+146
-3
lines changed

7 files changed

+146
-3
lines changed

cmd/mcp.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cmd
2+
3+
import (
4+
"log"
5+
6+
"github.com/spf13/cobra"
7+
"knative.dev/func/pkg/mcp"
8+
)
9+
10+
func NewMCPServerCmd() *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "mcp",
13+
Short: "Start MCP server",
14+
Long: `
15+
NAME
16+
{{rootCmdUse}} mcp - start a Model Context Protocol (MCP) server
17+
18+
SYNOPSIS
19+
{{rootCmdUse}} mcp [flags]
20+
21+
DESCRIPTION
22+
Starts a Model Context Protocol (MCP) server over standard input/output (stdio) transport.
23+
This implementation aims to support tools for deploying and creating serverless functions.
24+
25+
Note: This command is still under development.
26+
27+
EXAMPLES
28+
29+
30+
o Run an MCP server:
31+
{{rootCmdUse}} mcp
32+
`,
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
return runMCPServer(cmd, args)
35+
},
36+
}
37+
return cmd
38+
}
39+
40+
func runMCPServer(cmd *cobra.Command, args []string) error {
41+
s := mcp.NewServer()
42+
if err := s.Start(); err != nil {
43+
log.Fatalf("Server error: %v", err)
44+
return err
45+
}
46+
return nil
47+
}

cmd/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ Learn more about Knative at: https://knative.dev`, cfg.Name),
107107
NewEnvironmentCmd(newClient, &cfg.Version),
108108
},
109109
},
110+
{
111+
Header: "MCP Commands:",
112+
Commands: []*cobra.Command{
113+
NewMCPServerCmd(),
114+
},
115+
},
110116
{
111117
Header: "Other Commands:",
112118
Commands: []*cobra.Command{

docs/reference/func.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Learn more about Knative at: https://knative.dev
3434
* [func invoke](func_invoke.md) - Invoke a local or remote function
3535
* [func languages](func_languages.md) - List available function language runtimes
3636
* [func list](func_list.md) - List deployed functions
37+
* [func mcp](func_mcp.md) - Start MCP server
3738
* [func repository](func_repository.md) - Manage installed template repositories
3839
* [func run](func_run.md) - Run the function locally
3940
* [func subscribe](func_subscribe.md) - Subscribe a function to events

docs/reference/func_mcp.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## func mcp
2+
3+
Start MCP server
4+
5+
### Synopsis
6+
7+
8+
NAME
9+
func mcp - start a Model Context Protocol (MCP) server
10+
11+
SYNOPSIS
12+
func mcp [flags]
13+
14+
DESCRIPTION
15+
Starts a Model Context Protocol (MCP) server over standard input/output (stdio) transport.
16+
This implementation aims to support tools for deploying and creating serverless functions.
17+
18+
Note: This command is still under development.
19+
20+
EXAMPLES
21+
22+
23+
o Run an MCP server:
24+
func mcp
25+
26+
27+
```
28+
func mcp
29+
```
30+
31+
### Options
32+
33+
```
34+
-h, --help help for mcp
35+
```
36+
37+
### SEE ALSO
38+
39+
* [func](func.md) - func manages Knative Functions
40+

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ require (
3434
github.com/hinshun/vt10x v0.0.0-20220228203356-1ab2cad5fd82
3535
github.com/manifestival/client-go-client v0.6.0
3636
github.com/manifestival/manifestival v0.7.2
37+
github.com/mark3labs/mcp-go v0.30.0
3738
github.com/opencontainers/image-spec v1.1.0
3839
github.com/openshift-pipelines/pipelines-as-code v0.31.0
3940
github.com/openshift/source-to-image v1.5.0
@@ -246,7 +247,7 @@ require (
246247
github.com/skeema/knownhosts v1.3.0 // indirect
247248
github.com/sourcegraph/conc v0.3.0 // indirect
248249
github.com/spf13/afero v1.11.0 // indirect
249-
github.com/spf13/cast v1.6.0 // indirect
250+
github.com/spf13/cast v1.7.1 // indirect
250251
github.com/spf13/jwalterweatherman v1.1.0 // indirect
251252
github.com/spf13/viper v1.18.2 // indirect
252253
github.com/stoewer/go-strcase v1.3.0 // indirect
@@ -264,6 +265,7 @@ require (
264265
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
265266
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
266267
github.com/xlab/treeprint v1.2.0 // indirect
268+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
267269
go.opencensus.io v0.24.0 // indirect
268270
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
269271
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ github.com/manifestival/client-go-client v0.6.0/go.mod h1:2x6VHJ9/2It3TknttgiDgr
717717
github.com/manifestival/manifestival v0.7.1/go.mod h1:nl3T6HlfHCeidooWVTMI9vYNTBkQ1GdhLNb+smozbdk=
718718
github.com/manifestival/manifestival v0.7.2 h1:l4uFdWX/xQK4QcRfqGoMtBvaZeWPEuwD6hVsCwUqZY4=
719719
github.com/manifestival/manifestival v0.7.2/go.mod h1:nl3T6HlfHCeidooWVTMI9vYNTBkQ1GdhLNb+smozbdk=
720+
github.com/mark3labs/mcp-go v0.30.0 h1:Taz7fiefkxY/l8jz1nA90V+WdM2eoMtlvwfWforVYbo=
721+
github.com/mark3labs/mcp-go v0.30.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
720722
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
721723
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
722724
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
@@ -1004,8 +1006,8 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
10041006
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
10051007
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
10061008
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
1007-
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
1008-
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
1009+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
1010+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
10091011
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
10101012
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
10111013
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
@@ -1106,6 +1108,8 @@ github.com/xhit/go-str2duration v1.2.0/go.mod h1:3cPSlfZlUHVlneIVfePFWcJZsuwf+P1
11061108
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
11071109
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
11081110
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
1111+
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
1112+
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
11091113
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
11101114
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
11111115
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

pkg/mcp/mcp.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package mcp
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/mark3labs/mcp-go/mcp"
8+
"github.com/mark3labs/mcp-go/server"
9+
)
10+
11+
type MCPServer struct {
12+
server *server.MCPServer
13+
}
14+
15+
func NewServer() *MCPServer {
16+
mcpServer := server.NewMCPServer(
17+
"func-mcp",
18+
"1.0.0",
19+
server.WithToolCapabilities(true),
20+
)
21+
mcpServer.AddTool(
22+
mcp.NewTool("healthcheck",
23+
mcp.WithDescription("Checks if the server is running"),
24+
),
25+
handleHealthCheckTool,
26+
)
27+
28+
return &MCPServer{
29+
server: mcpServer,
30+
}
31+
}
32+
33+
func (s *MCPServer) Start() error {
34+
return server.ServeStdio(s.server)
35+
}
36+
37+
func handleHealthCheckTool(
38+
ctx context.Context,
39+
request mcp.CallToolRequest,
40+
) (*mcp.CallToolResult, error) {
41+
body := []byte(fmt.Sprintf(`{"message": "%s"}`, "The MCP server is running!"))
42+
return mcp.NewToolResultText(string(body)), nil
43+
}

0 commit comments

Comments
 (0)