Skip to content

Commit 64f2c58

Browse files
Copilotstephentoub
andcommitted
Address code review feedback
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 12d5683 commit 64f2c58

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,11 @@ private static TimeSpan GetElapsed(long startingTimestamp) =>
771771

772772
/// <summary>
773773
/// Converts the Exception.Data dictionary to a serializable Dictionary&lt;string, object?&gt;.
774-
/// Returns null if the data dictionary is empty.
774+
/// Returns null if the data dictionary is empty or contains no string keys.
775775
/// </summary>
776+
/// <remarks>
777+
/// Only entries with string keys are included in the result. Entries with non-string keys are ignored.
778+
/// </remarks>
776779
private static Dictionary<string, object?>? ConvertExceptionData(System.Collections.IDictionary data)
777780
{
778781
if (data.Count == 0)

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,9 @@ await transport.SendMessageAsync(
721721
Assert.NotNull(error.Error.Data);
722722

723723
// Verify the data contains the uri
724-
var dataJson = JsonSerializer.Serialize(error.Error.Data, McpJsonUtilities.DefaultOptions);
725-
var dataObject = JsonSerializer.Deserialize<JsonObject>(dataJson, McpJsonUtilities.DefaultOptions);
726-
Assert.NotNull(dataObject);
727-
Assert.True(dataObject.ContainsKey("uri"));
728-
Assert.Equal(resourceUri, dataObject["uri"]?.GetValue<string>());
724+
var dataDict = Assert.IsType<Dictionary<string, object?>>(error.Error.Data);
725+
Assert.True(dataDict.ContainsKey("uri"));
726+
Assert.Equal(resourceUri, dataDict["uri"]);
729727

730728
await transport.DisposeAsync();
731729
await runTask;

0 commit comments

Comments
 (0)