Skip to content

Commit dc67def

Browse files
committed
array input parsing
Signed-off-by: Shoumi <[email protected]>
1 parent 2f269c9 commit dc67def

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

mcpgateway/static/admin.js

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,49 +3535,36 @@ async function runToolTest() {
35353535
const inputValues = formData.getAll(key);
35363536
try {
35373537
// Convert values based on the items schema type
3538-
if (prop.items && prop.items.type) {
3539-
switch (prop.items.type) {
3540-
case "object":
3541-
value = inputValues.map((v) => {
3542-
try {
3543-
const parsed = JSON.parse(v);
3544-
if (
3545-
typeof parsed !== "object" ||
3546-
Array.isArray(parsed)
3547-
) {
3548-
throw new Error(
3549-
`Value must be an object, got ${typeof parsed}`,
3550-
);
3551-
}
3552-
return parsed;
3553-
} catch (e) {
3554-
console.error(
3555-
`Error parsing object for ${key}:`,
3556-
e,
3557-
);
3558-
throw new Error(
3559-
`Invalid object format for ${key}. Each item must be a valid JSON object.`,
3560-
);
3538+
if (prop.items) {
3539+
const itemType = Array.isArray(prop.items.anyOf)
3540+
? prop.items.anyOf.map(t => t.type)
3541+
: [prop.items.type];
3542+
3543+
if (itemType.includes("number") || itemType.includes("integer")) {
3544+
value = inputValues.map((v) => {
3545+
const num = Number(v);
3546+
if (isNaN(num)) {
3547+
throw new Error(`Invalid number: ${v}`);
3548+
}
3549+
return num;
3550+
});
3551+
} else if (itemType.includes("boolean")) {
3552+
value = inputValues.map(v => v === "true" || v === true);
3553+
} else if (itemType.includes("object")) {
3554+
value = inputValues.map((v) => {
3555+
try {
3556+
const parsed = JSON.parse(v);
3557+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
3558+
throw new Error(`Value must be an object`);
35613559
}
3562-
});
3563-
break;
3564-
case "number":
3565-
value = inputValues.map((v) =>
3566-
v === "" ? null : Number(v),
3567-
);
3568-
break;
3569-
case "boolean":
3570-
value = inputValues.map(
3571-
(v) => v === "true" || v === true,
3572-
);
3573-
break;
3574-
default:
3575-
// For other types (like strings), use raw values
3576-
value = inputValues;
3560+
return parsed;
3561+
} catch {
3562+
throw new Error(`Invalid object format for ${key}`);
3563+
}
3564+
});
3565+
} else {
3566+
value = inputValues;
35773567
}
3578-
} else {
3579-
// If no items type specified, use raw values
3580-
value = inputValues;
35813568
}
35823569

35833570
// Handle empty values

0 commit comments

Comments
 (0)