You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces the ability to filter Kubernetes resources by label using a labelSelector parameter for the following tools:
* pods_list
* pods_list_in_namespace
* resources_list
This enhancement allows users to retrieve a more specific set of resources based on their labels, improving the flexibility and utility of these tools.
The labelSelector parameter accepts standard Kubernetes label selector syntax, such as app=myapp,env=prod or app in (myapp,yourapp).
Signed-off-by: Eran Cohen <[email protected]>
Copy file name to clipboardExpand all lines: pkg/mcp/pods.go
+31-17Lines changed: 31 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,33 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+
7
8
"github.com/mark3labs/mcp-go/mcp"
8
9
"github.com/mark3labs/mcp-go/server"
9
10
)
10
11
11
12
func (s*Server) initPods() []server.ServerTool {
12
13
return []server.ServerTool{
13
-
{mcp.NewTool("pods_list",
14
+
{Tool: mcp.NewTool("pods_list",
14
15
mcp.WithDescription("List all the Kubernetes pods in the current cluster from all namespaces"),
15
-
), s.podsListInAllNamespaces},
16
-
{mcp.NewTool("pods_list_in_namespace",
16
+
mcp.WithString("labelSelector", mcp.Description("Optional Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label"), mcp.Pattern("([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]")),
17
+
), Handler: s.podsListInAllNamespaces},
18
+
{Tool: mcp.NewTool("pods_list_in_namespace",
17
19
mcp.WithDescription("List all the Kubernetes pods in the specified namespace in the current cluster"),
18
20
mcp.WithString("namespace", mcp.Description("Namespace to list pods from"), mcp.Required()),
19
-
), s.podsListInNamespace},
20
-
{mcp.NewTool("pods_get",
21
+
mcp.WithString("labelSelector", mcp.Description("Optional Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label"), mcp.Pattern("([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]")),
22
+
), Handler: s.podsListInNamespace},
23
+
{Tool: mcp.NewTool("pods_get",
21
24
mcp.WithDescription("Get a Kubernetes Pod in the current or provided namespace with the provided name"),
22
25
mcp.WithString("namespace", mcp.Description("Namespace to get the Pod from")),
23
26
mcp.WithString("name", mcp.Description("Name of the Pod"), mcp.Required()),
24
-
), s.podsGet},
25
-
{mcp.NewTool("pods_delete",
27
+
), Handler: s.podsGet},
28
+
{Tool: mcp.NewTool("pods_delete",
26
29
mcp.WithDescription("Delete a Kubernetes Pod in the current or provided namespace with the provided name"),
27
30
mcp.WithString("namespace", mcp.Description("Namespace to delete the Pod from")),
28
31
mcp.WithString("name", mcp.Description("Name of the Pod to delete"), mcp.Required()),
29
-
), s.podsDelete},
30
-
{mcp.NewTool("pods_exec",
32
+
), Handler: s.podsDelete},
33
+
{Tool: mcp.NewTool("pods_exec",
31
34
mcp.WithDescription("Execute a command in a Kubernetes Pod in the current or provided namespace with the provided name and command"),
32
35
mcp.WithString("namespace", mcp.Description("Namespace of the Pod where the command will be executed")),
33
36
mcp.WithString("name", mcp.Description("Name of the Pod where the command will be executed"), mcp.Required()),
@@ -45,25 +48,31 @@ func (s *Server) initPods() []server.ServerTool {
45
48
mcp.Required(),
46
49
),
47
50
mcp.WithString("container", mcp.Description("Name of the Pod container where the command will be executed (Optional)")),
48
-
), s.podsExec},
49
-
{mcp.NewTool("pods_log",
51
+
), Handler: s.podsExec},
52
+
{Tool: mcp.NewTool("pods_log",
50
53
mcp.WithDescription("Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name"),
51
54
mcp.WithString("namespace", mcp.Description("Namespace to get the Pod logs from")),
52
55
mcp.WithString("name", mcp.Description("Name of the Pod to get the logs from"), mcp.Required()),
53
56
mcp.WithString("container", mcp.Description("Name of the Pod container to get the logs from (Optional)")),
54
-
), s.podsLog},
55
-
{mcp.NewTool("pods_run",
57
+
), Handler: s.podsLog},
58
+
{Tool: mcp.NewTool("pods_run",
56
59
mcp.WithDescription("Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name"),
57
60
mcp.WithString("namespace", mcp.Description("Namespace to run the Pod in")),
58
61
mcp.WithString("name", mcp.Description("Name of the Pod (Optional, random name if not provided)")),
59
62
mcp.WithString("image", mcp.Description("Container Image to run in the Pod"), mcp.Required()),
60
63
mcp.WithNumber("port", mcp.Description("TCP/IP port to expose from the Pod container (Optional, no port exposed if not provided)")),
0 commit comments