Skip to content

Add exec_in_pod tool for command execution in Kubernetes pods #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

rr-paras-patel
Copy link
Collaborator

@rr-paras-patel rr-paras-patel commented Apr 23, 2025

Introduce a new tool to execute commands within Kubernetes pods, enhancing the functionality with a schema for input validation and response handling. The implementation supports both string and array command formats, along with an optional shell specification.

This pull request introduces a new feature for executing commands in Kubernetes pods, removes redundant functionality, and updates documentation to align with the changes. The most significant updates include the addition of the exec_in_pod tool, removal of the kubectl_list tool, and updates to prompts and documentation to reflect these changes.

New Feature: exec_in_pod Tool

  • Added a new tool, exec_in_pod, for executing commands in Kubernetes pods using the Kubernetes client-node Exec API. It supports both string and array command formats, optional container targeting, and customizable timeouts. (src/tools/exec_in_pod.ts, src/tools/exec_in_pod.tsR1-R203)
  • Registered the exec_in_pod tool in src/index.ts, including its schema and request handler. (src/index.ts, [1] [2] [3]

Removed Functionality: kubectl_list Tool

  • Removed the kubectl_list tool and its associated schema, as its functionality overlaps with kubectl_get. (src/index.ts, [1] [2] [3]
  • Updated documentation in README.md to remove references to kubectl_list. (README.md, [1] [2]

Updates to Prompts

  • Renamed the k8s-troubleshoot prompt to k8s-diagnose for better clarity and alignment with its purpose. Updated descriptions, error messages, and flow details accordingly. (src/prompts/index.ts, [1] [2]
  • Updated README.md to reflect the prompt name change and its description. (README.md, README.mdL92-R100)

Documentation Enhancements

  • Added a new CLAUDE.md file providing detailed development guidelines, architecture overview, and testing strategies for the MCP server. (CLAUDE.md, CLAUDE.mdR1-R90)

Schema Updates

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new tool, exec_in_pod, which enables command execution in Kubernetes pods while supporting both string and array command formats along with optional shell and container parameters. The key changes include:

  • Implementation of the exec_in_pod tool with input validation and output handling.
  • New tests to verify both array and string command executions and error handling.
  • Updates to response schemas and the main request handler to register the new tool.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/exec_in_pod.test.ts New integration tests for the exec_in_pod tool functionality.
src/tools/exec_in_pod.ts Implementation of the exec_in_pod tool using the Kubernetes Exec API.
src/models/response-schemas.ts Added ExecInPodResponseSchema to support the new tool.
src/index.ts Updated request handler to include exec_in_pod in the tool list.

Copy link
Owner

@Flux159 Flux159 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the comment about making timeout configurable. I think the copilot review around using ExecInPodSchema is correct too, so probably want to update that.

Everything else LGTM

@rr-paras-patel rr-paras-patel marked this pull request as ready for review April 24, 2025 05:33
@rr-paras-patel rr-paras-patel marked this pull request as draft April 24, 2025 05:33
Copy link
Owner

@Flux159 Flux159 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM - not entirely sure whats causing the tests to fail though, once tests are fixed up can merge & make new build.

@rr-paras-patel rr-paras-patel marked this pull request as ready for review May 16, 2025 06:23
Copy link
Owner

@Flux159 Flux159 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to land this before the big refactor or after?

@Flux159
Copy link
Owner

Flux159 commented May 21, 2025

This one needs a rebase after the refactor

@Flux159
Copy link
Owner

Flux159 commented Jun 17, 2025

@rr-paras-patel ping on this PR - should be an easy rebase for index right? Seems like it would be a useful feature for next release.

rr-paras-patel and others added 28 commits June 22, 2025 14:25
…t, detailing new features such as scaling deployments, port forwarding, and Helm operations.
…d enhance clarity in instructions. Updated descriptions and structured steps for better user guidance in Kubernetes resource investigations.
…-level issues, improving guidance for Kubernetes resource investigations. Updated instructions for clarity and actionable insights.
…tency. Updated keyword search description and expanded resource type identification to include Ingress.
… and kubectl_explain tool for resource type identification. Enhanced clarity in troubleshooting steps for Kubernetes resources.
… to "all" to broaden the search scope for troubleshooting resources across all namespaces.
…g fixed delay and updating response schema handling for prompts list.
…delete, create, logs, generic, patch, and rollout functionalities in index.ts.
…ubernetes resources, following the removal of kubectl_list functionality.
…uring consistency across documentation and functionality following the removal of kubectl_list.
…t, ensuring alignment with recent changes in functionality across all test files.
…metadata references for improved clarity and consistency.
…es, and namespaces, ensuring robustness and clarity in resource validation.
…error handling, and improve service creation and deletion logic. Added tests for NodePort and LoadBalancer services, and ensured consistent use of asResponseSchema for type safety.
…tempt, improving error handling for non-existent services, and ensuring test failure for unexpected responses.
…e, updating descriptions for clarity and consistency in diagnostic operations.
…or connecting to AWS EKS, Google GKE, and Azure AKS clusters, and specify the latest image tag for Docker commands.
Comment on lines +234 to +258
### Connect to Google GKE Clusters

```json
{
"mcpServers": {
"kubernetes": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"~/.kube:/home/appuser/.kube:ro",
"-v",
"~/.config/gcloud:/home/appuser/.config/gcloud:ro",
"-e",
"CLOUDSDK_CORE_PROJECT=my-gcp-project",
"-e",
"CLOUDSDK_COMPUTE_REGION=us-central1",
"flux159/mcp-server-kubernetes:latest"
]
}
}
}
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a note around GKE in #103 (comment) - specifically the auth plugin for kubeconfig needs to be named "gke-gcloud-auth-plugin" for the docker container to correctly authenticate. Think that this is still the case so should be in the readme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Flux159 can you please update GKE related instructions i only have capability to verify with EKS

@rr-paras-patel rr-paras-patel merged commit 6bd9250 into Flux159:main Jun 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants