Skip to content

Commit 76e9163

Browse files
committed
WIP: adds command for mcp server
Signed-off-by: KapilSareen <[email protected]>
1 parent a062cd2 commit 76e9163

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

cmd/mcp.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/mark3labs/mcp-go/mcp"
8+
"github.com/mark3labs/mcp-go/server"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func NewMCPServerCmd() *cobra.Command {
13+
cmd := &cobra.Command{
14+
Use: "mcp",
15+
Short: "Start MCP server",
16+
Long: `
17+
NAME
18+
{{rootCmdUse}} mcp - start a MCP server
19+
20+
SYNOPSIS
21+
TBD
22+
23+
DESCRIPTION
24+
TBD
25+
26+
EXAMPLES
27+
TBD
28+
`,
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
return runMCPServer(cmd, args)
31+
},
32+
}
33+
return cmd
34+
}
35+
36+
func runMCPServer(cmd *cobra.Command, args []string) error {
37+
fmt.Println("Running MCP server...")
38+
39+
s := server.NewMCPServer(
40+
"func",
41+
"1.0.0",
42+
server.WithToolCapabilities(false),
43+
)
44+
45+
tool := mcp.NewTool("health_check",
46+
mcp.WithDescription("Check the health of the server"),
47+
)
48+
s.AddTool(tool, healthCheckHandler)
49+
50+
if err := server.ServeStdio(s); err != nil {
51+
fmt.Printf("Server error: %v\n", err)
52+
}
53+
return nil
54+
}
55+
56+
func healthCheckHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
57+
return mcp.NewToolResultText(fmt.Sprintf("Hello, MCP server is working!")), nil
58+
}

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{

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ require (
194194
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
195195
github.com/magiconair/properties v1.8.7 // indirect
196196
github.com/mailru/easyjson v0.9.0 // indirect
197+
github.com/mark3labs/mcp-go v0.30.0 // indirect
197198
github.com/mattn/go-colorable v0.1.13 // indirect
198199
github.com/mattn/go-isatty v0.0.20 // indirect
199200
github.com/mattn/go-runewidth v0.0.16 // indirect
@@ -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 & 0 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=
@@ -1006,6 +1008,8 @@ github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNo
10061008
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
10071009
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
10081010
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
1011+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
1012+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
10091013
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
10101014
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
10111015
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
@@ -1106,6 +1110,8 @@ github.com/xhit/go-str2duration v1.2.0/go.mod h1:3cPSlfZlUHVlneIVfePFWcJZsuwf+P1
11061110
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
11071111
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
11081112
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
1113+
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
1114+
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
11091115
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
11101116
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
11111117
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

0 commit comments

Comments
 (0)