Skip to content

Commit 1605b1a

Browse files
committed
changed: optional props for list-k8s-pods tool
1 parent ee1202c commit 1605b1a

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

internal/tools/pods.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,33 @@ import (
99

1010
"github.com/strowk/foxy-contexts/pkg/fxctx"
1111
"github.com/strowk/foxy-contexts/pkg/mcp"
12+
"github.com/strowk/foxy-contexts/pkg/toolinput"
1213

1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
)
1516

1617
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+
)
1722
return fxctx.NewTool(
1823
&mcp.Tool{
1924
Name: "list-k8s-pods",
2025
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(),
3627
},
3728
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+
}
4133

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+
}
4339

4440
clientset, err := pool.GetClientset(k8sCtx)
4541

testdata/list_tools_test.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ out:
105105
"type": "object",
106106
"properties":
107107
{
108-
"context": { "type": "string" },
109-
"namespace": { "type": "string" },
108+
"context": { "type": "string", "description": "Name of the Kubernetes context to use, defaults to current context" },
109+
"namespace": { "type": "string", "description": "Namespace to list pods from, defaults to all namespaces" },
110110
},
111-
"required": ["context", "namespace"],
112111
},
113112
},
114113
{

0 commit comments

Comments
 (0)