Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,10 @@ private static McpServerToolCreateOptions DeriveOptions(MethodInfo method, McpSe
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;
}
newOptions.Destructive ??= toolAttr.Destructive;
newOptions.Idempotent ??= toolAttr.Idempotent;
newOptions.OpenWorld ??= toolAttr.OpenWorld;
newOptions.ReadOnly ??= toolAttr.ReadOnly;

if (newOptions.Icons is null && toolAttr.IconSource is { Length: > 0 } iconSource)
{
Expand Down Expand Up @@ -805,4 +790,4 @@ private static bool IsPrimitiveHeaderType(Type type)
type == typeof(uint) ||
type == typeof(long);
}
}
}
6 changes: 3 additions & 3 deletions tests/ModelContextProtocol.Tests/Client/McpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ public async Task ListToolsAsync_AllToolsReturned()

var valuesSetViaAttr = tools.Single(t => t.Name == "ValuesSetViaAttr");
Assert.Null(valuesSetViaAttr.ProtocolTool.Annotations?.Title);
Assert.Null(valuesSetViaAttr.ProtocolTool.Annotations?.ReadOnlyHint);
Assert.Null(valuesSetViaAttr.ProtocolTool.Annotations?.IdempotentHint);
Assert.False(valuesSetViaAttr.ProtocolTool.Annotations?.ReadOnlyHint);
Assert.False(valuesSetViaAttr.ProtocolTool.Annotations?.IdempotentHint);
Assert.False(valuesSetViaAttr.ProtocolTool.Annotations?.DestructiveHint);
Assert.True(valuesSetViaAttr.ProtocolTool.Annotations?.OpenWorldHint);

var valuesSetViaOptions = tools.Single(t => t.Name == "ValuesSetViaOptions");
Assert.Null(valuesSetViaOptions.ProtocolTool.Annotations?.Title);
Assert.True(valuesSetViaOptions.ProtocolTool.Annotations?.ReadOnlyHint);
Assert.Null(valuesSetViaOptions.ProtocolTool.Annotations?.IdempotentHint);
Assert.False(valuesSetViaOptions.ProtocolTool.Annotations?.IdempotentHint);
Assert.True(valuesSetViaOptions.ProtocolTool.Annotations?.DestructiveHint);
Assert.False(valuesSetViaOptions.ProtocolTool.Annotations?.OpenWorldHint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,10 @@ public void Create_ExtractsToolAnnotations_SomeSet()
var annotations = tool.ProtocolTool.Annotations;
Assert.NotNull(annotations);
Assert.Null(annotations.Title);
Assert.Null(annotations.DestructiveHint);
Assert.True(annotations.DestructiveHint);
Assert.False(annotations.IdempotentHint);
Assert.Null(annotations.OpenWorldHint);
Assert.Null(annotations.ReadOnlyHint);
Assert.True(annotations.OpenWorldHint);
Assert.False(annotations.ReadOnlyHint);
}

[Fact]
Expand Down Expand Up @@ -970,4 +970,4 @@ public class ComplexObject
[JsonSerializable(typeof(JsonElement))]
[JsonSerializable(typeof(CallToolResult))]
partial class BuilderToolsJsonContext : JsonSerializerContext;
}
}