-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
103 lines (93 loc) · 2.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"os"
"github.com/strowk/mcp-k8s-go/internal/k8s"
"github.com/strowk/mcp-k8s-go/internal/prompts"
"github.com/strowk/mcp-k8s-go/internal/resources"
"github.com/strowk/mcp-k8s-go/internal/tools"
"github.com/strowk/mcp-k8s-go/internal/utils"
"github.com/strowk/foxy-contexts/pkg/app"
"github.com/strowk/foxy-contexts/pkg/mcp"
"github.com/strowk/foxy-contexts/pkg/stdio"
"go.uber.org/fx"
"go.uber.org/fx/fxevent"
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func getCapabilities() *mcp.ServerCapabilities {
return &mcp.ServerCapabilities{
Resources: &mcp.ServerCapabilitiesResources{
ListChanged: utils.Ptr(false),
Subscribe: utils.Ptr(false),
},
Prompts: &mcp.ServerCapabilitiesPrompts{
ListChanged: utils.Ptr(false),
},
}
}
func getImplementation() *mcp.Implementation {
return &mcp.Implementation{
Name: "mcp-k8s-go",
Version: "0.0.1",
}
}
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
if len(os.Args) > 1 {
if os.Args[1] == "--version" {
println(version)
}
if os.Args[1] == "version" {
println("Version: ", version)
println("Commit: ", commit)
println("Date: ", date)
}
return
}
app.
NewFoxyApp().
WithFxOptions(
fx.Provide(func() clientcmd.ClientConfig {
return k8s.GetKubeConfig()
}),
fx.Provide(func() (*kubernetes.Clientset, error) {
return k8s.GetKubeClientset()
}),
fx.Provide(func() k8s.ClientPool {
return k8s.NewClientPool()
}),
).
WithTool(tools.NewPodLogsTool).
WithTool(tools.NewListContextsTool).
WithTool(tools.NewListNamespacesTool).
WithTool(tools.NewListEventsTool).
WithTool(tools.NewListPodsTool).
WithTool(tools.NewListServicesTool).
WithPrompt(prompts.NewListPodsPrompt).
WithPrompt(prompts.NewListNamespacesPrompt).
WithResourceProvider(resources.NewContextsResourceProvider).
WithServerCapabilities(getCapabilities()).
// setting up server
WithName("mcp-k8s-go").
WithVersion("0.0.1").
WithTransport(stdio.NewTransport()).
// Configuring fx logging to only show errors
WithFxOptions(
fx.Provide(func() *zap.Logger {
cfg := zap.NewDevelopmentConfig()
cfg.Level.SetLevel(zap.ErrorLevel)
logger, _ := cfg.Build()
return logger
}),
fx.Option(fx.WithLogger(
func(logger *zap.Logger) fxevent.Logger {
return &fxevent.ZapLogger{Logger: logger}
},
)),
).Run()
}