Skip to content

Commit 5baebfc

Browse files
committed
refactor: use new AddTools method
1 parent f80a363 commit 5baebfc

File tree

4 files changed

+99
-133
lines changed

4 files changed

+99
-133
lines changed

pkg/mcp/configuration.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"fmt"
66
"github.com/manusa/kubernetes-mcp-server/pkg/kubernetes"
77
"github.com/mark3labs/mcp-go/mcp"
8+
"github.com/mark3labs/mcp-go/server"
89
)
910

10-
func (s *Server) initConfiguration() {
11-
s.server.AddTool(mcp.NewTool(
12-
"configuration_view",
13-
mcp.WithDescription("Get the current Kubernetes configuration content as a kubeconfig YAML"),
14-
), configurationView)
11+
func (s *Server) initConfiguration() []server.ServerTool {
12+
return []server.ServerTool{
13+
{mcp.NewTool("configuration_view",
14+
mcp.WithDescription("Get the current Kubernetes configuration content as a kubeconfig YAML"),
15+
), configurationView},
16+
}
1517
}
1618

1719
func configurationView(_ context.Context, _ mcp.CallToolRequest) (*mcp.CallToolResult, error) {

pkg/mcp/mcp.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/manusa/kubernetes-mcp-server/pkg/version"
66
"github.com/mark3labs/mcp-go/mcp"
77
"github.com/mark3labs/mcp-go/server"
8+
"slices"
89
)
910

1011
type Server struct {
@@ -25,9 +26,11 @@ func NewSever() (*Server, error) {
2526
if err := s.reloadKubernetesClient(); err != nil {
2627
return nil, err
2728
}
28-
s.initConfiguration()
29-
s.initPods()
30-
s.initResources()
29+
s.server.AddTools(slices.Concat(
30+
s.initConfiguration(),
31+
s.initPods(),
32+
s.initResources(),
33+
)...)
3134
return s, nil
3235
}
3336

pkg/mcp/pods.go

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,41 @@ import (
55
"errors"
66
"fmt"
77
"github.com/mark3labs/mcp-go/mcp"
8+
"github.com/mark3labs/mcp-go/server"
89
)
910

10-
func (s *Server) initPods() {
11-
s.server.AddTool(mcp.NewTool(
12-
"pods_list",
13-
mcp.WithDescription("List all the Kubernetes pods in the current cluster from all namespaces"),
14-
), s.podsListInAllNamespaces)
15-
s.server.AddTool(mcp.NewTool(
16-
"pods_list_in_namespace",
17-
mcp.WithDescription("List all the Kubernetes pods in the specified namespace in the current cluster"),
18-
mcp.WithString("namespace",
19-
mcp.Description("Namespace to list pods from"),
20-
mcp.Required(),
21-
),
22-
), s.podsListInNamespace)
23-
s.server.AddTool(mcp.NewTool(
24-
"pods_get",
25-
mcp.WithDescription("Get a Kubernetes Pod in the current or provided namespace with the provided name"),
26-
mcp.WithString("namespace",
27-
mcp.Description("Namespace to get the Pod from"),
28-
),
29-
mcp.WithString("name",
30-
mcp.Description("Name of the Pod"),
31-
mcp.Required(),
32-
),
33-
), s.podsGet)
34-
s.server.AddTool(mcp.NewTool(
35-
"pods_delete",
36-
mcp.WithDescription("Delete a Kubernetes Pod in the current or provided namespace with the provided name"),
37-
mcp.WithString("namespace",
38-
mcp.Description("Namespace to delete the Pod from"),
39-
),
40-
mcp.WithString("name",
41-
mcp.Description("Name of the Pod to delete"),
42-
mcp.Required(),
43-
),
44-
), s.podsDelete)
45-
s.server.AddTool(mcp.NewTool(
46-
"pods_log",
47-
mcp.WithDescription("Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name"),
48-
mcp.WithString("namespace",
49-
mcp.Description("Namespace to get the Pod logs from"),
50-
),
51-
mcp.WithString("name",
52-
mcp.Description("Name of the Pod to get the logs from"),
53-
mcp.Required(),
54-
),
55-
), s.podsLog)
56-
s.server.AddTool(mcp.NewTool(
57-
"pods_run",
58-
mcp.WithDescription("Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name"),
59-
mcp.WithString("namespace",
60-
mcp.Description("Namespace to run the Pod in"),
61-
),
62-
mcp.WithString("name",
63-
mcp.Description("Name of the Pod (Optional, random name if not provided)"),
64-
),
65-
mcp.WithString("image",
66-
mcp.Description("Container Image to run in the Pod"),
67-
mcp.Required(),
68-
),
69-
mcp.WithNumber("port",
70-
mcp.Description("TCP/IP port to expose from the Pod container (Optional, no port exposed if not provided)"),
71-
),
72-
), s.podsRun)
11+
func (s *Server) initPods() []server.ServerTool {
12+
return []server.ServerTool{
13+
{mcp.NewTool("pods_list",
14+
mcp.WithDescription("List all the Kubernetes pods in the current cluster from all namespaces"),
15+
), s.podsListInAllNamespaces},
16+
{mcp.NewTool("pods_list_in_namespace",
17+
mcp.WithDescription("List all the Kubernetes pods in the specified namespace in the current cluster"),
18+
mcp.WithString("namespace", mcp.Description("Namespace to list pods from"), mcp.Required()),
19+
), s.podsListInNamespace},
20+
{mcp.NewTool("pods_get",
21+
mcp.WithDescription("Get a Kubernetes Pod in the current or provided namespace with the provided name"),
22+
mcp.WithString("namespace", mcp.Description("Namespace to get the Pod from")),
23+
mcp.WithString("name", mcp.Description("Name of the Pod"), mcp.Required()),
24+
), s.podsGet},
25+
{mcp.NewTool("pods_delete",
26+
mcp.WithDescription("Delete a Kubernetes Pod in the current or provided namespace with the provided name"),
27+
mcp.WithString("namespace", mcp.Description("Namespace to delete the Pod from")),
28+
mcp.WithString("name", mcp.Description("Name of the Pod to delete"), mcp.Required()),
29+
), s.podsDelete},
30+
{mcp.NewTool("pods_log",
31+
mcp.WithDescription("Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name"),
32+
mcp.WithString("namespace", mcp.Description("Namespace to get the Pod logs from")),
33+
mcp.WithString("name", mcp.Description("Name of the Pod to get the logs from"), mcp.Required()),
34+
), s.podsLog},
35+
{mcp.NewTool("pods_run",
36+
mcp.WithDescription("Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name"),
37+
mcp.WithString("namespace", mcp.Description("Namespace to run the Pod in")),
38+
mcp.WithString("name", mcp.Description("Name of the Pod (Optional, random name if not provided)")),
39+
mcp.WithString("image", mcp.Description("Container Image to run in the Pod"), mcp.Required()),
40+
mcp.WithNumber("port", mcp.Description("TCP/IP port to expose from the Pod container (Optional, no port exposed if not provided)")),
41+
), s.podsRun},
42+
}
7343
}
7444

7545
func (s *Server) podsListInAllNamespaces(ctx context.Context, _ mcp.CallToolRequest) (*mcp.CallToolResult, error) {

pkg/mcp/resources.go

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,62 @@ import (
55
"errors"
66
"fmt"
77
"github.com/mark3labs/mcp-go/mcp"
8+
"github.com/mark3labs/mcp-go/server"
89
"k8s.io/apimachinery/pkg/runtime/schema"
910
)
1011

11-
func (s *Server) initResources() {
12-
s.server.AddTool(mcp.NewTool(
13-
"resources_list",
14-
mcp.WithDescription("List Kubernetes resources in the current cluster by providing their apiVersion and kind and optionally the namespace"),
15-
mcp.WithString("apiVersion",
16-
mcp.Description("apiVersion of the resources (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
17-
mcp.Required(),
18-
),
19-
mcp.WithString("kind",
20-
mcp.Description("kind of the resources (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
21-
mcp.Required(),
22-
),
23-
mcp.WithString("namespace",
24-
mcp.Description("Optional Namespace to retrieve the namespaced resources from (ignored in case of cluster scoped resources). If not provided, will list resources from all namespaces"),
25-
),
26-
), s.resourcesList)
27-
s.server.AddTool(mcp.NewTool(
28-
"resources_get",
29-
mcp.WithDescription("Get a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name"),
30-
mcp.WithString("apiVersion",
31-
mcp.Description("apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
32-
mcp.Required(),
33-
),
34-
mcp.WithString("kind",
35-
mcp.Description("kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
36-
mcp.Required(),
37-
),
38-
mcp.WithString("namespace",
39-
mcp.Description("Optional Namespace to retrieve the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will get resource from configured namespace"),
40-
),
41-
mcp.WithString("name",
42-
mcp.Description("Name of the resource"),
43-
mcp.Required(),
44-
),
45-
), s.resourcesGet)
46-
s.server.AddTool(mcp.NewTool(
47-
"resources_create_or_update",
48-
mcp.WithDescription("Create or update a Kubernetes resource in the current cluster by providing a YAML or JSON representation of the resource"),
49-
mcp.WithString("resource",
50-
mcp.Description("A JSON or YAML containing a representation of the Kubernetes resource. Should include top-level fields such as apiVersion,kind,metadata, and spec"),
51-
mcp.Required(),
52-
),
53-
), s.resourcesCreateOrUpdate)
54-
s.server.AddTool(mcp.NewTool(
55-
"resources_delete",
56-
mcp.WithDescription("Delete a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name"),
57-
mcp.WithString("apiVersion",
58-
mcp.Description("apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
59-
mcp.Required(),
60-
),
61-
mcp.WithString("kind",
62-
mcp.Description("kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
63-
mcp.Required(),
64-
),
65-
mcp.WithString("namespace",
66-
mcp.Description("Optional Namespace to delete the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will delete resource from configured namespace"),
67-
),
68-
mcp.WithString("name",
69-
mcp.Description("Name of the resource"),
70-
mcp.Required(),
71-
),
72-
), s.resourcesDelete)
12+
func (s *Server) initResources() []server.ServerTool {
13+
return []server.ServerTool{
14+
{mcp.NewTool("resources_list",
15+
mcp.WithDescription("List Kubernetes resources in the current cluster by providing their apiVersion and kind and optionally the namespace"),
16+
mcp.WithString("apiVersion",
17+
mcp.Description("apiVersion of the resources (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
18+
mcp.Required(),
19+
),
20+
mcp.WithString("kind",
21+
mcp.Description("kind of the resources (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
22+
mcp.Required(),
23+
),
24+
mcp.WithString("namespace",
25+
mcp.Description("Optional Namespace to retrieve the namespaced resources from (ignored in case of cluster scoped resources). If not provided, will list resources from all namespaces"))), s.resourcesList},
26+
{mcp.NewTool("resources_get",
27+
mcp.WithDescription("Get a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name"),
28+
mcp.WithString("apiVersion",
29+
mcp.Description("apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
30+
mcp.Required(),
31+
),
32+
mcp.WithString("kind",
33+
mcp.Description("kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
34+
mcp.Required(),
35+
),
36+
mcp.WithString("namespace",
37+
mcp.Description("Optional Namespace to retrieve the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will get resource from configured namespace"),
38+
),
39+
mcp.WithString("name", mcp.Description("Name of the resource"), mcp.Required()),
40+
), s.resourcesGet},
41+
{mcp.NewTool("resources_create_or_update",
42+
mcp.WithDescription("Create or update a Kubernetes resource in the current cluster by providing a YAML or JSON representation of the resource"),
43+
mcp.WithString("resource",
44+
mcp.Description("A JSON or YAML containing a representation of the Kubernetes resource. Should include top-level fields such as apiVersion,kind,metadata, and spec"),
45+
mcp.Required(),
46+
),
47+
), s.resourcesCreateOrUpdate},
48+
{mcp.NewTool("resources_delete",
49+
mcp.WithDescription("Delete a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name"),
50+
mcp.WithString("apiVersion",
51+
mcp.Description("apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)"),
52+
mcp.Required(),
53+
),
54+
mcp.WithString("kind",
55+
mcp.Description("kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)"),
56+
mcp.Required(),
57+
),
58+
mcp.WithString("namespace",
59+
mcp.Description("Optional Namespace to delete the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will delete resource from configured namespace"),
60+
),
61+
mcp.WithString("name", mcp.Description("Name of the resource"), mcp.Required()),
62+
), s.resourcesDelete},
63+
}
7364
}
7465

7566
func (s *Server) resourcesList(ctx context.Context, ctr mcp.CallToolRequest) (*mcp.CallToolResult, error) {

0 commit comments

Comments
 (0)