-
Notifications
You must be signed in to change notification settings - Fork 441
Description
Bug Description
I'm doing simple SDK example in order to learn how to use it for my application. One think that I need and I've not seen in any examples is about optional parameters in a function. I tried to simulate it with string? date
[McpServerTool, Description("Gets the weather")]
public string GetWeather([Description("City code")] string cityCode, [Description("Date in yyyy-mm-dd format")] string? date = null)
{
but when using from MCP Client both parameters appears like required in the function definition.
I've been debugging and investigating a possible solution and the reason seems to be due to default JsonSchemaCreateOptions.RequireAllProperties that is true so regardless of the parameter is or not optional it's always required.
I was able to make it works adding a JsonSchemaCreateOptions in CreateAIFunctionFactoryOptions in AIFunctionMcpServerTool.cs but I'm not familiar with the source code and could be an invalid workaround with side effects (although it works perfectly for me)
private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
MethodInfo method, McpServerToolCreateOptions? options) =>
new()
{
Name = options?.Name ?? method.GetCustomAttribute<McpServerToolAttribute>()?.Name,
Description = options?.Description,
MarshalResult = static (result, _, cancellationToken) => new ValueTask<object?>(result),
SerializerOptions = options?.SerializerOptions ?? McpJsonUtilities.DefaultOptions,
**JsonSchemaCreateOptions=new AIJsonSchemaCreateOptions()
{
RequireAllProperties=false
}**,
.......