Skip to content

Commit 984df0d

Browse files
committed
Throw error if kubectl patch receives a string instead of object
Summary: Test Plan:
1 parent 48e5065 commit 984df0d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/tools/kubectl-patch.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import * as fs from "fs";
55
import * as path from "path";
66
import * as os from "os";
77
import { getSpawnMaxBuffer } from "../config/max-buffer.js";
8-
import { contextParameter, dryRunParameter, namespaceParameter } from "../models/common-parameters.js";
8+
import {
9+
contextParameter,
10+
dryRunParameter,
11+
namespaceParameter,
12+
} from "../models/common-parameters.js";
913

1014
export const kubectlPatchSchema = {
1115
name: "kubectl_patch",
@@ -93,6 +97,13 @@ export async function kubectlPatch(
9397

9498
// Handle patch data
9599
if (input.patchData) {
100+
if (input.patchData === null || typeof input.patchData !== "object") {
101+
throw new McpError(
102+
ErrorCode.InvalidRequest,
103+
"patchData must be a valid JSON object, not a string."
104+
);
105+
}
106+
96107
// Create a temporary file for the patch data
97108
const tmpDir = os.tmpdir();
98109
tempFile = path.join(tmpDir, `patch-${Date.now()}.json`);

0 commit comments

Comments
 (0)