namespace ModelContextProtocol.Server;
///
/// Used to indicate that a method should be considered an MCP tool and describe it.
///
[AttributeUsage(AttributeTargets.Method)]
public sealed class McpServerToolAttribute : Attribute
{
// Defaults based on the spec
private const bool DestructiveDefault = true;
private const bool IdempotentDefault = false;
private const bool OpenWorldDefault = true;
private const bool ReadOnlyDefault = false;
// Nullable backing fields so we can distinguish
internal bool? _destructive;
internal bool? _idempotent;
internal bool? _openWorld;
internal bool? _readOnly;
///
/// Initializes a new instance of the class.
///
public McpServerToolAttribute()
{
}
/// Gets the name of the tool.
/// If , the method name will be used.
public string? Name { get; set; }
///
/// Gets or sets a human-readable title for the tool.
///
public string? Title { get; set; }
///
/// Gets or sets whether the tool may perform destructive updates to its environment.
///
public bool Destructive
{
get => _destructive ?? DestructiveDefault;
set => _destructive = value;
}
///
/// Gets or sets whether calling the tool repeatedly with the same arguments will have no additional effect on its environment.
///
public bool Idempotent
{
get => _idempotent ?? IdempotentDefault;
set => _idempotent = value;
}
///
/// Gets or sets whether this tool may interact with an "open world" of external entities
/// (e.g. the world of a web search tool is open, whereas that of a memory tool is not).
///
public bool OpenWorld
{
get => _openWorld ?? OpenWorldDefault;
set => _openWorld = value;
}
///
/// Gets or sets whether the tool does not modify its environment.
///
public bool ReadOnly
{
get => _readOnly ?? ReadOnlyDefault;
set => _readOnly = value;
}
}