You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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")]publicstringGetWeather([Description("City code")]stringcityCode,[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)
We recently merged this PR in Microsoft.Extensions.AI that among other things changes the default value of RequireAllProperties to false. The issue should resolve itself once the MCP sdk references an updated version of MEAI.
Activity
1357310795 commentedon Apr 26, 2025
See #354
you can use
McpServerTool.Createto pass AIJsonSchemaCreateOptions now.although this cannot yet be achieved using the most commonly used
WithToolmy workaround is duplicating
WithTool/WithToolsFromAssemblyinto project and apply some minor adjustmentshttps://github.com/SJTU-Geek/sjtu-mcp-server/blob/a9d8b6ef3f0ff3ea8af229976f0f0b983694bc34/SJTUGeek.MCP.Server/Extensions/McpScriptBuilderExtensions.cs#L55
jason-lee-x commentedon Apr 28, 2025
That was really helpful!
Thanks a lot.
Hoping the
WithToolsFromCurrentAssemblycan be parts of SDK.stephentoub commentedon Apr 28, 2025
cc: @eiriktsarpalis
1357310795 commentedon Apr 28, 2025
Passing AIJsonSchemaCreateOptions into
WithTool/WithToolsFromAssemblymaybe need a more flexible way.Perhaps there are more parameters that need to be passed in the future
eiriktsarpalis commentedon Apr 28, 2025
We recently merged this PR in Microsoft.Extensions.AI that among other things changes the default value of
RequireAllPropertiesto false. The issue should resolve itself once the MCP sdk references an updated version of MEAI.