Skip to content

Commit b575e9b

Browse files
committed
address review comments
Signed-off-by: iamsudip <[email protected]>
1 parent 2b46da4 commit b575e9b

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The following sets of tools are available (all on by default):
261261
- `name` (`string`) **(required)** - Name of the Pod to get the logs from
262262
- `namespace` (`string`) - Namespace to get the Pod logs from
263263
- `previous` (`boolean`) - Return previous terminated container logs (Optional)
264-
- `tailLines` (`number`) - Number of lines to retrieve from the end of the logs (Optional, default: 256)
264+
- `tail` (`number`) - Number of lines to retrieve from the end of the logs (Optional, default: 100)
265265

266266
- **pods_run** - Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name
267267
- `image` (`string`) **(required)** - Container Image to run in the Pod

pkg/kubernetes/pods.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ import (
1717
"k8s.io/client-go/tools/remotecommand"
1818
"k8s.io/metrics/pkg/apis/metrics"
1919
metricsv1beta1api "k8s.io/metrics/pkg/apis/metrics/v1beta1"
20+
"k8s.io/utils/ptr"
2021

2122
"github.com/containers/kubernetes-mcp-server/pkg/version"
2223
)
2324

25+
// Default number of lines to retrieve from the end of the logs
26+
const DefaultTailLines = int64(100)
27+
2428
type PodsTopOptions struct {
2529
metav1.ListOptions
2630
AllNamespaces bool
@@ -107,9 +111,8 @@ func (k *Kubernetes) PodsLog(ctx context.Context, namespace, name, container str
107111
if tailLines > 0 {
108112
logOptions.TailLines = &tailLines
109113
} else {
110-
// Default to 256 lines when not specified
111-
defaultLines := int64(256)
112-
logOptions.TailLines = &defaultLines
114+
// Default to DefaultTailLines lines when not specified
115+
logOptions.TailLines = ptr.To(DefaultTailLines)
113116
}
114117

115118
req := pods.GetLogs(name, logOptions)

pkg/mcp/pods_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,13 @@ func TestPodsLog(t *testing.T) {
757757
}
758758
})
759759

760-
// Test with tailLines parameter
760+
// Test with tail parameter
761761
podsTailLines, err := c.callTool("pods_log", map[string]interface{}{
762762
"namespace": "ns-1",
763763
"name": "a-pod-in-ns-1",
764-
"tailLines": 100,
764+
"tail": 50,
765765
})
766-
t.Run("pods_log with tailLines=100 returns pod log", func(t *testing.T) {
766+
t.Run("pods_log with tail=50 returns pod log", func(t *testing.T) {
767767
if err != nil {
768768
t.Fatalf("call tool failed %v", err)
769769
return
@@ -774,18 +774,18 @@ func TestPodsLog(t *testing.T) {
774774
}
775775
})
776776

777-
// Test with invalid tailLines parameter
777+
// Test with invalid tail parameter
778778
podsInvalidTailLines, _ := c.callTool("pods_log", map[string]interface{}{
779779
"namespace": "ns-1",
780780
"name": "a-pod-in-ns-1",
781-
"tailLines": "invalid",
781+
"tail": "invalid",
782782
})
783-
t.Run("pods_log with invalid tailLines returns error", func(t *testing.T) {
783+
t.Run("pods_log with invalid tail returns error", func(t *testing.T) {
784784
if !podsInvalidTailLines.IsError {
785785
t.Fatalf("call tool should fail")
786786
return
787787
}
788-
expectedErrorMsg := "failed to parse tailLines parameter: expected integer"
788+
expectedErrorMsg := "failed to parse tail parameter: expected integer"
789789
if errMsg := podsInvalidTailLines.Content[0].(mcp.TextContent).Text; !strings.Contains(errMsg, expectedErrorMsg) {
790790
t.Fatalf("unexpected error message, expected to contain '%s', got '%s'", expectedErrorMsg, errMsg)
791791
return

pkg/toolsets/core/pods.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func initPods() []api.ServerTool {
201201
Type: "string",
202202
Description: "Name of the Pod container to get the logs from (Optional)",
203203
},
204-
"tailLines": {
204+
"tail": {
205205
Type: "integer",
206-
Description: "Number of lines to retrieve from the end of the logs (Optional, default: 256)",
207-
Default: api.ToRawMessage(int64(256)),
206+
Description: "Number of lines to retrieve from the end of the logs (Optional, default: 100)",
207+
Default: api.ToRawMessage(kubernetes.DefaultTailLines),
208208
Minimum: ptr.To(float64(0)),
209209
},
210210
"previous": {
@@ -403,7 +403,7 @@ func podsLog(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
403403
previousBool = previous.(bool)
404404
}
405405
// Extract tailLines parameter
406-
tailLines := params.GetArguments()["tailLines"]
406+
tailLines := params.GetArguments()["tail"]
407407
var tailLinesInt int64
408408
if tailLines != nil {
409409
// Convert to int64 - safely handle both float64 (JSON number) and int types
@@ -415,7 +415,7 @@ func podsLog(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
415415
case int64:
416416
tailLinesInt = v
417417
default:
418-
return api.NewToolCallResult("", fmt.Errorf("failed to parse tailLines parameter: expected integer, got %T", tailLines)), nil
418+
return api.NewToolCallResult("", fmt.Errorf("failed to parse tail parameter: expected integer, got %T", tailLines)), nil
419419
}
420420
}
421421

0 commit comments

Comments
 (0)