Skip to content

Commit 9b5d0fe

Browse files
Copilotstephentoub
andauthored
Make Tool.Name required to match other protocol types (#1351)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent fa56de9 commit 9b5d0fe

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

  • src/ModelContextProtocol.Core/Protocol
  • tests/ModelContextProtocol.Tests/Protocol

src/ModelContextProtocol.Core/Protocol/Tool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class Tool : IBaseMetadata
1515
{
1616
/// <inheritdoc />
1717
[JsonPropertyName("name")]
18-
public string Name { get; set; } = string.Empty;
18+
public required string Name { get; set; }
1919

2020
/// <inheritdoc />
2121
[JsonPropertyName("title")]

tests/ModelContextProtocol.Tests/Protocol/ToolTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void Tool_HasCorrectJsonPropertyNames()
9595
[Fact]
9696
public static void ToolInputSchema_HasValidDefaultSchema()
9797
{
98-
var tool = new Tool();
98+
var tool = new Tool { Name = "test" };
9999
JsonElement jsonElement = tool.InputSchema;
100100

101101
Assert.Equal(JsonValueKind.Object, jsonElement.ValueKind);
@@ -119,7 +119,7 @@ public static void ToolInputSchema_HasValidDefaultSchema()
119119
public static void ToolInputSchema_RejectsInvalidSchemaDocuments(string invalidSchema)
120120
{
121121
using var document = JsonDocument.Parse(invalidSchema);
122-
var tool = new Tool();
122+
var tool = new Tool { Name = "test" };
123123

124124
Assert.Throws<ArgumentException>(() => tool.InputSchema = document.RootElement);
125125
}
@@ -133,6 +133,7 @@ public static void ToolInputSchema_AcceptsValidSchemaDocuments(string validSchem
133133
using var document = JsonDocument.Parse(validSchema);
134134
Tool tool = new()
135135
{
136+
Name = "test",
136137
InputSchema = document.RootElement
137138
};
138139

0 commit comments

Comments
 (0)