Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 60 additions & 44 deletions mcpgateway/static/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3348,9 +3348,19 @@ async function testTool(toolId) {
input.className =
"mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 text-gray-700 dark:text-gray-300 dark:border-gray-700 dark:focus:border-indigo-400 dark:focus:ring-indigo-400";

if (prop.items?.type === "number") {
const itemTypes = Array.isArray(prop.items?.anyOf)
? prop.items.anyOf.map((t) => t.type)
: [prop.items?.type];

if (
itemTypes.includes("number") ||
itemTypes.includes("integer")
) {
input.type = "number";
} else if (prop.items?.type === "boolean") {
input.step = itemTypes.includes("integer")
? "1"
: "any";
} else if (itemTypes.includes("boolean")) {
input.type = "checkbox";
input.value = "true";
input.checked = value === true || value === "true";
Expand Down Expand Up @@ -3390,9 +3400,16 @@ async function testTool(toolId) {
});

if (Array.isArray(prop.default)) {
prop.default.forEach((val) => {
arrayContainer.appendChild(createArrayInput(val));
});
if (prop.default.length > 0) {
prop.default.forEach((val) => {
arrayContainer.appendChild(
createArrayInput(val),
);
});
} else {
// Create one empty input for empty default arrays
arrayContainer.appendChild(createArrayInput());
}
} else {
arrayContainer.appendChild(createArrayInput());
}
Expand Down Expand Up @@ -3535,49 +3552,48 @@ async function runToolTest() {
const inputValues = formData.getAll(key);
try {
// Convert values based on the items schema type
if (prop.items && prop.items.type) {
switch (prop.items.type) {
case "object":
value = inputValues.map((v) => {
try {
const parsed = JSON.parse(v);
if (
typeof parsed !== "object" ||
Array.isArray(parsed)
) {
throw new Error(
`Value must be an object, got ${typeof parsed}`,
);
}
return parsed;
} catch (e) {
console.error(
`Error parsing object for ${key}:`,
e,
);
if (prop.items) {
const itemType = Array.isArray(prop.items.anyOf)
? prop.items.anyOf.map((t) => t.type)
: [prop.items.type];

if (
itemType.includes("number") ||
itemType.includes("integer")
) {
value = inputValues.map((v) => {
const num = Number(v);
if (isNaN(num)) {
throw new Error(`Invalid number: ${v}`);
}
return num;
});
} else if (itemType.includes("boolean")) {
value = inputValues.map(
(v) => v === "true" || v === true,
);
} else if (itemType.includes("object")) {
value = inputValues.map((v) => {
try {
const parsed = JSON.parse(v);
if (
typeof parsed !== "object" ||
Array.isArray(parsed)
) {
throw new Error(
`Invalid object format for ${key}. Each item must be a valid JSON object.`,
"Value must be an object",
);
}
});
break;
case "number":
value = inputValues.map((v) =>
v === "" ? null : Number(v),
);
break;
case "boolean":
value = inputValues.map(
(v) => v === "true" || v === true,
);
break;
default:
// For other types (like strings), use raw values
value = inputValues;
return parsed;
} catch {
throw new Error(
`Invalid object format for ${key}`,
);
}
});
} else {
value = inputValues;
}
} else {
// If no items type specified, use raw values
value = inputValues;
}

// Handle empty values
Expand Down
Loading