Skip to content

Commit c2b7afe

Browse files
committed
Address feedback
1 parent f944439 commit c2b7afe

5 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/ModelContextProtocol/Protocol/Messages/ProgressToken.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,45 @@ namespace ModelContextProtocol.Protocol.Messages;
1212
[JsonConverter(typeof(Converter))]
1313
public readonly struct ProgressToken : IEquatable<ProgressToken>
1414
{
15-
/// <summary>The id, either a string or a boxed long or null.</summary>
16-
private readonly object? _id;
15+
/// <summary>The token, either a string or a boxed long or null.</summary>
16+
private readonly object? _token;
1717

1818
/// <summary>Initializes a new instance of the <see cref="ProgressToken"/> with a specified value.</summary>
1919
/// <param name="value">The required ID value.</param>
2020
public ProgressToken(string value)
2121
{
2222
Throw.IfNull(value);
23-
_id = value;
23+
_token = value;
2424
}
2525

2626
/// <summary>Initializes a new instance of the <see cref="ProgressToken"/> with a specified value.</summary>
2727
/// <param name="value">The required ID value.</param>
2828
public ProgressToken(long value)
2929
{
3030
// Box the long. Progress tokens are almost always strings in practice, so this should be rare.
31-
_id = value;
31+
_token = value;
3232
}
3333

34-
/// <summary>Gets whether the identifier is uninitialized.</summary>
35-
public bool IsDefault => _id is null;
34+
/// <summary>Gets the underlying object for this token.</summary>
35+
/// <remarks>This will either be a <see cref="string"/>, a boxed <see cref="long"/>, or <see langword="null"/>.</remarks>
36+
public object? Token => _token;
3637

3738
/// <inheritdoc />
3839
public override string? ToString() =>
39-
_id is string stringValue ? $"\"{stringValue}\"" :
40-
_id is long longValue ? longValue.ToString(CultureInfo.InvariantCulture) :
40+
_token is string stringValue ? $"{stringValue}" :
41+
_token is long longValue ? longValue.ToString(CultureInfo.InvariantCulture) :
4142
null;
4243

4344
/// <summary>
4445
/// Compares this ProgressToken to another ProgressToken.
4546
/// </summary>
46-
public bool Equals(ProgressToken other) => Equals(_id, other._id);
47+
public bool Equals(ProgressToken other) => Equals(_token, other._token);
4748

4849
/// <inheritdoc />
4950
public override bool Equals(object? obj) => obj is ProgressToken other && Equals(other);
5051

5152
/// <inheritdoc />
52-
public override int GetHashCode() => _id?.GetHashCode() ?? 0;
53+
public override int GetHashCode() => _token?.GetHashCode() ?? 0;
5354

5455
/// <summary>
5556
/// Compares two ProgressTokens for equality.
@@ -83,7 +84,7 @@ public override void Write(Utf8JsonWriter writer, ProgressToken value, JsonSeria
8384
{
8485
Throw.IfNull(writer);
8586

86-
switch (value._id)
87+
switch (value._token)
8788
{
8889
case string str:
8990
writer.WriteStringValue(str);

src/ModelContextProtocol/Protocol/Messages/RequestId.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ public RequestId(long value)
3131
_id = value;
3232
}
3333

34-
/// <summary>Gets whether the identifier is uninitialized.</summary>
35-
public bool IsDefault => _id is null;
36-
3734
/// <summary>Gets the underlying object for this id.</summary>
3835
/// <remarks>This will either be a <see cref="string"/>, a boxed <see cref="long"/>, or <see langword="null"/>.</remarks>
3936
public object? Id => _id;

src/ModelContextProtocol/Shared/McpSession.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private async Task HandleNotification(JsonRpcNotification notification)
271271

272272
private void HandleMessageWithId(IJsonRpcMessage message, IJsonRpcMessageWithId messageWithId)
273273
{
274-
if (messageWithId.Id.IsDefault)
274+
if (messageWithId.Id.Id is null)
275275
{
276276
_logger.RequestHasInvalidId(EndpointName);
277277
}
@@ -331,7 +331,7 @@ public async Task<TResult> SendRequestAsync<TResult>(JsonRpcRequest request, Can
331331
null;
332332

333333
// Set request ID
334-
if (request.Id.IsDefault)
334+
if (request.Id.Id is null)
335335
{
336336
request.Id = new RequestId($"{_id}-{Interlocked.Increment(ref _nextRequestId)}");
337337
}
@@ -491,7 +491,7 @@ public async Task SendMessageAsync(IJsonRpcMessage message, CancellationToken ca
491491
private string CreateActivityName(string method) =>
492492
$"mcp.{(_isServer ? "server" : "client")}.{_transportKind}/{method}";
493493

494-
private string GetMethodName(IJsonRpcMessage message) =>
494+
private static string GetMethodName(IJsonRpcMessage message) =>
495495
message switch
496496
{
497497
JsonRpcRequest request => request.Method,
@@ -511,7 +511,7 @@ private void AddStandardTags(ref TagList tags, string method)
511511
// server.address, server.port, client.address, client.port, network.peer.address, network.peer.port, network.type
512512
}
513513

514-
private void AddRpcRequestTags(ref TagList tags, Activity? activity, JsonRpcRequest request)
514+
private static void AddRpcRequestTags(ref TagList tags, Activity? activity, JsonRpcRequest request)
515515
{
516516
tags.Add("rpc.jsonrpc.request_id", request.Id.ToString());
517517

@@ -547,7 +547,7 @@ private void AddRpcRequestTags(ref TagList tags, Activity? activity, JsonRpcRequ
547547
}
548548
}
549549

550-
private void AddExceptionTags(ref TagList tags, Exception e)
550+
private static void AddExceptionTags(ref TagList tags, Exception e)
551551
{
552552
tags.Add("error.type", e.GetType().FullName);
553553
tags.Add("rpc.jsonrpc.error_code",

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public async Task HandlesIProgressParameter()
640640
Assert.Equal(10, array.Length);
641641
for (int i = 0; i < array.Length; i++)
642642
{
643-
Assert.Equal("\"abc123\"", array[i].ProgressToken.ToString());
643+
Assert.Equal("abc123", array[i].ProgressToken.ToString());
644644
Assert.Equal(i, array[i].Progress.Progress);
645645
Assert.Equal(10, array[i].Progress.Total);
646646
Assert.Equal($"Progress {i}", array[i].Progress.Message);

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ await transport.SendMessageAsync(new JsonRpcNotification
684684

685685
var notification = await notificationReceived.Task;
686686
var progress = (ProgressNotification)notification.Params!;
687-
Assert.Equal("\"abc\"", progress.ProgressToken.ToString());
687+
Assert.Equal("abc", progress.ProgressToken.ToString());
688688
Assert.Equal(50, progress.Progress.Progress);
689689
Assert.Equal(100, progress.Progress.Total);
690690
Assert.Equal("Progress message", progress.Progress.Message);

0 commit comments

Comments
 (0)