Skip to main content
Glama
Flux159
by Flux159

explain_resource

Get documentation for Kubernetes resources or fields to understand their structure and usage in cluster operations.

Instructions

Get documentation for a Kubernetes resource or field

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceYesResource name or field path (e.g. 'pods' or 'pods.spec.containers')
apiVersionNoAPI version to use (e.g. 'apps/v1')
recursiveNoPrint the fields of fields recursively
contextNoKubeconfig Context to use for the command (optional - defaults to null)
outputNoOutput format (plaintext or plaintext-openapiv2)plaintext

Implementation Reference

  • The main handler function that implements the 'explain_resource' tool. It constructs and executes a 'kubectl explain' command using the provided parameters and returns the output as MCP content.
    export async function explainResource(
      params: ExplainResourceParams
    ): Promise<{ content: { type: string; text: string }[] }> {
      try {
        const command = "kubectl";
        const args = ["explain"];
    
        if (params.apiVersion) {
          args.push(`--api-version=${params.apiVersion}`);
        }
    
        if (params.recursive) {
          args.push("--recursive");
        }
    
        if (params.context) {
          args.push("--context", params.context);
        }
    
        if (params.output) {
          args.push(`--output=${params.output}`);
        }
    
        args.push(params.resource);
    
        const result = executeKubectlCommand(command, args);
    
        return {
          content: [
            {
              type: "text",
              text: result,
            },
          ],
        };
      } catch (error: any) {
        throw new Error(`Failed to explain resource: ${error.message}`);
      }
    }
  • The schema definition for the 'explain_resource' tool, specifying input parameters, description, and annotations.
    export const explainResourceSchema = {
      name: "explain_resource",
      description: "Get documentation for a Kubernetes resource or field",
      annotations: {
        readOnlyHint: true,
      },
      inputSchema: {
        type: "object",
        properties: {
          resource: {
            type: "string",
            description:
              "Resource name or field path (e.g. 'pods' or 'pods.spec.containers')",
          },
          apiVersion: {
            type: "string",
            description: "API version to use (e.g. 'apps/v1')",
          },
          recursive: {
            type: "boolean",
            description: "Print the fields of fields recursively",
            default: false,
          },
          context: contextParameter,
          output: {
            type: "string",
            description: "Output format (plaintext or plaintext-openapiv2)",
            enum: ["plaintext", "plaintext-openapiv2"],
            default: "plaintext",
          },
        },
        required: ["resource"],
      },
    };
  • TypeScript interface defining the input parameters for the explain_resource handler function.
    export interface ExplainResourceParams {
      resource: string;
      apiVersion?: string;
      recursive?: boolean;
      output?: "plaintext" | "plaintext-openapiv2";
      context?: string;
    }
  • src/index.ts:400-410 (registration)
    Registration and dispatching of the 'explain_resource' tool in the main CallToolRequest handler switch statement.
    case "explain_resource": {
      return await explainResource(
        input as {
          context?: string;
          resource: string;
          apiVersion?: string;
          recursive?: boolean;
          output?: "plaintext" | "plaintext-openapiv2";
        }
      );
    }
  • src/index.ts:20-24 (registration)
    Import of the explainResource handler and explainResourceSchema into the main index file.
      explainResource,
      explainResourceSchema,
      listApiResources,
      listApiResourcesSchema,
    } from "./tools/kubectl-operations.js";

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/Flux159/mcp-server-kubernetes'

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