@@ -9,37 +9,33 @@ import (
9
9
10
10
"github.com/strowk/foxy-contexts/pkg/fxctx"
11
11
"github.com/strowk/foxy-contexts/pkg/mcp"
12
+ "github.com/strowk/foxy-contexts/pkg/toolinput"
12
13
13
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
15
)
15
16
16
17
func NewListPodsTool (pool k8s.ClientPool ) fxctx.Tool {
18
+ schema := toolinput .NewToolInputSchema (
19
+ toolinput .WithString ("context" , "Name of the Kubernetes context to use, defaults to current context" ),
20
+ toolinput .WithString ("namespace" , "Namespace to list pods from, defaults to all namespaces" ),
21
+ )
17
22
return fxctx .NewTool (
18
23
& mcp.Tool {
19
24
Name : "list-k8s-pods" ,
20
25
Description : utils .Ptr ("List Kubernetes pods using specific context in a specified namespace" ),
21
- InputSchema : mcp.ToolInputSchema {
22
- Type : "object" ,
23
- Properties : map [string ]map [string ]interface {}{
24
- "context" : {
25
- "type" : "string" ,
26
- },
27
- "namespace" : {
28
- "type" : "string" ,
29
- },
30
- },
31
- Required : []string {
32
- "context" ,
33
- "namespace" ,
34
- },
35
- },
26
+ InputSchema : schema .GetMcpToolInputSchema (),
36
27
},
37
28
func (args map [string ]interface {}) * mcp.CallToolResult {
38
- // TODO: figure out how to bind args reflectively
39
- k8sCtx := args ["context" ].(string )
40
- k8sNamespace := args ["namespace" ].(string )
29
+ input , err := schema .Validate (args )
30
+ if err != nil {
31
+ return errResponse (err )
32
+ }
41
33
42
- // TODO: figure out how to use current context, i.e need to make k8sCtx optional
34
+ k8sCtx := input .StringOr ("context" , "" )
35
+ k8sNamespace := input .StringOr ("namespace" , "" )
36
+ if k8sNamespace == "" {
37
+ k8sNamespace = metav1 .NamespaceAll
38
+ }
43
39
44
40
clientset , err := pool .GetClientset (k8sCtx )
45
41
0 commit comments