6
6
[ AttributeUsage ( AttributeTargets . Method ) ]
7
7
public sealed class McpServerToolAttribute : Attribute
8
8
{
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 ;
13
20
14
21
/// <summary>
15
22
/// Initializes a new instance of the <see cref="McpServerToolTypeAttribute"/> class.
@@ -30,41 +37,37 @@ public McpServerToolAttribute()
30
37
/// <summary>
31
38
/// Gets or sets whether the tool may perform destructive updates to its environment.
32
39
/// </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
+ }
39
45
40
46
/// <summary>
41
47
/// Gets or sets whether calling the tool repeatedly with the same arguments will have no additional effect on its environment.
42
48
/// </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
+ }
49
54
50
55
/// <summary>
51
56
/// Gets or sets whether this tool may interact with an "open world" of external entities
52
57
/// (e.g. the world of a web search tool is open, whereas that of a memory tool is not).
53
58
/// </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
+ }
60
64
61
65
/// <summary>
62
66
/// Gets or sets whether the tool does not modify its environment.
63
67
/// </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
+ }
70
73
}
0 commit comments