Skip to content

Commit 9db41ec

Browse files
authored
set json format optional (#16)
* set json format optional Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * set json format optional Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * set json format optional Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> --------- Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
1 parent 3561157 commit 9db41ec

8 files changed

Lines changed: 21 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ bin/
1313
*.html
1414
/helm/kagent-tools/Chart.yaml
1515
/reports/tools-cve.csv
16+
.dagger/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ DOCKER_BUILD_ARGS ?= --pull --load --platform linux/$(LOCALARCH) --builder $(BUI
138138
# tools image build args
139139
TOOLS_ISTIO_VERSION ?= 1.26.2
140140
TOOLS_ARGO_ROLLOUTS_VERSION ?= 1.8.3
141-
TOOLS_KUBECTL_VERSION ?= 1.33.2
141+
TOOLS_KUBECTL_VERSION ?= 1.33.3
142142
TOOLS_HELM_VERSION ?= 3.18.4
143143
TOOLS_CILIUM_VERSION ?= 0.18.5
144144

internal/commands/builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func GetPods(namespace string, labels map[string]string) *CommandBuilder {
445445
builder = builder.WithLabels(labels)
446446
}
447447

448-
return builder.WithCache(true).WithOutput("json")
448+
return builder.WithCache(true)
449449
}
450450

451451
// GetServices creates a command to get services
@@ -460,7 +460,7 @@ func GetServices(namespace string, labels map[string]string) *CommandBuilder {
460460
builder = builder.WithLabels(labels)
461461
}
462462

463-
return builder.WithCache(true).WithOutput("json")
463+
return builder.WithCache(true)
464464
}
465465

466466
// GetDeployments creates a command to get deployments
@@ -475,7 +475,7 @@ func GetDeployments(namespace string, labels map[string]string) *CommandBuilder
475475
builder = builder.WithLabels(labels)
476476
}
477477

478-
return builder.WithCache(true).WithOutput("json")
478+
return builder.WithCache(true)
479479
}
480480

481481
// DescribeResource creates a command to describe a resource

internal/commands/builder_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestGetPods(t *testing.T) {
253253
assert.Equal(t, namespace, cb.namespace)
254254
assert.Equal(t, labels, cb.labels)
255255
assert.True(t, cb.cached)
256-
assert.Equal(t, "json", cb.output)
256+
assert.Empty(t, cb.output) // No default output format
257257
}
258258

259259
func TestGetServices(t *testing.T) {
@@ -268,7 +268,7 @@ func TestGetServices(t *testing.T) {
268268
assert.Equal(t, namespace, cb.namespace)
269269
assert.Equal(t, labels, cb.labels)
270270
assert.True(t, cb.cached)
271-
assert.Equal(t, "json", cb.output)
271+
assert.Empty(t, cb.output) // No default output format
272272
}
273273

274274
func TestGetDeployments(t *testing.T) {
@@ -283,7 +283,7 @@ func TestGetDeployments(t *testing.T) {
283283
assert.Equal(t, namespace, cb.namespace)
284284
assert.Equal(t, labels, cb.labels)
285285
assert.True(t, cb.cached)
286-
assert.Equal(t, "json", cb.output)
286+
assert.Empty(t, cb.output) // No default output format
287287
}
288288

289289
func TestDescribeResource(t *testing.T) {

pkg/k8s/k8s.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (k *K8sTool) handleKubectlGetEnhanced(ctx context.Context, request mcp.Call
5858
resourceName := mcp.ParseString(request, "resource_name", "")
5959
namespace := mcp.ParseString(request, "namespace", "")
6060
allNamespaces := mcp.ParseString(request, "all_namespaces", "") == "true"
61-
output := mcp.ParseString(request, "output", "json")
61+
output := mcp.ParseString(request, "output", "wide")
6262

6363
if resourceType == "" {
6464
return mcp.NewToolResultError("resource_type parameter is required"), nil
@@ -292,7 +292,7 @@ func (k *K8sTool) handleExecCommand(ctx context.Context, request mcp.CallToolReq
292292

293293
// Get available API resources
294294
func (k *K8sTool) handleGetAvailableAPIResources(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
295-
return k.runKubectlCommand(ctx, "api-resources", "-o", "json")
295+
return k.runKubectlCommand(ctx, "api-resources")
296296
}
297297

298298
// Kubectl describe tool
@@ -567,7 +567,7 @@ func RegisterTools(s *server.MCPServer, llm llms.Model, kubeconfig string) {
567567
mcp.WithString("resource_name", mcp.Description("Name of specific resource (optional)")),
568568
mcp.WithString("namespace", mcp.Description("Namespace to query (optional)")),
569569
mcp.WithString("all_namespaces", mcp.Description("Query all namespaces (true/false)")),
570-
mcp.WithString("output", mcp.Description("Output format (json, yaml, wide, etc.)")),
570+
mcp.WithString("output", mcp.Description("Output format (json, yaml, wide)"), mcp.DefaultString("wide")),
571571
), telemetry.AdaptToolHandler(telemetry.WithTracing("k8s_get_resources", k8sTool.handleKubectlGetEnhanced)))
572572

573573
s.AddTool(mcp.NewTool("k8s_get_pod_logs",

pkg/k8s/k8s_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func TestHandleGetAvailableAPIResources(t *testing.T) {
3737

3838
t.Run("success", func(t *testing.T) {
3939
mock := cmd.NewMockShellExecutor()
40-
expectedOutput := `[{"name": "pods", "singularName": "pod", "namespaced": true, "kind": "Pod"}]`
41-
mock.AddCommandString("kubectl", []string{"api-resources", "-o", "json"}, expectedOutput, nil)
40+
expectedOutput := `NAME SHORTNAMES APIVERSION NAMESPACED KIND
41+
pods po v1 true Pod
42+
services svc v1 true Service`
43+
mock.AddCommandString("kubectl", []string{"api-resources"}, expectedOutput, nil)
4244
ctx := cmd.WithShellExecutor(ctx, mock)
4345

4446
k8sTool := newTestK8sTool()
@@ -56,7 +58,7 @@ func TestHandleGetAvailableAPIResources(t *testing.T) {
5658

5759
t.Run("kubectl command failure", func(t *testing.T) {
5860
mock := cmd.NewMockShellExecutor()
59-
mock.AddCommandString("kubectl", []string{"api-resources", "-o", "json"}, "", assert.AnError)
61+
mock.AddCommandString("kubectl", []string{"api-resources"}, "", assert.AnError)
6062
ctx := cmd.WithShellExecutor(ctx, mock)
6163

6264
k8sTool := newTestK8sTool()
@@ -408,8 +410,8 @@ func TestHandleKubectlGetEnhanced(t *testing.T) {
408410

409411
t.Run("valid resource_type", func(t *testing.T) {
410412
mock := cmd.NewMockShellExecutor()
411-
expectedOutput := `{"items": [{"metadata": {"name": "pod1"}}]}`
412-
mock.AddCommandString("kubectl", []string{"get", "pods", "-o", "json"}, expectedOutput, nil)
413+
expectedOutput := `NAME READY STATUS RESTARTS AGE`
414+
mock.AddCommandString("kubectl", []string{"get", "pods", "-o", "wide"}, expectedOutput, nil)
413415
ctx := cmd.WithShellExecutor(ctx, mock)
414416

415417
k8sTool := newTestK8sTool()

test/e2e/cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = Describe("KAgent Tools E2E Tests", func() {
4444
config := TestServerConfig{
4545
Port: 8085,
4646
Stdio: false,
47-
Timeout: 30 * time.Second,
47+
Timeout: 60 * time.Second,
4848
}
4949

5050
server := NewTestServer(config)

test/e2e/helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ func InstallKAgentTools(namespace string, releaseName string) {
249249

250250
// GetMCPClient creates a new MCP client configured for the e2e test environment using the official mcp-go client
251251
func GetMCPClient() (*MCPClient, error) {
252-
// Create HTTP transport for the MCP server
253-
httpTransport, err := transport.NewStreamableHTTP("http://127.0.0.1:30885/mcp", transport.WithHTTPTimeout(15*time.Second))
252+
// Create HTTP transport for the MCP server with timeout long enough for operations like Istio installation
253+
httpTransport, err := transport.NewStreamableHTTP("http://127.0.0.1:30885/mcp", transport.WithHTTPTimeout(180*time.Second))
254254
if err != nil {
255255
return nil, fmt.Errorf("failed to create HTTP transport: %w", err)
256256
}

0 commit comments

Comments
 (0)