patch
Apply partial updates to Kubernetes resources using JSON or YAML patches to modify configurations without redeploying entire resources.
Instructions
Patch a Kubernetes resource
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| resource | Yes | The resource type | |
| name | Yes | The name of the resource | |
| patch | Yes | The patch to apply (JSON or YAML) | |
| type | No | The patch type (strategic, merge, json) | |
| namespace | No | The namespace of the resource (optional, defaults to current context namespace) |
Implementation Reference
- server.js:2050-2058 (handler)The handler function for the "patch" tool. It destructures the arguments, constructs a `kubectl patch` command using the provided resource type, name, patch content, patch type (defaulting to 'strategic'), and optional namespace, executes it via execAsync, and returns the stdout or a success message.case "patch": { const { resource, name, patch, type = "strategic", namespace } = args; const nsArg = namespace ? `-n ${namespace}` : ""; const cmd = `kubectl patch ${resource} ${name} --type=${type} -p '${patch}' ${nsArg}`; const { stdout } = await execAsync(cmd); return { content: [{ type: "text", text: stdout || `${resource} ${name} patched successfully` }] }; }
- server.js:1011-1038 (schema)The tool definition including name, description, and inputSchema for validating the arguments: resource (string), name (string), patch (string), type (string, optional), namespace (string, optional). Required: resource, name, patch.name: "patch", description: "Patch a Kubernetes resource", inputSchema: { type: "object", properties: { resource: { type: "string", description: "The resource type" }, name: { type: "string", description: "The name of the resource" }, patch: { type: "string", description: "The patch to apply (JSON or YAML)" }, type: { type: "string", description: "The patch type (strategic, merge, json)" }, namespace: { type: "string", description: "The namespace of the resource (optional, defaults to current context namespace)" } }, required: ["resource", "name", "patch"] }
- server.js:1392-1394 (registration)The request handler for listing tools, which returns the 'tools' array containing the 'patch' tool definition.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });