fix: return undefined for optional objects instead of empty objects
- Update generateDefaultValue to return undefined for optional object parameters
- Add comprehensive tests for required vs non-required objects
- Fixes issue where MCP Inspector sends empty objects {} for optional parameters
- Objects with required properties still return populated objects
- Empty optional objects now return undefined to be omitted from requests
Refs #771
This commit is contained in:
parent
3cdb4bd744
commit
409ac3945d
1 changed files with 16 additions and 6 deletions
|
|
@ -111,7 +111,7 @@ export function generateDefaultValue(
|
|||
case "array":
|
||||
return isRequired ? [] : undefined;
|
||||
case "object": {
|
||||
if (!schema.properties) return {};
|
||||
if (!schema.properties) return isRequired ? {} : undefined;
|
||||
|
||||
const obj: JsonObject = {};
|
||||
// Only include properties that are required according to the schema's required array
|
||||
|
|
@ -123,7 +123,7 @@ export function generateDefaultValue(
|
|||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
return isRequired ? obj : Object.keys(obj).length > 0 ? obj : undefined;
|
||||
}
|
||||
case "null":
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue