From c7bd6a567fd9e1174ca0b00f8ca93397088f62c1 Mon Sep 17 00:00:00 2001 From: Shoumi Date: Wed, 30 Jul 2025 15:29:47 +0530 Subject: [PATCH 1/2] fix for tool input issue Signed-off-by: Shoumi --- mcpgateway/static/admin.js | 58 ++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 9ee4d95ec..057196998 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -3507,19 +3507,53 @@ async function runToolTest() { } let value; if (prop.type === "array") { - value = formData.getAll(key); - if (prop.items && prop.items.type === "number") { - value = value.map((v) => (v === "" ? null : Number(v))); - } else if (prop.items && prop.items.type === "boolean") { - value = value.map((v) => v === "true" || v === true); - } - if ( - value.length === 0 || - (value.length === 1 && value[0] === "") - ) { - continue; + let 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); + throw new Error(`Invalid object format for ${key}. Each item must be a valid JSON 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; + } + } else { + // If no items type specified, use raw values + value = inputValues; + } + + // Handle empty values + if (value.length === 0 || (value.length === 1 && value[0] === "")) { + if (schema.required && schema.required.includes(key)) { + params[keyValidation.value] = []; + } + continue; + } + params[keyValidation.value] = value; + } catch (error) { + console.error(`Error parsing array values for ${key}:`, error); + showErrorMessage(`Invalid input format for ${key}. Please check the values are in correct format.`); + throw error; } - params[keyValidation.value] = value; } else { value = formData.get(key); if (value === null || value === undefined || value === "") { From 0f36bda2286174ea42c93fee499ecba450c03d7c Mon Sep 17 00:00:00 2001 From: Madhav Kandukuri Date: Wed, 30 Jul 2025 20:14:58 +0530 Subject: [PATCH 2/2] lint-web fixes Signed-off-by: Madhav Kandukuri --- mcpgateway/static/admin.js | 49 ++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 057196998..f9ace620a 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -3507,30 +3507,44 @@ async function runToolTest() { } let value; if (prop.type === "array") { - let inputValues = formData.getAll(key); + 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 => { + 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}`); + 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); - throw new Error(`Invalid object format for ${key}. Each item must be a valid JSON object.`); + console.error( + `Error parsing object for ${key}:`, + e, + ); + throw new Error( + `Invalid object format for ${key}. Each item must be a valid JSON object.`, + ); } }); break; case "number": - value = inputValues.map(v => v === "" ? null : Number(v)); + value = inputValues.map((v) => + v === "" ? null : Number(v), + ); break; case "boolean": - value = inputValues.map(v => v === "true" || v === true); + value = inputValues.map( + (v) => v === "true" || v === true, + ); break; default: // For other types (like strings), use raw values @@ -3542,16 +3556,27 @@ async function runToolTest() { } // Handle empty values - if (value.length === 0 || (value.length === 1 && value[0] === "")) { - if (schema.required && schema.required.includes(key)) { + if ( + value.length === 0 || + (value.length === 1 && value[0] === "") + ) { + if ( + schema.required && + schema.required.includes(key) + ) { params[keyValidation.value] = []; } continue; } params[keyValidation.value] = value; } catch (error) { - console.error(`Error parsing array values for ${key}:`, error); - showErrorMessage(`Invalid input format for ${key}. Please check the values are in correct format.`); + console.error( + `Error parsing array values for ${key}:`, + error, + ); + showErrorMessage( + `Invalid input format for ${key}. Please check the values are in correct format.`, + ); throw error; } } else {