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
Merged
Show file tree
Hide file tree
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 Apr 22, 2025
308c2de
Add ExecInPodResponseSchema for executing commands in pods
rr-paras-patel Apr 22, 2025
b0c58d6
Add execInPod tool and schema for executing commands in pods
rr-paras-patel Apr 22, 2025
3128b65
Add shell option to execInPodSchema and enhance execInPod function fo…
rr-paras-patel Apr 23, 2025
8c816d2
Update exec_in_pod tests to use ExecInPodResponseSchema for response …
rr-paras-patel Apr 24, 2025
1dd9a28
Add timeout option to execInPodSchema and execInPod function for comm…
rr-paras-patel Apr 24, 2025
6b8c08a
Fix TypeScript errors in exec_in_pod tests and skip timeout-prone tests
rr-paras-patel May 16, 2025
12b86af
Add comprehensive unit tests for exec_in_pod functionality
rr-paras-patel May 16, 2025
e2edf0d
Adding DeepWiki link to readme & contributing
Flux159 Apr 29, 2025
1b65e21
Rename status to phase for list_pods
Flux159 Apr 24, 2025
264d09c
Bump version to 1.6.1
github-actions[bot] Apr 29, 2025
f3358f4
fix(CVE): jsonpath-plus
May 7, 2025
273c91b
Bump version to 1.6.2
github-actions[bot] May 7, 2025
68a7e17
Updates to support in-cluster configuration
ajit-pendse May 15, 2025
6381c17
Added unit test cases for isRunningInCluster
ajit-pendse May 15, 2025
3fcdb62
Added debug logs
ajit-pendse May 15, 2025
75164da
Refactor configmap.test.ts to use kubectl_create and fix test timeouts
rr-paras-patel May 16, 2025
b0b31d4
Add hookTimeout to vitest config for longer-running test hooks
rr-paras-patel May 16, 2025
1dc6280
Add unified kubectl command implementation for get, list, describe, a…
rr-paras-patel May 16, 2025
3313cd2
Add comprehensive tests for unified kubectl commands
rr-paras-patel May 16, 2025
130dce4
Update existing tests to use unified kubectl commands
rr-paras-patel May 16, 2025
b686e86
Integrate unified kubectl commands into server handler
rr-paras-patel May 16, 2025
61f519a
Add .vscode directory to .gitignore
rr-paras-patel May 16, 2025
bb15215
Update service tests to use kubectl-*.ts tools
rr-paras-patel May 16, 2025
48783a0
Enhance update service test to use more kubectl tools
rr-paras-patel May 16, 2025
dbb271b
Enhance delete service test to use multiple kubectl tools
rr-paras-patel May 16, 2025
d971c26
Replace create_service with kubectl_create in delete service test
rr-paras-patel May 16, 2025
4a90b0f
Update NodePort service test to use kubectl tools
rr-paras-patel May 16, 2025
6ed55fc
Update pod lifecycle management test to use kubectl-*.ts tools
rr-paras-patel May 17, 2025
a441b93
Update unit.test.ts to use kubectl-*.ts tools for namespaces, nodes, …
rr-paras-patel May 17, 2025
3d284b4
Update port_forward.test.ts to use kubectl-*.ts tools
rr-paras-patel May 17, 2025
31e2aea
Refactor helm tests to utilize kubectl tools for resource management
rr-paras-patel May 18, 2025
a2ad295
Update namespace.test.ts to use kubectl tools
rr-paras-patel May 18, 2025
d63111b
Update service.test.ts to use kubectl tools instead of direct service…
rr-paras-patel May 18, 2025
288333a
Update sse.test.ts to use kubectl_list instead of list_pods
rr-paras-patel May 18, 2025
877cd04
Replace last create_service with kubectl_create in service.test.ts
rr-paras-patel May 18, 2025
7db779d
Increase timeout for LoadBalancer service test
rr-paras-patel May 18, 2025
188b5d1
Replace create_service with kubectl_create in describe service test
rr-paras-patel May 18, 2025
7dabcd1
Simplify tools by replacing legacy APIs with kubectl-*.ts equivalents
rr-paras-patel May 18, 2025
494e981
Remove legacy tool implementations replaced by kubectl-*.ts equivalents
rr-paras-patel May 18, 2025
91b86bf
Remove legacy tools imports and reimplement tool handlers using kubec…
rr-paras-patel May 18, 2025
1251ff2
Delete remaining legacy tool implementations replaced by kubectl-*.ts…
rr-paras-patel May 18, 2025
09b33f9
Refactor index.ts to integrate kubectl_logs and kubectl_get, removing…
rr-paras-patel May 18, 2025
26e2e52
Consolidate context-related tools into kubectl-context.ts and events …
rr-paras-patel May 18, 2025
b99fe68
Refactor: Remove createDeploymentSchema as separate tool, using kubec…
rr-paras-patel May 18, 2025
2917329
Refactor: Remove legacy tools mapping to simplify the API
rr-paras-patel May 18, 2025
c9e2a88
Update test cases to use kubectl_context instead of legacy context tools
rr-paras-patel May 18, 2025
1a67832
Refactor tests to utilize asResponseSchema for response validation, e…
rr-paras-patel May 18, 2025
e288744
Refactor kubectl tests to use kubectl_get and kubectl_logs, updating …
rr-paras-patel May 18, 2025
8fbb1b9
Update README.md to reflect unified kubectl API structure
rr-paras-patel May 18, 2025
8639c63
Replace scale_deployment with kubectl-scale implementation following …
rr-paras-patel May 19, 2025
c559747
Add kubectl_generic, kubectl_patch, and kubectl_rollout implementatio…
rr-paras-patel May 19, 2025
73f37b3
Update README.md to document new kubectl commands
rr-paras-patel May 19, 2025
54d42cf
Add test files for kubectl-generic, kubectl-patch, and kubectl-rollou…
rr-paras-patel May 19, 2025
5149f97
Optimize test timeouts for faster execution: Reduce wait and retry in…
rr-paras-patel May 19, 2025
d71df3d
Remove deprecated scale_deployment command and related schemas; strea…
rr-paras-patel May 20, 2025
cceffd6
Bump version to 2.0.0
github-actions[bot] May 21, 2025
03a5848
Added Gitlab CI config
ajit-pendse May 21, 2025
8948d9c
Updated image repo name in CI
ajit-pendse May 21, 2025
97a2a58
Latest changes merged
ajit-pendse May 21, 2025
2afe39d
Removed console.log
ajit-pendse May 22, 2025
75b52e2
Bump version to 2.1.0
github-actions[bot] May 22, 2025
852d7c5
Enhance README.md with detailed documentation on non-destructive mode…
rr-paras-patel May 21, 2025
672e7ac
Update README.md to clarify the status of `kubectl_generic` in non-de…
rr-paras-patel May 21, 2025
ccd978b
fix: remove console.log calls that break stdio transport
aliou May 30, 2025
91bad09
Bump version to 2.1.1
github-actions[bot] May 30, 2025
d562af1
feat: Add comprehensive environment variable kubeconfig support with …
spo0nman May 29, 2025
10afb79
feat: add KUBECONFIG_PATH support and improve authentication document…
spo0nman May 30, 2025
def4705
Bump version to 2.2.0
github-actions[bot] May 30, 2025
4d97db2
Remove unnecessary esbuild
Flux159 May 30, 2025
41d4245
Bump version to 2.2.1
github-actions[bot] May 30, 2025
a1c07d1
feat: ensure kubectl works by writing kubeconfig to temp file if only…
spo0nman Jun 2, 2025
dde6601
fix: simplify kubeconfig handling and ensure kubectl env var inheritance
spo0nman Jun 5, 2025
6c859fd
feat: enhance kubeconfig handling by creating temp files from YAML an…
spo0nman Jun 5, 2025
53b4615
feat: prioritize KUBECONFIG_YAML over in-cluster config when explicit…
spo0nman Jun 5, 2025
56dab8b
fix: resolve test failures in KubernetesManager, kubectl, namespace, …
spo0nman Jun 5, 2025
43cf677
Cleanup of kubeconfig loading
Flux159 Jun 5, 2025
c798908
Bump version to 2.3.0
github-actions[bot] Jun 6, 2025
07c5202
Upgrading kubernetes/client-node
Flux159 Jun 11, 2025
9f7ea36
Bump version to 2.3.1
github-actions[bot] Jun 11, 2025
96105b1
Upgrade node image to fix Critical Vulnerabilities, also fix schema f…
kkambhat Jun 14, 2025
59797c9
Upgrade node image to fix Critical Vulnerabilities, also fix schema f…
kkambhat Jun 14, 2025
633beea
Address reviewers comment
kkambhat Jun 14, 2025
f7d4be0
Additional changes
kkambhat Jun 16, 2025
6a47a3c
Bump version to 2.4.0
github-actions[bot] Jun 17, 2025
66d5c3e
Adding support for HOST variable for sse transport
Flux159 Jun 17, 2025
39af5d3
Bump version to 2.4.1
github-actions[bot] Jun 17, 2025
03780d4
feat: add prompt handling for Kubernetes troubleshooting
rr-paras-patel Jun 16, 2025
e850556
Update README to include detailed information on the new k8s-troubles…
rr-paras-patel Jun 16, 2025
8bb2134
Enhance error handling for multi-container pods in kubectl-logs.ts an…
rr-paras-patel Jun 16, 2025
5c4efd3
Added default value for namespace in prompt registration to enhance u…
rr-paras-patel Jun 16, 2025
b810e30
Added default value for the 'namespace' field in prompt registration …
rr-paras-patel Jun 16, 2025
9d8794e
Update README to include advanced operations for Kubernetes managemen…
rr-paras-patel Jun 16, 2025
d0ac5fc
Refine troubleshooting prompts to include nodes in search criteria an…
rr-paras-patel Jun 16, 2025
0495f77
Enhance troubleshooting prompts to include detailed analysis for node…
rr-paras-patel Jun 16, 2025
843ce6b
Refine descriptions in k8s-troubleshoot prompt for clarity and consis…
rr-paras-patel Jun 16, 2025
18e1d5e
Update k8s-troubleshoot prompt to include custom resource definitions…
rr-paras-patel Jun 17, 2025
a30cbe0
Update default namespace in k8s-troubleshoot prompt from "monitoring"…
rr-paras-patel Jun 18, 2025
4983e32
Update tests/prompts.test.ts
rr-paras-patel Jun 19, 2025
77d0f73
Refactor tests/prompts.test.ts to improve test reliability by removin…
rr-paras-patel Jun 19, 2025
44f5b39
Bump version to 2.4.2
github-actions[bot] Jun 20, 2025
3b4bae1
Add execInPod tool and schema for executing commands in pods
rr-paras-patel Apr 22, 2025
8c67175
Add CLAUDE.md
rr-paras-patel Jun 22, 2025
94ad575
Update .gitignore to ignore editor files
rr-paras-patel Jun 22, 2025
23ecbb0
Merge branch 'main' into feat/add-exec-into-pod-method
rr-paras-patel Jun 22, 2025
0ddafca
Enhance kubectl toolset by adding imports for describe, list, apply, …
rr-paras-patel Jun 22, 2025
8c40dce
Add type definitions for input parameters in execInPod method to enha…
rr-paras-patel Jun 22, 2025
caa3e79
Remove unused imports in exec_in_pod.test.ts
rr-paras-patel Jun 22, 2025
80d4ea0
Remove unused imports from index.ts to clean up the codebase.
rr-paras-patel Jun 22, 2025
ed95e3d
Remove kubectl_list functionality and its associated schema from inde…
rr-paras-patel Jun 22, 2025
3966e37
Refactor tests to replace kubectl_list with kubectl_get for listing K…
rr-paras-patel Jun 22, 2025
729e1cf
Update README and tests to replace kubectl_list with kubectl_get, ens…
rr-paras-patel Jun 22, 2025
8290d0f
Refactor tests to consistently use kubectl_get instead of kubectl_lis…
rr-paras-patel Jun 22, 2025
8a6527a
Update tests to access resource names directly, removing unnecessary …
rr-paras-patel Jun 22, 2025
aaffa44
Enhance tests by adding checks for item existence in deployments, nod…
rr-paras-patel Jun 22, 2025
8752d78
Refactor service tests to implement proper response schemas, enhance …
rr-paras-patel Jun 22, 2025
6cb7c68
Enhance service deletion test by capturing response after deletion at…
rr-paras-patel Jun 22, 2025
edafde6
Rename troubleshooting prompt to `k8s-diagnose` in README and codebas…
rr-paras-patel Jun 23, 2025
3d52036
Update ADVANCED_README.md to include advanced Docker usage examples f…
rr-paras-patel Jun 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Ignore editor-specific directories and files
.cursor/
.vscode/
78 changes: 77 additions & 1 deletion ADVANCED_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,83 @@ Complete Example
Assuming your image name is flux159/mcp-server-kubernetes and you need to map ports and set environment parameters, you can run:

```shell
docker run --rm -it -p 3001:3001 -e ENABLE_UNSAFE_SSE_TRANSPORT=1 -e PORT=3001 -v ~/.kube/config:/home/appuser/.kube/config flux159/mcp-server-kubernetes
docker run --rm -it -p 3001:3001 -e ENABLE_UNSAFE_SSE_TRANSPORT=1 -e PORT=3001 -v ~/.kube/config:/home/appuser/.kube/config flux159/mcp-server-kubernetes:latest
```

## Advance Docker Usage

### Connect to AWS EKS Cluster

```json
{
"mcpServers": {
"kubernetes": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"~/.kube:/home/appuser/.kube:ro",
"-v",
"~/.aws:/home/appuser/.aws:ro",
"-e",
"AWS_PROFILE=default",
"-e",
"AWS_REGION=us-west-2",
"flux159/mcp-server-kubernetes:latest"
]
}
}
}
```

### 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"
]
}
}
}
```
Comment on lines +234 to +258
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


### Connect to Azure AKS Clusters

```json
{
"mcpServers": {
"kubernetes": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"~/.kube:/home/appuser/.kube:ro",
"-e",
"AZURE_SUBSCRIPTION=my-subscription-id",
"flux159/mcp-server-kubernetes:latest"
]
}
}
}
```

⚠️ Key safety considerations
Expand Down
90 changes: 90 additions & 0 deletions CLAUDE.md
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).
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
- [x] Unified kubectl API for managing resources
- Get or list resources with `kubectl_get`
- Describe resources with `kubectl_describe`
- List resources with `kubectl_list`
- List resources with `kubectl_get`
- Create resources with `kubectl_create`
- Apply YAML manifests with `kubectl_apply`
- Delete resources with `kubectl_delete`
Expand All @@ -89,15 +89,15 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
- Run Helm operations
- Install, upgrade, and uninstall charts
- Support for custom values, repositories, and versions
- [x] Troubleshooting Prompt (`k8s-troubleshoot`)
- [x] Troubleshooting Prompt (`k8s-diagnose`)
- Guides through a systematic Kubernetes troubleshooting flow for pods based on a keyword and optional namespace.
- [x] Non-destructive mode for read and create/update-only access to clusters

## Prompts

The MCP Kubernetes server includes specialized prompts to assist with common operations.
The MCP Kubernetes server includes specialized prompts to assist with common diagnostic operations.

### k8s-troubleshoot Prompt
### k8s-diagnose Prompt

This prompt provides a systematic troubleshooting flow for Kubernetes pods. It accepts a `keyword` to identify relevant pods and an optional `namespace` to narrow the search.
The prompt's output will guide you through an autonomous troubleshooting flow, providing instructions for identifying issues, collecting evidence, and suggesting remediation steps.
Expand Down Expand Up @@ -192,7 +192,7 @@ For Claude Desktop configuration with non-destructive mode:

All read-only and resource creation/update operations remain available:

- Resource Information: `kubectl_get`, `kubectl_describe`, `kubectl_list`, `kubectl_logs`, `explain_resource`, `list_api_resources`
- Resource Information: `kubectl_get`, `kubectl_describe`, `kubectl_logs`, `explain_resource`, `list_api_resources`
- Resource Creation/Modification: `kubectl_apply`, `kubectl_create`, `kubectl_scale`, `kubectl_patch`, `kubectl_rollout`
- Helm Operations: `install_helm_chart`, `upgrade_helm_chart`
- Connectivity: `port_forward`, `stop_port_forward`
Expand Down
33 changes: 16 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
listApiResources,
listApiResourcesSchema,
} from "./tools/kubectl-operations.js";
import { execInPod, execInPodSchema } from "./tools/exec_in_pod.js";
import { getResourceHandlers } from "./resources/handlers.js";
import {
ListResourcesRequestSchema,
Expand Down Expand Up @@ -44,7 +45,6 @@ import {
kubectlDescribe,
kubectlDescribeSchema,
} from "./tools/kubectl-describe.js";
import { kubectlList, kubectlListSchema } from "./tools/kubectl-list.js";
import { kubectlApply, kubectlApplySchema } from "./tools/kubectl-apply.js";
import { kubectlDelete, kubectlDeleteSchema } from "./tools/kubectl-delete.js";
import { kubectlCreate, kubectlCreateSchema } from "./tools/kubectl-create.js";
Expand Down Expand Up @@ -80,7 +80,6 @@ const allTools = [
// Unified kubectl-style tools - these replace many specific tools
kubectlGetSchema,
kubectlDescribeSchema,
kubectlListSchema,
kubectlApplySchema,
kubectlDeleteSchema,
kubectlCreateSchema,
Expand All @@ -103,10 +102,11 @@ const allTools = [
// Port forwarding
PortForwardSchema,
StopPortForwardSchema,
execInPodSchema,


// API resource operations
listApiResourcesSchema,

// Generic kubectl command
kubectlGenericSchema,
];
Expand Down Expand Up @@ -187,6 +187,7 @@ server.setRequestHandler(
allNamespaces?: boolean;
labelSelector?: string;
fieldSelector?: string;
sortBy?: string;
}
);
}
Expand All @@ -203,20 +204,6 @@ server.setRequestHandler(
);
}

if (name === "kubectl_list") {
return await kubectlList(
k8sManager,
input as {
resourceType: string;
namespace?: string;
output?: string;
allNamespaces?: boolean;
labelSelector?: string;
fieldSelector?: string;
}
);
}

if (name === "kubectl_apply") {
return await kubectlApply(
k8sManager,
Expand Down Expand Up @@ -451,6 +438,18 @@ server.setRequestHandler(
);
}

case "exec_in_pod": {
return await execInPod(
k8sManager,
input as {
name: string;
namespace?: string;
command: string | string[];
container?: string;
}
);
}

default:
throw new McpError(ErrorCode.InvalidRequest, `Unknown tool: ${name}`);
}
Expand Down
4 changes: 4 additions & 0 deletions src/models/response-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ export const SetCurrentContextResponseSchema = z.object({
export const DescribeNodeResponseSchema = z.object({
content: z.array(ToolResponseContent),
});

export const ExecInPodResponseSchema = z.object({
content: z.array(ToolResponseContent),
});
15 changes: 6 additions & 9 deletions src/prompts/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { KubernetesManager } from "../types.js";
import { ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { kubectlList } from "../tools/kubectl-list.js";
import { kubectlDescribe } from "../tools/kubectl-describe.js";
import { kubectlLogs } from "../tools/kubectl-logs.js";

export function registerPromptHandlers(server: Server, k8sManager: KubernetesManager) {
// Register prompts list handler
server.setRequestHandler(ListPromptsRequestSchema, async () => {
return {
prompts: [
{
name: "k8s-troubleshoot",
description: "Troubleshoot Kubernetes Resources.",
name: "k8s-diagnose",
description: "Diagnose Kubernetes Resources.",
arguments: [
{
name: "keyword",
Expand All @@ -35,18 +32,18 @@ export function registerPromptHandlers(server: Server, k8sManager: KubernetesMan
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
const { name, arguments: args } = request.params;

if (name === "k8s-troubleshoot") {
if (name === "k8s-diagnose") {
const keyword = args?.keyword as string;
const namespace = args?.namespace as string;

if (!keyword) {
throw new Error("Keyword parameter is required for k8s-troubleshoot prompt");
throw new Error("Keyword parameter is required for k8s-diagnose prompt");
}

const actualNamespace = namespace || "all";
const message = `Troubleshooting for resources (pods, nodes, etc.) containing keyword "${keyword}" in their names within namespace "${actualNamespace}" (or across all namespaces if specified) for this investigation:
const message = `Diagnose Kubernetes resources (pods, nodes, etc.) containing keyword "${keyword}" in their names within namespace "${actualNamespace}" (or across all namespaces if specified) for this investigation:

**Autonomous Kubernetes Troubleshooting Flow**
**Autonomous Kubernetes Diagnosis Flow**

0. **Perform Quick Health Checks / Golden Signals Analysis**
- Assess latency, errors, and resource utilization. If a clear issue is identified (e.g., node not ready, network partition), streamline or deprioritize subsequent detailed steps.
Expand Down
Loading