66[ AttributeUsage ( AttributeTargets . Method ) ]
77public 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