exec
Execute commands directly in Kubernetes pod containers to run diagnostics, perform maintenance, or troubleshoot applications within your cluster.
Instructions
Execute a command in a pod container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pod | Yes | The name of the pod to execute in | |
| command | Yes | The command to execute | |
| namespace | No | The namespace of the pod (optional, defaults to current context namespace) | |
| container | No | The container name to execute in (if pod has multiple containers) |
Implementation Reference
- server.js:1716-1725 (handler)The handler for the 'exec' tool. It destructures the input arguments, builds a kubectl exec command with optional namespace and container flags, executes it using execAsync (promisified child_process.exec), and returns the stdout in the MCP response format.case "exec": { const { pod, command, namespace, container } = args; const nsArg = namespace ? `-n ${namespace}` : ""; const containerArg = container ? `-c ${container}` : ""; const cmd = `kubectl exec ${pod} ${nsArg} ${containerArg} -- ${command}`; const { stdout } = await execAsync(cmd); return { content: [{ type: "text", text: stdout || "Command executed" }] }; }
- server.js:507-532 (schema)The JSON schema definition for the 'exec' tool, including name, description, and inputSchema with properties for pod, command, optional namespace and container, requiring pod and command.{ name: "exec", description: "Execute a command in a pod container", inputSchema: { type: "object", properties: { pod: { type: "string", description: "The name of the pod to execute in" }, command: { type: "string", description: "The command to execute" }, namespace: { type: "string", description: "The namespace of the pod (optional, defaults to current context namespace)" }, container: { type: "string", description: "The container name to execute in (if pod has multiple containers)" } }, required: ["pod", "command"] } },
- server.js:1392-1394 (registration)Registration via the ListToolsRequestHandler which returns the full list of tools including the 'exec' tool schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
- server.js:7-7 (helper)Helper function execAsync created by promisifying Node.js child_process.exec, used by all tool handlers including 'exec' to run kubectl commands.const execAsync = promisify(exec);