-
Notifications
You must be signed in to change notification settings - Fork 126
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
rr-paras-patel
merged 119 commits into
Flux159:main
from
rr-paras-patel:feat/add-exec-into-pod-method
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
bc8782f
Add exec_in_pod tool for executing commands in Kubernetes pods
rr-paras-patel 308c2de
Add ExecInPodResponseSchema for executing commands in pods
rr-paras-patel b0c58d6
Add execInPod tool and schema for executing commands in pods
rr-paras-patel 3128b65
Add shell option to execInPodSchema and enhance execInPod function fo…
rr-paras-patel 8c816d2
Update exec_in_pod tests to use ExecInPodResponseSchema for response …
rr-paras-patel 1dd9a28
Add timeout option to execInPodSchema and execInPod function for comm…
rr-paras-patel 6b8c08a
Fix TypeScript errors in exec_in_pod tests and skip timeout-prone tests
rr-paras-patel 12b86af
Add comprehensive unit tests for exec_in_pod functionality
rr-paras-patel e2edf0d
Adding DeepWiki link to readme & contributing
Flux159 1b65e21
Rename status to phase for list_pods
Flux159 264d09c
Bump version to 1.6.1
github-actions[bot] f3358f4
fix(CVE): jsonpath-plus
273c91b
Bump version to 1.6.2
github-actions[bot] 68a7e17
Updates to support in-cluster configuration
ajit-pendse 6381c17
Added unit test cases for isRunningInCluster
ajit-pendse 3fcdb62
Added debug logs
ajit-pendse 75164da
Refactor configmap.test.ts to use kubectl_create and fix test timeouts
rr-paras-patel b0b31d4
Add hookTimeout to vitest config for longer-running test hooks
rr-paras-patel 1dc6280
Add unified kubectl command implementation for get, list, describe, a…
rr-paras-patel 3313cd2
Add comprehensive tests for unified kubectl commands
rr-paras-patel 130dce4
Update existing tests to use unified kubectl commands
rr-paras-patel b686e86
Integrate unified kubectl commands into server handler
rr-paras-patel 61f519a
Add .vscode directory to .gitignore
rr-paras-patel bb15215
Update service tests to use kubectl-*.ts tools
rr-paras-patel 48783a0
Enhance update service test to use more kubectl tools
rr-paras-patel dbb271b
Enhance delete service test to use multiple kubectl tools
rr-paras-patel d971c26
Replace create_service with kubectl_create in delete service test
rr-paras-patel 4a90b0f
Update NodePort service test to use kubectl tools
rr-paras-patel 6ed55fc
Update pod lifecycle management test to use kubectl-*.ts tools
rr-paras-patel a441b93
Update unit.test.ts to use kubectl-*.ts tools for namespaces, nodes, …
rr-paras-patel 3d284b4
Update port_forward.test.ts to use kubectl-*.ts tools
rr-paras-patel 31e2aea
Refactor helm tests to utilize kubectl tools for resource management
rr-paras-patel a2ad295
Update namespace.test.ts to use kubectl tools
rr-paras-patel d63111b
Update service.test.ts to use kubectl tools instead of direct service…
rr-paras-patel 288333a
Update sse.test.ts to use kubectl_list instead of list_pods
rr-paras-patel 877cd04
Replace last create_service with kubectl_create in service.test.ts
rr-paras-patel 7db779d
Increase timeout for LoadBalancer service test
rr-paras-patel 188b5d1
Replace create_service with kubectl_create in describe service test
rr-paras-patel 7dabcd1
Simplify tools by replacing legacy APIs with kubectl-*.ts equivalents
rr-paras-patel 494e981
Remove legacy tool implementations replaced by kubectl-*.ts equivalents
rr-paras-patel 91b86bf
Remove legacy tools imports and reimplement tool handlers using kubec…
rr-paras-patel 1251ff2
Delete remaining legacy tool implementations replaced by kubectl-*.ts…
rr-paras-patel 09b33f9
Refactor index.ts to integrate kubectl_logs and kubectl_get, removing…
rr-paras-patel 26e2e52
Consolidate context-related tools into kubectl-context.ts and events …
rr-paras-patel b99fe68
Refactor: Remove createDeploymentSchema as separate tool, using kubec…
rr-paras-patel 2917329
Refactor: Remove legacy tools mapping to simplify the API
rr-paras-patel c9e2a88
Update test cases to use kubectl_context instead of legacy context tools
rr-paras-patel 1a67832
Refactor tests to utilize asResponseSchema for response validation, e…
rr-paras-patel e288744
Refactor kubectl tests to use kubectl_get and kubectl_logs, updating …
rr-paras-patel 8fbb1b9
Update README.md to reflect unified kubectl API structure
rr-paras-patel 8639c63
Replace scale_deployment with kubectl-scale implementation following …
rr-paras-patel c559747
Add kubectl_generic, kubectl_patch, and kubectl_rollout implementatio…
rr-paras-patel 73f37b3
Update README.md to document new kubectl commands
rr-paras-patel 54d42cf
Add test files for kubectl-generic, kubectl-patch, and kubectl-rollou…
rr-paras-patel 5149f97
Optimize test timeouts for faster execution: Reduce wait and retry in…
rr-paras-patel d71df3d
Remove deprecated scale_deployment command and related schemas; strea…
rr-paras-patel cceffd6
Bump version to 2.0.0
github-actions[bot] 03a5848
Added Gitlab CI config
ajit-pendse 8948d9c
Updated image repo name in CI
ajit-pendse 97a2a58
Latest changes merged
ajit-pendse 2afe39d
Removed console.log
ajit-pendse 75b52e2
Bump version to 2.1.0
github-actions[bot] 852d7c5
Enhance README.md with detailed documentation on non-destructive mode…
rr-paras-patel 672e7ac
Update README.md to clarify the status of `kubectl_generic` in non-de…
rr-paras-patel ccd978b
fix: remove console.log calls that break stdio transport
aliou 91bad09
Bump version to 2.1.1
github-actions[bot] d562af1
feat: Add comprehensive environment variable kubeconfig support with …
spo0nman 10afb79
feat: add KUBECONFIG_PATH support and improve authentication document…
spo0nman def4705
Bump version to 2.2.0
github-actions[bot] 4d97db2
Remove unnecessary esbuild
Flux159 41d4245
Bump version to 2.2.1
github-actions[bot] a1c07d1
feat: ensure kubectl works by writing kubeconfig to temp file if only…
spo0nman dde6601
fix: simplify kubeconfig handling and ensure kubectl env var inheritance
spo0nman 6c859fd
feat: enhance kubeconfig handling by creating temp files from YAML an…
spo0nman 53b4615
feat: prioritize KUBECONFIG_YAML over in-cluster config when explicit…
spo0nman 56dab8b
fix: resolve test failures in KubernetesManager, kubectl, namespace, …
spo0nman 43cf677
Cleanup of kubeconfig loading
Flux159 c798908
Bump version to 2.3.0
github-actions[bot] 07c5202
Upgrading kubernetes/client-node
Flux159 9f7ea36
Bump version to 2.3.1
github-actions[bot] 96105b1
Upgrade node image to fix Critical Vulnerabilities, also fix schema f…
kkambhat 59797c9
Upgrade node image to fix Critical Vulnerabilities, also fix schema f…
kkambhat 633beea
Address reviewers comment
kkambhat f7d4be0
Additional changes
kkambhat 6a47a3c
Bump version to 2.4.0
github-actions[bot] 66d5c3e
Adding support for HOST variable for sse transport
Flux159 39af5d3
Bump version to 2.4.1
github-actions[bot] 03780d4
feat: add prompt handling for Kubernetes troubleshooting
rr-paras-patel e850556
Update README to include detailed information on the new k8s-troubles…
rr-paras-patel 8bb2134
Enhance error handling for multi-container pods in kubectl-logs.ts an…
rr-paras-patel 5c4efd3
Added default value for namespace in prompt registration to enhance u…
rr-paras-patel b810e30
Added default value for the 'namespace' field in prompt registration …
rr-paras-patel 9d8794e
Update README to include advanced operations for Kubernetes managemen…
rr-paras-patel d0ac5fc
Refine troubleshooting prompts to include nodes in search criteria an…
rr-paras-patel 0495f77
Enhance troubleshooting prompts to include detailed analysis for node…
rr-paras-patel 843ce6b
Refine descriptions in k8s-troubleshoot prompt for clarity and consis…
rr-paras-patel 18e1d5e
Update k8s-troubleshoot prompt to include custom resource definitions…
rr-paras-patel a30cbe0
Update default namespace in k8s-troubleshoot prompt from "monitoring"…
rr-paras-patel 4983e32
Update tests/prompts.test.ts
rr-paras-patel 77d0f73
Refactor tests/prompts.test.ts to improve test reliability by removin…
rr-paras-patel 44f5b39
Bump version to 2.4.2
github-actions[bot] 3b4bae1
Add execInPod tool and schema for executing commands in pods
rr-paras-patel 8c67175
Add CLAUDE.md
rr-paras-patel 94ad575
Update .gitignore to ignore editor files
rr-paras-patel 23ecbb0
Merge branch 'main' into feat/add-exec-into-pod-method
rr-paras-patel 0ddafca
Enhance kubectl toolset by adding imports for describe, list, apply, …
rr-paras-patel 8c40dce
Add type definitions for input parameters in execInPod method to enha…
rr-paras-patel caa3e79
Remove unused imports in exec_in_pod.test.ts
rr-paras-patel 80d4ea0
Remove unused imports from index.ts to clean up the codebase.
rr-paras-patel ed95e3d
Remove kubectl_list functionality and its associated schema from inde…
rr-paras-patel 3966e37
Refactor tests to replace kubectl_list with kubectl_get for listing K…
rr-paras-patel 729e1cf
Update README and tests to replace kubectl_list with kubectl_get, ens…
rr-paras-patel 8290d0f
Refactor tests to consistently use kubectl_get instead of kubectl_lis…
rr-paras-patel 8a6527a
Update tests to access resource names directly, removing unnecessary …
rr-paras-patel aaffa44
Enhance tests by adding checks for item existence in deployments, nod…
rr-paras-patel 8752d78
Refactor service tests to implement proper response schemas, enhance …
rr-paras-patel 6cb7c68
Enhance service deletion test by capturing response after deletion at…
rr-paras-patel edafde6
Rename troubleshooting prompt to `k8s-diagnose` in README and codebas…
rr-paras-patel 3d52036
Update ADVANCED_README.md to include advanced Docker usage examples f…
rr-paras-patel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
||
## Development Commands | ||
|
||
### Build and Development | ||
|
||
- `bun run build` - Compile TypeScript to dist/ and make executables | ||
- `bun run dev` - Start TypeScript compiler in watch mode for development | ||
- `bun run start` - Run the compiled server from dist/index.js | ||
- `bun run test` - Run all tests using Vitest | ||
|
||
### Testing and Quality | ||
|
||
- `bun run test` - Execute the complete test suite with custom sequencer (kubectl tests run last) | ||
- Tests have 120s timeout and 60s hook timeout due to Kubernetes operations | ||
- Use `npx @modelcontextprotocol/inspector node dist/index.js` for local testing with Inspector | ||
- Always run single test based on with area you are working on. running all tests will take a long time. | ||
|
||
### Local Development Testing | ||
|
||
- `bun run chat` - Test locally with mcp-chat CLI client | ||
- For Claude Desktop testing, point to local `dist/index.js` build | ||
|
||
## Architecture Overview | ||
|
||
This is an MCP (Model Context Protocol) server that provides Kubernetes cluster management capabilities. The server connects to Kubernetes clusters via kubectl and offers both read-only and destructive operations. | ||
|
||
### Core Components | ||
|
||
**KubernetesManager** (`src/utils/kubernetes-manager.ts`): Central class managing Kubernetes API connections, resource tracking, port forwards, and watches. Handles kubeconfig loading from multiple sources in priority order. | ||
|
||
**Tool Structure**: Each Kubernetes operation is implemented as a separate tool in `src/tools/`, with corresponding Zod schemas for validation. Tools are divided into: | ||
|
||
- kubectl operations (get, describe, apply, delete, create, etc.) | ||
- Helm operations (install, upgrade, uninstall charts) | ||
- Specialized operations (port forwarding, scaling, rollouts) | ||
|
||
**Resource Handlers** (`src/resources/handlers.ts`): Manage MCP resource endpoints for dynamic data retrieval. | ||
|
||
**Configuration System** (`src/config/`): Contains schemas and templates for deployments, namespaces, containers, and cleanup operations. | ||
|
||
### Key Architecture Patterns | ||
|
||
- **Tool Filtering**: Non-destructive mode dynamically removes destructive tools based on `ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS` environment variable | ||
- **Unified kubectl API**: Consistent interface across all kubectl operations with standardized error handling | ||
- **Resource Tracking**: All created resources are tracked for cleanup capabilities | ||
- **Transport Flexibility**: Supports both StdioTransport and SSE transport for different integration scenarios | ||
|
||
### Request Flow | ||
|
||
1. Client sends MCP request via transport layer | ||
2. Server filters available tools based on destructive/non-destructive mode | ||
3. Request routed to appropriate handler (tools/resources) | ||
4. KubernetesManager executes Kubernetes API calls | ||
5. Responses formatted and returned through transport | ||
|
||
## Development Guidelines | ||
|
||
### Adding New Tools | ||
|
||
- Create new tool file in `src/tools/` with Zod schema export | ||
- Import and register in `src/index.ts` main server setup | ||
- Add to destructive/non-destructive filtering logic as appropriate | ||
- Include comprehensive error handling for Kubernetes API failures | ||
|
||
### Testing Strategy | ||
|
||
- Unit tests focus on tool functionality and schema validation | ||
- Integration tests verify actual Kubernetes operations | ||
- Custom test sequencer ensures kubectl tests run last (they modify cluster state) | ||
- Tests require active Kubernetes cluster connection | ||
|
||
### Configuration Handling | ||
|
||
- Server loads kubeconfig from multiple sources: KUBECONFIG_YAML env var, KUBECONFIG path, or ~/.kube/config | ||
- Supports multiple kubectl contexts with context switching capabilities | ||
- Environment variables control server behavior (non-destructive mode, custom kubeconfig paths) | ||
|
||
## Kubernetes Integration Details | ||
|
||
The server requires: | ||
|
||
- kubectl installed and accessible in PATH | ||
- Valid kubeconfig with configured contexts | ||
- Active Kubernetes cluster connection | ||
- Helm v3 for chart operations (optional) | ||
|
||
**Non-destructive mode** disables: kubectl_delete, uninstall_helm_chart, cleanup operations, and kubectl_generic (which could contain destructive commands). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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