Skip to content

Commit 98ad948

Browse files
zaevieiriktsarpalis
authored andcommitted
Fix enum serialization
1 parent 1a5732b commit 98ad948

File tree

3 files changed

+11
-27
lines changed

3 files changed

+11
-27
lines changed

src/ModelContextProtocol/Client/McpClientExtensions.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public static Task SetLoggingLevel(this IMcpClient client, LoggingLevel level, C
485485
Throw.IfNull(client);
486486

487487
return client.SendRequestAsync<EmptyResult>(
488-
CreateRequest("logging/setLevel", new() { ["level"] = level.ToJsonValue() }),
488+
CreateRequest("logging/setLevel", new() { ["level"] = level }),
489489
cancellationToken);
490490
}
491491

@@ -514,22 +514,6 @@ private static JsonRpcRequest CreateRequest(string method, Dictionary<string, ob
514514
return parameters;
515515
}
516516

517-
private static string ToJsonValue(this LoggingLevel level)
518-
{
519-
return level switch
520-
{
521-
LoggingLevel.Debug => "debug",
522-
LoggingLevel.Info => "info",
523-
LoggingLevel.Notice => "notice",
524-
LoggingLevel.Warning => "warning",
525-
LoggingLevel.Error => "error",
526-
LoggingLevel.Critical => "critical",
527-
LoggingLevel.Alert => "alert",
528-
LoggingLevel.Emergency => "emergency",
529-
_ => throw new ArgumentOutOfRangeException(nameof(level))
530-
};
531-
}
532-
533517
/// <summary>Provides an AI function that calls a tool through <see cref="IMcpClient"/>.</summary>
534518
private sealed class McpAIFunction(IMcpClient client, Tool tool) : AIFunction
535519
{

src/ModelContextProtocol/Protocol/Types/LoggingLevel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ namespace ModelContextProtocol.Protocol.Types;
1010
public enum LoggingLevel
1111
{
1212
/// <summary>Detailed debug information, typically only valuable to developers.</summary>
13-
[JsonPropertyName("debug")]
13+
[JsonStringEnumMemberName("debug")]
1414
Debug,
1515

1616
/// <summary>Normal operational messages that require no action.</summary>
17-
[JsonPropertyName("info")]
17+
[JsonStringEnumMemberName("info")]
1818
Info,
1919

2020
/// <summary>Normal but significant events that might deserve attention.</summary>
21-
[JsonPropertyName("notice")]
21+
[JsonStringEnumMemberName("notice")]
2222
Notice,
2323

2424
/// <summary>Warning conditions that don't represent an error but indicate potential issues.</summary>
25-
[JsonPropertyName("warning")]
25+
[JsonStringEnumMemberName("warning")]
2626
Warning,
2727

2828
/// <summary>Error conditions that should be addressed but don't require immediate action.</summary>
29-
[JsonPropertyName("error")]
29+
[JsonStringEnumMemberName("error")]
3030
Error,
3131

3232
/// <summary>Critical conditions that require immediate attention.</summary>
33-
[JsonPropertyName("critical")]
33+
[JsonStringEnumMemberName("critical")]
3434
Critical,
3535

3636
/// <summary>Action must be taken immediately to address the condition.</summary>
37-
[JsonPropertyName("alert")]
37+
[JsonStringEnumMemberName("alert")]
3838
Alert,
3939

4040
/// <summary>System is unusable and requires immediate attention.</summary>
41-
[JsonPropertyName("emergency")]
41+
[JsonStringEnumMemberName("emergency")]
4242
Emergency
4343
}

src/ModelContextProtocol/Protocol/Types/Role.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public enum Role
1111
/// <summary>
1212
/// Corresponds to the user in the conversation.
1313
/// </summary>
14-
[JsonPropertyName("user")]
14+
[JsonStringEnumMemberName("user")]
1515
User,
1616

1717
/// <summary>
1818
/// Corresponds to the AI in the conversation.
1919
/// </summary>
20-
[JsonPropertyName("assistant")]
20+
[JsonStringEnumMemberName("assistant")]
2121
Assistant
2222
}

0 commit comments

Comments
 (0)