Skip to content

Commit eb94e61

Browse files
committed
Address feedback
1 parent 81a54ec commit eb94e61

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

Diff for: src/ModelContextProtocol/Server/AIFunctionMcpServerTool.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,24 @@ options.OpenWorld is not null ||
185185
newOptions.Name ??= attr.Name;
186186
newOptions.Title ??= attr.Title;
187187

188-
if (attr.DestructiveIsSet)
188+
if (attr._destructive is bool destructive)
189189
{
190-
newOptions.Destructive ??= attr.Destructive;
190+
newOptions.Destructive ??= destructive;
191191
}
192192

193-
if (attr.IdempotentIsSet)
193+
if (attr._idempotent is bool idempotent)
194194
{
195-
newOptions.Idempotent ??= attr.Idempotent;
195+
newOptions.Idempotent ??= idempotent;
196196
}
197197

198-
if (attr.OpenWorldIsSet)
198+
if (attr._openWorld is bool openWorld)
199199
{
200-
newOptions.OpenWorld ??= attr.OpenWorld;
200+
newOptions.OpenWorld ??= openWorld;
201201
}
202202

203-
if (attr.ReadOnlyIsSet)
203+
if (attr._readOnly is bool readOnly)
204204
{
205-
newOptions.ReadOnly ??= attr.ReadOnly;
205+
newOptions.ReadOnly ??= readOnly;
206206
}
207207
}
208208

Diff for: src/ModelContextProtocol/Server/McpServerToolAttribute.cs

+31-28
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
[AttributeUsage(AttributeTargets.Method)]
77
public sealed class McpServerToolAttribute : Attribute
88
{
9-
private bool? _destructive;
10-
private bool? _idempotent;
11-
private bool? _openWorld;
12-
private bool? _readOnly;
9+
// Defaults based on the spec
10+
private const bool DestructiveDefault = true;
11+
private const bool IdempotentDefault = false;
12+
private const bool OpenWorldDefault = true;
13+
private const bool ReadOnlyDefault = false;
14+
15+
// Nullable backing fields so we can distinguish
16+
internal bool? _destructive;
17+
internal bool? _idempotent;
18+
internal bool? _openWorld;
19+
internal bool? _readOnly;
1320

1421
/// <summary>
1522
/// Initializes a new instance of the <see cref="McpServerToolTypeAttribute"/> class.
@@ -30,41 +37,37 @@ public McpServerToolAttribute()
3037
/// <summary>
3138
/// Gets or sets whether the tool may perform destructive updates to its environment.
3239
/// </summary>
33-
public bool Destructive { get => _destructive ?? true; set => _destructive = value; }
34-
35-
/// <summary>
36-
/// Gets whether the <see cref="Destructive"/> property has been assigned a value.
37-
/// </summary>
38-
public bool DestructiveIsSet => _destructive.HasValue;
40+
public bool Destructive
41+
{
42+
get => _destructive ?? DestructiveDefault;
43+
set => _destructive = value;
44+
}
3945

4046
/// <summary>
4147
/// Gets or sets whether calling the tool repeatedly with the same arguments will have no additional effect on its environment.
4248
/// </summary>
43-
public bool Idempotent { get => _idempotent ?? false; set => _idempotent = value; }
44-
45-
/// <summary>
46-
/// Gets whether the <see cref="Idempotent"/> property has been assigned a value.
47-
/// </summary>
48-
public bool IdempotentIsSet => _idempotent.HasValue;
49+
public bool Idempotent
50+
{
51+
get => _idempotent ?? IdempotentDefault;
52+
set => _idempotent = value;
53+
}
4954

5055
/// <summary>
5156
/// Gets or sets whether this tool may interact with an "open world" of external entities
5257
/// (e.g. the world of a web search tool is open, whereas that of a memory tool is not).
5358
/// </summary>
54-
public bool OpenWorld { get => _openWorld ?? true; set => _openWorld = value; }
55-
56-
/// <summary>
57-
/// Gets whether the <see cref="OpenWorld"/> property has been assigned a value.
58-
/// </summary>
59-
public bool OpenWorldIsSet => _openWorld.HasValue;
59+
public bool OpenWorld
60+
{
61+
get => _openWorld ?? OpenWorldDefault;
62+
set => _openWorld = value;
63+
}
6064

6165
/// <summary>
6266
/// Gets or sets whether the tool does not modify its environment.
6367
/// </summary>
64-
public bool ReadOnly { get => _readOnly ?? false; set => _readOnly = value; }
65-
66-
/// <summary>
67-
/// Gets whether the <see cref="ReadOnly"/> property has been assigned a value.
68-
/// </summary>
69-
public bool ReadOnlyIsSet => _readOnly.HasValue;
68+
public bool ReadOnly
69+
{
70+
get => _readOnly ?? ReadOnlyDefault;
71+
set => _readOnly = value;
72+
}
7073
}

0 commit comments

Comments
 (0)