Skip to main content
Glama
TaichiHo

k8s-interactive-mcp

by TaichiHo

run_kubectl_command

Execute kubectl commands on a Kubernetes cluster by specifying the kubeconfig file and the desired command, enabling direct cluster interaction through the MCP server.

Instructions

Run a kubectl command against the cluster pointed to by the current kubeconfig

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe kubectl command to run. It should also include the 'kubectl' prefix.
kubeconfigYesPath to the kubeconfig file

Implementation Reference

  • Executes the run_kubectl_command tool by instantiating Kubectl with kubeconfig, running the provided command, and returning the result as text.
    case "run_kubectl_command": {
      const kubeconfig = String(request.params.arguments?.kubeconfig);
      if (!kubeconfig) {
        throw new Error("Kubeconfig is required");
      }
      const kubectl = new Kubectl(kubeconfig);
      const result = await kubectl.run(String(request.params.arguments?.command));
    
      return {
        content: [{
          type: "text",
          text: `title: ${result.title}\noutput: ${result.output}`,
        }]
      };
    }
  • Defines the input schema for the run_kubectl_command tool, specifying kubeconfig and command as required string parameters.
    inputSchema: {
      type: "object",
      properties: {
        kubeconfig: {
          type: "string",
          description: "Path to the kubeconfig file"
        },
        command: {
          type: "string",
          description: "The kubectl command to run. It should also include the 'kubectl' prefix."
        }
      },
      required: ["kubeconfig", "command"]
    }
  • src/index.ts:108-131 (registration)
    Registers the run_kubectl_command tool by including it in the list of available tools with name, description, and input schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "run_kubectl_command",
            description: "Run a kubectl command against the cluster pointed to by the current kubeconfig",
            inputSchema: {
              type: "object",
              properties: {
                kubeconfig: {
                  type: "string",
                  description: "Path to the kubeconfig file"
                },
                command: {
                  type: "string",
                  description: "The kubectl command to run. It should also include the 'kubectl' prefix."
                }
              },
              required: ["kubeconfig", "command"]
            }
          }
        ]
      };
    });
  • Helper class Kubectl that handles execution of kubectl commands via child_process.exec, setting KUBECONFIG env var, checking for kubectl availability, and formatting output with title and output.
    export class Kubectl {
      private kubeconfig: string;
    
      constructor(kubeconfig: string) {
        this.kubeconfig = kubeconfig;
      }
    
      async run(command?: string): Promise<{ title: string; output: string }> {
        if (!command) {
          throw new Error('Command is required');
        }
    
        try {
          // First check if kubectl is installed
          try {
            await execAsync('which kubectl');
          } catch (error) {
            return {
              title: 'kubectl not found',
              output: 'kubectl is not installed or not in PATH. Please install kubectl first: https://kubernetes.io/docs/tasks/tools/'
            };
          }
    
          const { stdout, stderr } = await execAsync(`KUBECONFIG=${this.kubeconfig} ${command}`);
          return {
            title: `${command}`,
            output: stdout || stderr
          };
        } catch (error) {
          if (error instanceof Error) {
            return {
              title: `${command} (error)`,
              output: error.message
            };
          }
          throw error;
        }
      }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions running a command against a cluster but fails to disclose critical traits like whether this is a read-only or destructive operation, potential security implications, error handling, or output format. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It is appropriately sized and front-loaded, with every part contributing essential information, earning a top score for conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of running kubectl commands (which can be destructive or require specific permissions), the lack of annotations and output schema, and the description's failure to address behavioral traits, the description is incomplete. It does not provide enough context for safe or effective use by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning the input schema already documents both parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as examples or constraints on the command format. Thus, it meets the baseline score of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Run a kubectl command') and the target ('against the cluster pointed to by the current kubeconfig'), providing a specific verb+resource combination. However, since there are no sibling tools mentioned, it cannot demonstrate differentiation from alternatives, which prevents a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives or any prerequisites for its use. It lacks explicit context about scenarios where this tool is appropriate, such as for administrative tasks or debugging, leaving the agent without usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TaichiHo/k8s-interactive-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server