I was taking a try at the tool annotations. According to the code XML comments, there are default values for them. I was expecting that those default annotations are attached. But it's not, so I took some investigation on source.
The code checks nullability on internal fields instead of public properties. The public properties getter will use the default values while internal fields won't. So the default values are not applied.
Is this intended? Seems a choice between null annotation vs default values annotation.
|
if (method.GetCustomAttribute<McpServerToolAttribute>() is { } toolAttr) |
|
{ |
|
newOptions.Name ??= toolAttr.Name; |
|
newOptions.Title ??= toolAttr.Title; |
|
|
|
if (toolAttr._destructive is bool destructive) |
|
{ |
|
newOptions.Destructive ??= destructive; |
|
} |
|
|
|
if (toolAttr._idempotent is bool idempotent) |
|
{ |
|
newOptions.Idempotent ??= idempotent; |
|
} |
|
|
|
if (toolAttr._openWorld is bool openWorld) |
|
{ |
|
newOptions.OpenWorld ??= openWorld; |
|
} |
|
|
|
if (toolAttr._readOnly is bool readOnly) |
|
{ |
|
newOptions.ReadOnly ??= readOnly; |
|
} |
I was taking a try at the tool annotations. According to the code XML comments, there are default values for them. I was expecting that those default annotations are attached. But it's not, so I took some investigation on source.
The code checks nullability on internal fields instead of public properties. The public properties getter will use the default values while internal fields won't. So the default values are not applied.
Is this intended? Seems a choice between
nullannotation vs default values annotation.csharp-sdk/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs
Lines 165 to 188 in d6b1615