Skip to content

Commit 503e3f5

Browse files
committed
helm
1 parent c158836 commit 503e3f5

File tree

6 files changed

+97
-9
lines changed

6 files changed

+97
-9
lines changed

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ A powerful and flexible Kubernetes [Model Context Protocol (MCP)](https://blog.m
1717
- **✅ Configuration**:
1818
- Automatically detect changes in the Kubernetes configuration and update the MCP server.
1919
- **View** and manage the current [Kubernetes `.kube/config`](https://blog.marcnuri.com/where-is-my-default-kubeconfig-file) or in-cluster configuration.
20+
- **Multi-cluster support**: Switch between different Kubernetes contexts on the fly using the optional `context` parameter on any cluster-specific tool.
21+
- **List available contexts**: Discover all available Kubernetes contexts in your kubeconfig with `contexts_list`.
2022
- **✅ Generic Kubernetes Resources**: Perform operations on **any** Kubernetes or OpenShift resource.
2123
- Any CRUD operation (Create or Update, Get, List, Delete).
2224
- **✅ Pods**: Perform Pod-specific operations.
@@ -196,11 +198,21 @@ Get the current Kubernetes configuration content as a kubeconfig YAML
196198
- If `true`, keeps only the current-context and relevant configuration pieces
197199
- If `false`, returns all contexts, clusters, auth-infos, and users
198200

201+
### `contexts_list`
202+
203+
List all available Kubernetes contexts from your kubeconfig with their cluster server URLs
204+
205+
**Parameters:** None
206+
207+
**Output format:** `[*] CONTEXT_NAME -> CLUSTER_SERVER_URL` where `*` indicates the current active context.
208+
199209
### `events_list`
200210

201211
List all the Kubernetes events in the current cluster from all namespaces
202212

203213
**Parameters:**
214+
- `context` (`string`, optional)
215+
- Kubernetes context to use for this operation. If not provided, uses the current context
204216
- `namespace` (`string`, optional)
205217
- Namespace to retrieve the events from. If not provided, will list events from all namespaces
206218

@@ -209,6 +221,8 @@ List all the Kubernetes events in the current cluster from all namespaces
209221
Install a Helm chart in the current or provided namespace with the provided name and chart
210222

211223
**Parameters:**
224+
- `context` (`string`, optional)
225+
- Kubernetes context to use for this operation. If not provided, uses the current context
212226
- `chart` (`string`, required)
213227
- Name of the Helm chart to install
214228
- Can be a local path or a remote URL
@@ -228,6 +242,8 @@ Install a Helm chart in the current or provided namespace with the provided name
228242
List all the Helm releases in the current or provided namespace (or in all namespaces if specified)
229243

230244
**Parameters:**
245+
- `context` (`string`, optional)
246+
- Kubernetes context to use for this operation. If not provided, uses the current context
231247
- `namespace` (`string`, optional)
232248
- Namespace to list the Helm releases from
233249
- If not provided, will use the configured namespace
@@ -240,6 +256,8 @@ List all the Helm releases in the current or provided namespace (or in all names
240256
Uninstall a Helm release in the current or provided namespace with the provided name
241257

242258
**Parameters:**
259+
- `context` (`string`, optional)
260+
- Kubernetes context to use for this operation. If not provided, uses the current context
243261
- `name` (`string`, required)
244262
- Name of the Helm release to uninstall
245263
- `namespace` (`string`, optional)
@@ -250,13 +268,17 @@ Uninstall a Helm release in the current or provided namespace with the provided
250268

251269
List all the Kubernetes namespaces in the current cluster
252270

253-
**Parameters:** None
271+
**Parameters:**
272+
- `context` (`string`, optional)
273+
- Kubernetes context to use for this operation. If not provided, uses the current context
254274

255275
### `pods_delete`
256276

257277
Delete a Kubernetes Pod in the current or provided namespace with the provided name
258278

259279
**Parameters:**
280+
- `context` (`string`, optional)
281+
- Kubernetes context to use for this operation. If not provided, uses the current context
260282
- `name` (`string`, required)
261283
- Name of the Pod to delete
262284
- `namespace` (`string`, required)
@@ -267,6 +289,8 @@ Delete a Kubernetes Pod in the current or provided namespace with the provided n
267289
Execute a command in a Kubernetes Pod in the current or provided namespace with the provided name and command
268290

269291
**Parameters:**
292+
- `context` (`string`, optional)
293+
- Kubernetes context to use for this operation. If not provided, uses the current context
270294
- `command` (`string[]`, required)
271295
- Command to execute in the Pod container
272296
- First item is the command, rest are arguments
@@ -283,6 +307,8 @@ Execute a command in a Kubernetes Pod in the current or provided namespace with
283307
Get a Kubernetes Pod in the current or provided namespace with the provided name
284308

285309
**Parameters:**
310+
- `context` (`string`, optional)
311+
- Kubernetes context to use for this operation. If not provided, uses the current context
286312
- `name` (`string`, required)
287313
- Name of the Pod
288314
- `namespace` (`string`, required)
@@ -293,6 +319,8 @@ Get a Kubernetes Pod in the current or provided namespace with the provided name
293319
List all the Kubernetes pods in the current cluster from all namespaces
294320

295321
**Parameters:**
322+
- `context` (`string`, optional)
323+
- Kubernetes context to use for this operation. If not provided, uses the current context
296324
- `labelSelector` (`string`, optional)
297325
- Kubernetes label selector (e.g., 'app=myapp,env=prod' or 'app in (myapp,yourapp)'). Use this option to filter the pods by label
298326

@@ -301,6 +329,8 @@ List all the Kubernetes pods in the current cluster from all namespaces
301329
List all the Kubernetes pods in the specified namespace in the current cluster
302330

303331
**Parameters:**
332+
- `context` (`string`, optional)
333+
- Kubernetes context to use for this operation. If not provided, uses the current context
304334
- `namespace` (`string`, required)
305335
- Namespace to list pods from
306336
- `labelSelector` (`string`, optional)
@@ -311,6 +341,8 @@ List all the Kubernetes pods in the specified namespace in the current cluster
311341
Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name
312342

313343
**Parameters:**
344+
- `context` (`string`, optional)
345+
- Kubernetes context to use for this operation. If not provided, uses the current context
314346
- `name` (`string`, required)
315347
- Name of the Pod to get logs from
316348
- `namespace` (`string`, required)
@@ -325,6 +357,8 @@ Get the logs of a Kubernetes Pod in the current or provided namespace with the p
325357
Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name
326358

327359
**Parameters:**
360+
- `context` (`string`, optional)
361+
- Kubernetes context to use for this operation. If not provided, uses the current context
328362
- `image` (`string`, required)
329363
- Container Image to run in the Pod
330364
- `namespace` (`string`, required)
@@ -340,6 +374,8 @@ Run a Kubernetes Pod in the current or provided namespace with the provided cont
340374
Lists the resource consumption (CPU and memory) as recorded by the Kubernetes Metrics Server for the specified Kubernetes Pods in the all namespaces, the provided namespace, or the current namespace
341375

342376
**Parameters:**
377+
- `context` (`string`, optional)
378+
- Kubernetes context to use for this operation. If not provided, uses the current context
343379
- `all_namespaces` (`boolean`, optional, default: `true`)
344380
- If `true`, lists resource consumption for Pods in all namespaces
345381
- If `false`, lists resource consumption for Pods in the configured or provided namespace
@@ -356,11 +392,17 @@ Lists the resource consumption (CPU and memory) as recorded by the Kubernetes Me
356392

357393
List all the OpenShift projects in the current cluster
358394

395+
**Parameters:**
396+
- `context` (`string`, optional)
397+
- Kubernetes context to use for this operation. If not provided, uses the current context
398+
359399
### `resources_create_or_update`
360400

361401
Create or update a Kubernetes resource in the current cluster by providing a YAML or JSON representation of the resource
362402

363403
**Parameters:**
404+
- `context` (`string`, optional)
405+
- Kubernetes context to use for this operation. If not provided, uses the current context
364406
- `resource` (`string`, required)
365407
- A JSON or YAML containing a representation of the Kubernetes resource
366408
- Should include top-level fields such as apiVersion, kind, metadata, and spec
@@ -377,6 +419,8 @@ Create or update a Kubernetes resource in the current cluster by providing a YAM
377419
Delete a Kubernetes resource in the current cluster
378420

379421
**Parameters:**
422+
- `context` (`string`, optional)
423+
- Kubernetes context to use for this operation. If not provided, uses the current context
380424
- `apiVersion` (`string`, required)
381425
- apiVersion of the resource (e.g., `v1`, `apps/v1`, `networking.k8s.io/v1`)
382426
- `kind` (`string`, required)
@@ -393,6 +437,8 @@ Delete a Kubernetes resource in the current cluster
393437
Get a Kubernetes resource in the current cluster
394438

395439
**Parameters:**
440+
- `context` (`string`, optional)
441+
- Kubernetes context to use for this operation. If not provided, uses the current context
396442
- `apiVersion` (`string`, required)
397443
- apiVersion of the resource (e.g., `v1`, `apps/v1`, `networking.k8s.io/v1`)
398444
- `kind` (`string`, required)
@@ -409,6 +455,8 @@ Get a Kubernetes resource in the current cluster
409455
List Kubernetes resources and objects in the current cluster
410456

411457
**Parameters:**
458+
- `context` (`string`, optional)
459+
- Kubernetes context to use for this operation. If not provided, uses the current context
412460
- `apiVersion` (`string`, required)
413461
- apiVersion of the resources (e.g., `v1`, `apps/v1`, `networking.k8s.io/v1`)
414462
- `kind` (`string`, required)

pkg/mcp/testdata/toolsets-full-tools-openshift.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
"description": "Chart reference to install (for example: stable/grafana, oci://ghcr.io/nginxinc/charts/nginx-ingress)",
7474
"type": "string"
7575
},
76+
"context": {
77+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
78+
"type": "string"
79+
},
7680
"name": {
7781
"description": "Name of the Helm release (Optional, random name if not provided)",
7882
"type": "string"
@@ -108,6 +112,10 @@
108112
"description": "If true, lists all Helm releases in all namespaces ignoring the namespace argument (Optional)",
109113
"type": "boolean"
110114
},
115+
"context": {
116+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
117+
"type": "string"
118+
},
111119
"namespace": {
112120
"description": "Namespace to list Helm releases from (Optional, all namespaces if not provided)",
113121
"type": "string"
@@ -128,6 +136,10 @@
128136
"inputSchema": {
129137
"type": "object",
130138
"properties": {
139+
"context": {
140+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
141+
"type": "string"
142+
},
131143
"name": {
132144
"description": "Name of the Helm release to uninstall",
133145
"type": "string"

pkg/mcp/testdata/toolsets-full-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
"description": "Chart reference to install (for example: stable/grafana, oci://ghcr.io/nginxinc/charts/nginx-ingress)",
7474
"type": "string"
7575
},
76+
"context": {
77+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
78+
"type": "string"
79+
},
7680
"name": {
7781
"description": "Name of the Helm release (Optional, random name if not provided)",
7882
"type": "string"
@@ -108,6 +112,10 @@
108112
"description": "If true, lists all Helm releases in all namespaces ignoring the namespace argument (Optional)",
109113
"type": "boolean"
110114
},
115+
"context": {
116+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
117+
"type": "string"
118+
},
111119
"namespace": {
112120
"description": "Namespace to list Helm releases from (Optional, all namespaces if not provided)",
113121
"type": "string"
@@ -128,6 +136,10 @@
128136
"inputSchema": {
129137
"type": "object",
130138
"properties": {
139+
"context": {
140+
"description": "Optional Kubernetes context to use for this operation (if not provided, uses the current context)",
141+
"type": "string"
142+
},
131143
"name": {
132144
"description": "Name of the Helm release to uninstall",
133145
"type": "string"

pkg/toolsets/full/helm.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func initHelm() []api.ServerTool {
1717
InputSchema: &jsonschema.Schema{
1818
Type: "object",
1919
Properties: map[string]*jsonschema.Schema{
20+
"context": api.ContextParameterSchema,
2021
"chart": {
2122
Type: "string",
2223
Description: "Chart reference to install (for example: stable/grafana, oci://ghcr.io/nginxinc/charts/nginx-ingress)",
@@ -51,6 +52,7 @@ func initHelm() []api.ServerTool {
5152
InputSchema: &jsonschema.Schema{
5253
Type: "object",
5354
Properties: map[string]*jsonschema.Schema{
55+
"context": api.ContextParameterSchema,
5456
"namespace": {
5557
Type: "string",
5658
Description: "Namespace to list Helm releases from (Optional, all namespaces if not provided)",
@@ -75,6 +77,7 @@ func initHelm() []api.ServerTool {
7577
InputSchema: &jsonschema.Schema{
7678
Type: "object",
7779
Properties: map[string]*jsonschema.Schema{
80+
"context": api.ContextParameterSchema,
7881
"name": {
7982
Type: "string",
8083
Description: "Name of the Helm release to uninstall",
@@ -98,6 +101,11 @@ func initHelm() []api.ServerTool {
98101
}
99102

100103
func helmInstall(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
104+
k8sClient, err := api.GetKubernetesWithContext(params)
105+
if err != nil {
106+
return api.NewToolCallResult("", err), nil
107+
}
108+
101109
var chart string
102110
ok := false
103111
if chart, ok = params.GetArguments()["chart"].(string); !ok {
@@ -115,14 +123,19 @@ func helmInstall(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
115123
if v, ok := params.GetArguments()["namespace"].(string); ok {
116124
namespace = v
117125
}
118-
ret, err := params.NewHelm().Install(params, chart, values, name, namespace)
126+
ret, err := k8sClient.NewHelm().Install(params, chart, values, name, namespace)
119127
if err != nil {
120128
return api.NewToolCallResult("", fmt.Errorf("failed to install helm chart '%s': %w", chart, err)), nil
121129
}
122130
return api.NewToolCallResult(ret, err), nil
123131
}
124132

125133
func helmList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
134+
k8sClient, err := api.GetKubernetesWithContext(params)
135+
if err != nil {
136+
return api.NewToolCallResult("", err), nil
137+
}
138+
126139
allNamespaces := false
127140
if v, ok := params.GetArguments()["all_namespaces"].(bool); ok {
128141
allNamespaces = v
@@ -131,14 +144,19 @@ func helmList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
131144
if v, ok := params.GetArguments()["namespace"].(string); ok {
132145
namespace = v
133146
}
134-
ret, err := params.NewHelm().List(namespace, allNamespaces)
147+
ret, err := k8sClient.NewHelm().List(namespace, allNamespaces)
135148
if err != nil {
136149
return api.NewToolCallResult("", fmt.Errorf("failed to list helm releases in namespace '%s': %w", namespace, err)), nil
137150
}
138151
return api.NewToolCallResult(ret, err), nil
139152
}
140153

141154
func helmUninstall(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
155+
k8sClient, err := api.GetKubernetesWithContext(params)
156+
if err != nil {
157+
return api.NewToolCallResult("", err), nil
158+
}
159+
142160
var name string
143161
ok := false
144162
if name, ok = params.GetArguments()["name"].(string); !ok {
@@ -148,7 +166,7 @@ func helmUninstall(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
148166
if v, ok := params.GetArguments()["namespace"].(string); ok {
149167
namespace = v
150168
}
151-
ret, err := params.NewHelm().Uninstall(name, namespace)
169+
ret, err := k8sClient.NewHelm().Uninstall(name, namespace)
152170
if err != nil {
153171
return api.NewToolCallResult("", fmt.Errorf("failed to uninstall helm chart '%s': %w", name, err)), nil
154172
}

pkg/toolsets/full/namespaces.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"k8s.io/utils/ptr"
99

1010
"github.com/containers/kubernetes-mcp-server/pkg/api"
11-
"github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
1211
internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
1312
)
1413

@@ -64,7 +63,7 @@ func namespacesList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
6463
return api.NewToolCallResult("", err), nil
6564
}
6665

67-
ret, err := k8sClient.NamespacesList(params.Context, kubernetes.ResourceListOptions{AsTable: params.ListOutput.AsTable()})
66+
ret, err := k8sClient.NamespacesList(params.Context, internalk8s.ResourceListOptions{AsTable: params.ListOutput.AsTable()})
6867
if err != nil {
6968
return api.NewToolCallResult("", fmt.Errorf("failed to list namespaces: %v", err)), nil
7069
}
@@ -78,7 +77,7 @@ func projectsList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
7877
return api.NewToolCallResult("", err), nil
7978
}
8079

81-
ret, err := k8sClient.ProjectsList(params.Context, kubernetes.ResourceListOptions{AsTable: params.ListOutput.AsTable()})
80+
ret, err := k8sClient.ProjectsList(params.Context, internalk8s.ResourceListOptions{AsTable: params.ListOutput.AsTable()})
8281
if err != nil {
8382
return api.NewToolCallResult("", fmt.Errorf("failed to list projects: %v", err)), nil
8483
}

pkg/toolsets/full/resources.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"k8s.io/utils/ptr"
1111

1212
"github.com/containers/kubernetes-mcp-server/pkg/api"
13-
"github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
1413
internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
1514
"github.com/containers/kubernetes-mcp-server/pkg/output"
1615
)
@@ -162,7 +161,7 @@ func resourcesList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
162161
namespace = ""
163162
}
164163
labelSelector := params.GetArguments()["labelSelector"]
165-
resourceListOptions := kubernetes.ResourceListOptions{
164+
resourceListOptions := internalk8s.ResourceListOptions{
166165
AsTable: params.ListOutput.AsTable(),
167166
}
168167

0 commit comments

Comments
 (0)