- {Object.entries(actualSchema.properties).map(([key, prop]) => (
-
- {key} {actualSchema.required?.includes(key) && *}
- {prop.description && (
-
-
-
- )}
-
- }
- name={key}
- rules={[
- {
- required: actualSchema.required?.includes(key),
+ {Object.entries(actualSchema.properties).map(([key, prop]) => {
+ const initialValue = getInitialValueForField(prop);
+ const fieldKey = `${tool.name}-${key}`;
+ return (
+
+ {key} {actualSchema.required?.includes(key) && *}
+ {prop.description && (
+
+
+
+ )}
+
+ }
+ name={key}
+ initialValue={initialValue}
+ rules={[
+ {
+ required: actualSchema.required?.includes(key),
message: `Please enter ${key}`,
},
+ ...(prop.type === "object" || prop.type === "array"
+ ? [
+ {
+ validator: (_rule: any, value: any) => {
+ if (
+ (value === undefined || value === null || value === "") &&
+ !actualSchema.required?.includes(key)
+ ) {
+ return Promise.resolve();
+ }
+
+ try {
+ const parsed = typeof value === "string" ? JSON.parse(value) : value;
+ const isValidObject =
+ prop.type === "object" &&
+ parsed !== null &&
+ typeof parsed === "object" &&
+ !Array.isArray(parsed);
+ const isValidArray = prop.type === "array" && Array.isArray(parsed);
+
+ if ((prop.type === "object" && isValidObject) || (prop.type === "array" && isValidArray)) {
+ return Promise.resolve();
+ }
+
+ return Promise.reject(
+ new Error(
+ prop.type === "object"
+ ? "Please enter a JSON object"
+ : "Please enter a JSON array",
+ ),
+ );
+ } catch (error) {
+ return Promise.reject(new Error("Invalid JSON"));
+ }
+ },
+ },
+ ]
+ : []),
]}
- className="mb-3"
- >
- {prop.type === "string" && prop.enum && (
-
- )}
+ className="mb-3"
+ >
+ {prop.type === "string" && prop.enum && (
+
+ )}
- {prop.type === "string" && !prop.enum && (
-
- )}
+ {prop.type === "string" && !prop.enum && (
+
+ )}
- {prop.type === "number" && (
-
- )}
+ {(prop.type === "number" || prop.type === "integer") && (
+
+ )}
- {prop.type === "boolean" && (
-
- )}
-
- ))}
+ {prop.type === "boolean" && (
+
+ )}
+
+ {(prop.type === "object" || prop.type === "array") && (
+
+
+
+ {prop.type === "object"
+ ? "Provide a valid JSON object."
+ : "Provide a valid JSON array."}
+
+
+ )}
+
+ );
+ })}
)}
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/types.tsx b/ui/litellm-dashboard/src/components/mcp_tools/types.tsx
index fd19a23a8b..95632e28dc 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/types.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/types.tsx
@@ -43,6 +43,7 @@ export interface InputSchemaProperty {
required?: string[]; // For required fields in nested objects
enum?: string[]; // For enum values
default?: any; // For default values
+ items?: InputSchemaProperty | InputSchemaProperty[]; // For array item schemas
}
// Define the structure for the input schema of a tool