list_api_resources
Discover available Kubernetes API resources in your cluster to understand what operations you can perform. Filter by API group, namespaced status, or supported verbs to find specific resources for managing deployments, pods, and services.
Instructions
List the API resources available in the cluster
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiGroup | No | API group to filter by | |
| namespaced | No | If true, only show namespaced resources | |
| context | No | Kubeconfig Context to use for the command (optional - defaults to null) | |
| verbs | No | List of verbs to filter by | |
| output | No | Output format (wide, name, or no-headers) | wide |
Implementation Reference
- src/tools/kubectl-operations.ts:136-176 (handler)The main handler function that constructs and executes the 'kubectl api-resources' command based on input parameters and returns the formatted output as MCP content.export async function listApiResources( params: ListApiResourcesParams ): Promise<{ content: { type: string; text: string }[] }> { try { const command = "kubectl"; const args = ["api-resources"]; if (params.apiGroup) { args.push(`--api-group=${params.apiGroup}`); } if (params.namespaced !== undefined) { args.push(`--namespaced=${params.namespaced}`); } if (params.verbs && params.verbs.length > 0) { args.push(`--verbs=${params.verbs.join(",")}`); } if (params.output) { args.push(`-o`, params.output); } if (params.context) { args.push("--context", params.context); } const result = executeKubectlCommand(command, args); return { content: [ { type: "text", text: result, }, ], }; } catch (error: any) { throw new Error(`Failed to list API resources: ${error.message}`); } }
- The MCP tool schema defining the name, description, annotations, and input schema for the list_api_resources tool.export const listApiResourcesSchema = { name: "list_api_resources", description: "List the API resources available in the cluster", annotations: { readOnlyHint: true, }, inputSchema: { type: "object", properties: { apiGroup: { type: "string", description: "API group to filter by", }, namespaced: { type: "boolean", description: "If true, only show namespaced resources", }, context: { type: "string", description: "Kubeconfig Context to use for the command (optional - defaults to null)", default: "", }, verbs: { type: "array", items: { type: "string", }, description: "List of verbs to filter by", }, output: { type: "string", description: "Output format (wide, name, or no-headers)", enum: ["wide", "name", "no-headers"], default: "wide", }, }, }, };
- src/index.ts:468-478 (registration)The dispatch case in the CallToolRequestSchema handler that invokes the listApiResources handler function.case "list_api_resources": { return await listApiResources( input as { apiGroup?: string; namespaced?: boolean; verbs?: string[]; output?: "wide" | "name" | "no-headers"; context?: string; } ); }
- src/models/kubectl-models.ts:20-26 (schema)TypeScript interface defining the parameters for the listApiResources function.export interface ListApiResourcesParams { apiGroup?: string; namespaced?: boolean; verbs?: string[]; output?: "wide" | "name" | "no-headers"; context?: string; }