1
1
package mcp
2
2
3
3
import (
4
+ "github.com/mark3labs/mcp-go/mcp"
4
5
corev1 "k8s.io/api/core/v1"
5
6
rbacv1 "k8s.io/api/rbac/v1"
6
7
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -27,7 +28,7 @@ func TestPodsListInAllNamespaces(t *testing.T) {
27
28
}
28
29
})
29
30
var decoded []unstructured.Unstructured
30
- err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decoded )
31
+ err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(mcp. TextContent ). Text ), & decoded )
31
32
t .Run ("pods_list has yaml content" , func (t * testing.T ) {
32
33
if err != nil {
33
34
t .Fatalf ("invalid tool result content %v" , err )
@@ -102,7 +103,7 @@ func TestPodsListInAllNamespacesUnauthorized(t *testing.T) {
102
103
}
103
104
})
104
105
var decoded []unstructured.Unstructured
105
- err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decoded )
106
+ err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(mcp. TextContent ). Text ), & decoded )
106
107
t .Run ("pods_list has yaml content" , func (t * testing.T ) {
107
108
if err != nil {
108
109
t .Fatalf ("invalid tool result content %v" , err )
@@ -137,8 +138,8 @@ func TestPodsListInNamespace(t *testing.T) {
137
138
t .Fatalf ("call tool should fail" )
138
139
return
139
140
}
140
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to list pods in namespace, missing argument namespace" {
141
- t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
141
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to list pods in namespace, missing argument namespace" {
142
+ t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
142
143
return
143
144
}
144
145
})
@@ -156,7 +157,7 @@ func TestPodsListInNamespace(t *testing.T) {
156
157
}
157
158
})
158
159
var decoded []unstructured.Unstructured
159
- err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decoded )
160
+ err = yaml .Unmarshal ([]byte (toolResult .Content [0 ].(mcp. TextContent ). Text ), & decoded )
160
161
t .Run ("pods_list_in_namespace has yaml content" , func (t * testing.T ) {
161
162
if err != nil {
162
163
t .Fatalf ("invalid tool result content %v" , err )
@@ -197,8 +198,8 @@ func TestPodsGet(t *testing.T) {
197
198
t .Fatalf ("call tool should fail" )
198
199
return
199
200
}
200
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to get pod, missing argument name" {
201
- t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
201
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to get pod, missing argument name" {
202
+ t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
202
203
return
203
204
}
204
205
})
@@ -208,8 +209,8 @@ func TestPodsGet(t *testing.T) {
208
209
t .Fatalf ("call tool should fail" )
209
210
return
210
211
}
211
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to get pod not-found in namespace : pods \" not-found\" not found" {
212
- t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
212
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to get pod not-found in namespace : pods \" not-found\" not found" {
213
+ t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
213
214
return
214
215
}
215
216
})
@@ -227,7 +228,7 @@ func TestPodsGet(t *testing.T) {
227
228
}
228
229
})
229
230
var decodedNilNamespace unstructured.Unstructured
230
- err = yaml .Unmarshal ([]byte (podsGetNilNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decodedNilNamespace )
231
+ err = yaml .Unmarshal ([]byte (podsGetNilNamespace .Content [0 ].(mcp. TextContent ). Text ), & decodedNilNamespace )
231
232
t .Run ("pods_get with name and nil namespace has yaml content" , func (t * testing.T ) {
232
233
if err != nil {
233
234
t .Fatalf ("invalid tool result content %v" , err )
@@ -265,7 +266,7 @@ func TestPodsGet(t *testing.T) {
265
266
}
266
267
})
267
268
var decodedInNamespace unstructured.Unstructured
268
- err = yaml .Unmarshal ([]byte (podsGetInNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decodedInNamespace )
269
+ err = yaml .Unmarshal ([]byte (podsGetInNamespace .Content [0 ].(mcp. TextContent ). Text ), & decodedInNamespace )
269
270
t .Run ("pods_get with name and namespace has yaml content" , func (t * testing.T ) {
270
271
if err != nil {
271
272
t .Fatalf ("invalid tool result content %v" , err )
@@ -295,8 +296,8 @@ func TestPodsDelete(t *testing.T) {
295
296
t .Errorf ("call tool should fail" )
296
297
return
297
298
}
298
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to delete pod, missing argument name" {
299
- t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
299
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to delete pod, missing argument name" {
300
+ t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
300
301
return
301
302
}
302
303
})
@@ -306,8 +307,8 @@ func TestPodsDelete(t *testing.T) {
306
307
t .Errorf ("call tool should fail" )
307
308
return
308
309
}
309
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to delete pod not-found in namespace : pods \" not-found\" not found" {
310
- t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
310
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to delete pod not-found in namespace : pods \" not-found\" not found" {
311
+ t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
311
312
return
312
313
}
313
314
})
@@ -329,8 +330,8 @@ func TestPodsDelete(t *testing.T) {
329
330
t .Errorf ("call tool failed" )
330
331
return
331
332
}
332
- if podsDeleteNilNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "Pod deleted successfully" {
333
- t .Errorf ("invalid tool result content, got %v" , podsDeleteNilNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
333
+ if podsDeleteNilNamespace .Content [0 ].(mcp. TextContent ). Text != "Pod deleted successfully" {
334
+ t .Errorf ("invalid tool result content, got %v" , podsDeleteNilNamespace .Content [0 ].(mcp. TextContent ). Text )
334
335
return
335
336
}
336
337
})
@@ -359,8 +360,8 @@ func TestPodsDelete(t *testing.T) {
359
360
t .Errorf ("call tool failed" )
360
361
return
361
362
}
362
- if podsDeleteInNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "Pod deleted successfully" {
363
- t .Errorf ("invalid tool result content, got %v" , podsDeleteInNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
363
+ if podsDeleteInNamespace .Content [0 ].(mcp. TextContent ). Text != "Pod deleted successfully" {
364
+ t .Errorf ("invalid tool result content, got %v" , podsDeleteInNamespace .Content [0 ].(mcp. TextContent ). Text )
364
365
return
365
366
}
366
367
})
@@ -396,8 +397,8 @@ func TestPodsDelete(t *testing.T) {
396
397
t .Errorf ("call tool failed" )
397
398
return
398
399
}
399
- if podsDeleteManaged .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "Pod deleted successfully" {
400
- t .Errorf ("invalid tool result content, got %v" , podsDeleteManaged .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
400
+ if podsDeleteManaged .Content [0 ].(mcp. TextContent ). Text != "Pod deleted successfully" {
401
+ t .Errorf ("invalid tool result content, got %v" , podsDeleteManaged .Content [0 ].(mcp. TextContent ). Text )
401
402
return
402
403
}
403
404
})
@@ -451,8 +452,8 @@ func TestPodsDeleteInOpenShift(t *testing.T) {
451
452
t .Errorf ("call tool failed" )
452
453
return
453
454
}
454
- if podsDeleteManagedOpenShift .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "Pod deleted successfully" {
455
- t .Errorf ("invalid tool result content, got %v" , podsDeleteManagedOpenShift .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
455
+ if podsDeleteManagedOpenShift .Content [0 ].(mcp. TextContent ). Text != "Pod deleted successfully" {
456
+ t .Errorf ("invalid tool result content, got %v" , podsDeleteManagedOpenShift .Content [0 ].(mcp. TextContent ). Text )
456
457
return
457
458
}
458
459
})
@@ -482,8 +483,8 @@ func TestPodsLog(t *testing.T) {
482
483
t .Fatalf ("call tool should fail" )
483
484
return
484
485
}
485
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to get pod log, missing argument name" {
486
- t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
486
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to get pod log, missing argument name" {
487
+ t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
487
488
return
488
489
}
489
490
})
@@ -493,8 +494,8 @@ func TestPodsLog(t *testing.T) {
493
494
t .Fatalf ("call tool should fail" )
494
495
return
495
496
}
496
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to get pod not-found log in namespace : pods \" not-found\" not found" {
497
- t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
497
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to get pod not-found log in namespace : pods \" not-found\" not found" {
498
+ t .Fatalf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
498
499
return
499
500
}
500
501
})
@@ -537,8 +538,8 @@ func TestPodsRun(t *testing.T) {
537
538
t .Errorf ("call tool should fail" )
538
539
return
539
540
}
540
- if toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) != "failed to run pod, missing argument image" {
541
- t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) )
541
+ if toolResult .Content [0 ].(mcp. TextContent ). Text != "failed to run pod, missing argument image" {
542
+ t .Errorf ("invalid error message, got %v" , toolResult .Content [0 ].(mcp. TextContent ). Text )
542
543
return
543
544
}
544
545
})
@@ -554,7 +555,7 @@ func TestPodsRun(t *testing.T) {
554
555
}
555
556
})
556
557
var decodedNilNamespace []unstructured.Unstructured
557
- err = yaml .Unmarshal ([]byte (podsRunNilNamespace .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decodedNilNamespace )
558
+ err = yaml .Unmarshal ([]byte (podsRunNilNamespace .Content [0 ].(mcp. TextContent ). Text ), & decodedNilNamespace )
558
559
t .Run ("pods_run with image and nil namespace has yaml content" , func (t * testing.T ) {
559
560
if err != nil {
560
561
t .Errorf ("invalid tool result content %v" , err )
@@ -622,7 +623,7 @@ func TestPodsRun(t *testing.T) {
622
623
}
623
624
})
624
625
var decodedNamespaceAndPort []unstructured.Unstructured
625
- err = yaml .Unmarshal ([]byte (podsRunNamespaceAndPort .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decodedNamespaceAndPort )
626
+ err = yaml .Unmarshal ([]byte (podsRunNamespaceAndPort .Content [0 ].(mcp. TextContent ). Text ), & decodedNamespaceAndPort )
626
627
t .Run ("pods_run with image, namespace, and port has yaml content" , func (t * testing.T ) {
627
628
if err != nil {
628
629
t .Errorf ("invalid tool result content %v" , err )
@@ -692,7 +693,7 @@ func TestPodsRunInOpenShift(t *testing.T) {
692
693
return
693
694
}
694
695
var decodedPodServiceRoute []unstructured.Unstructured
695
- err = yaml .Unmarshal ([]byte (podsRunInOpenShift .Content [0 ].(map [ string ] interface {})[ "text" ].( string ) ), & decodedPodServiceRoute )
696
+ err = yaml .Unmarshal ([]byte (podsRunInOpenShift .Content [0 ].(mcp. TextContent ). Text ), & decodedPodServiceRoute )
696
697
if err != nil {
697
698
t .Errorf ("invalid tool result content %v" , err )
698
699
return
0 commit comments