@@ -110,14 +110,25 @@ func (s *Server) resourcesList(ctx context.Context, ctr mcp.CallToolRequest) (*m
110
110
resourceListOptions := kubernetes.ResourceListOptions {
111
111
AsTable : s .configuration .ListOutput .AsTable (),
112
112
}
113
+
113
114
if labelSelector != nil {
114
- resourceListOptions .ListOptions .LabelSelector = labelSelector .(string )
115
+ l , ok := labelSelector .(string )
116
+ if ! ok {
117
+ return NewTextResult ("" , fmt .Errorf ("labelSelector is not a string" )), nil
118
+ }
119
+ resourceListOptions .ListOptions .LabelSelector = l
115
120
}
116
121
gvk , err := parseGroupVersionKind (ctr .GetArguments ())
117
122
if err != nil {
118
123
return NewTextResult ("" , fmt .Errorf ("failed to list resources, %s" , err )), nil
119
124
}
120
- ret , err := s .k .Derived (ctx ).ResourcesList (ctx , gvk , namespace .(string ), resourceListOptions )
125
+
126
+ ns , ok := namespace .(string )
127
+ if ! ok {
128
+ return NewTextResult ("" , fmt .Errorf ("namespace is not a string" )), nil
129
+ }
130
+
131
+ ret , err := s .k .Derived (ctx ).ResourcesList (ctx , gvk , ns , resourceListOptions )
121
132
if err != nil {
122
133
return NewTextResult ("" , fmt .Errorf ("failed to list resources: %v" , err )), nil
123
134
}
@@ -137,7 +148,18 @@ func (s *Server) resourcesGet(ctx context.Context, ctr mcp.CallToolRequest) (*mc
137
148
if name == nil {
138
149
return NewTextResult ("" , errors .New ("failed to get resource, missing argument name" )), nil
139
150
}
140
- ret , err := s .k .Derived (ctx ).ResourcesGet (ctx , gvk , namespace .(string ), name .(string ))
151
+
152
+ ns , ok := namespace .(string )
153
+ if ! ok {
154
+ return NewTextResult ("" , fmt .Errorf ("namespace is not a string" )), nil
155
+ }
156
+
157
+ n , ok := name .(string )
158
+ if ! ok {
159
+ return NewTextResult ("" , fmt .Errorf ("name is not a string" )), nil
160
+ }
161
+
162
+ ret , err := s .k .Derived (ctx ).ResourcesGet (ctx , gvk , ns , n )
141
163
if err != nil {
142
164
return NewTextResult ("" , fmt .Errorf ("failed to get resource: %v" , err )), nil
143
165
}
@@ -149,7 +171,13 @@ func (s *Server) resourcesCreateOrUpdate(ctx context.Context, ctr mcp.CallToolRe
149
171
if resource == nil || resource == "" {
150
172
return NewTextResult ("" , errors .New ("failed to create or update resources, missing argument resource" )), nil
151
173
}
152
- resources , err := s .k .Derived (ctx ).ResourcesCreateOrUpdate (ctx , resource .(string ))
174
+
175
+ r , ok := resource .(string )
176
+ if ! ok {
177
+ return NewTextResult ("" , fmt .Errorf ("resource is not a string" )), nil
178
+ }
179
+
180
+ resources , err := s .k .Derived (ctx ).ResourcesCreateOrUpdate (ctx , r )
153
181
if err != nil {
154
182
return NewTextResult ("" , fmt .Errorf ("failed to create or update resources: %v" , err )), nil
155
183
}
@@ -173,7 +201,18 @@ func (s *Server) resourcesDelete(ctx context.Context, ctr mcp.CallToolRequest) (
173
201
if name == nil {
174
202
return NewTextResult ("" , errors .New ("failed to delete resource, missing argument name" )), nil
175
203
}
176
- err = s .k .Derived (ctx ).ResourcesDelete (ctx , gvk , namespace .(string ), name .(string ))
204
+
205
+ ns , ok := namespace .(string )
206
+ if ! ok {
207
+ return NewTextResult ("" , fmt .Errorf ("namespace is not a string" )), nil
208
+ }
209
+
210
+ n , ok := name .(string )
211
+ if ! ok {
212
+ return NewTextResult ("" , fmt .Errorf ("name is not a string" )), nil
213
+ }
214
+
215
+ err = s .k .Derived (ctx ).ResourcesDelete (ctx , gvk , ns , n )
177
216
if err != nil {
178
217
return NewTextResult ("" , fmt .Errorf ("failed to delete resource: %v" , err )), nil
179
218
}
@@ -189,7 +228,13 @@ func parseGroupVersionKind(arguments map[string]interface{}) (*schema.GroupVersi
189
228
if kind == nil {
190
229
return nil , errors .New ("missing argument kind" )
191
230
}
192
- gv , err := schema .ParseGroupVersion (apiVersion .(string ))
231
+
232
+ a , ok := apiVersion .(string )
233
+ if ! ok {
234
+ return nil , fmt .Errorf ("name is not a string" )
235
+ }
236
+
237
+ gv , err := schema .ParseGroupVersion (a )
193
238
if err != nil {
194
239
return nil , errors .New ("invalid argument apiVersion" )
195
240
}
0 commit comments