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
| Name | Required | Description | Default |
|---|---|---|---|
| resource | Yes | Resource name or field path (e.g. 'pods' or 'pods.spec.containers') | |
| apiVersion | No | API version to use (e.g. 'apps/v1') | |
| recursive | No | Print the fields of fields recursively | |
| context | No | Kubeconfig Context to use for the command (optional - defaults to null) | |
| output | No | Output format (plaintext or plaintext-openapiv2) | plaintext |
Implementation Reference
- src/tools/kubectl-operations.ts:96-134 (handler)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}`); } }
- src/tools/kubectl-operations.ts:9-42 (schema)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"], }, };
- src/models/kubectl-models.ts:12-18 (schema)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";