Skip to content

Commit 2cf72e1

Browse files
Copilotstephentoub
andcommitted
Address PR feedback: improve DebuggerDisplay implementations
- Show MimeType and byte length instead of base64 data for binary content - Use string literals in DebuggerDisplay attribute where possible - Make ToolResultContentBlock display more dynamic (show result or error) - Show actual text content in PromptMessage when available Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent e41dece commit 2cf72e1

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed

src/ModelContextProtocol.Core/Protocol/BlobResourceContents.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ private string DebuggerDisplay
3535
{
3636
get
3737
{
38-
const int MaxLength = 80;
39-
string blobPreview = Blob.Length <= MaxLength ? Blob : $"{Blob.Substring(0, MaxLength)}...";
40-
return $"Uri = {Uri}, Blob = {blobPreview}";
38+
// Decode base64 to get actual byte length
39+
int byteLength = Blob.Length * 3 / 4;
40+
string mimeInfo = MimeType is not null ? $", MimeType = {MimeType}" : "";
41+
return $"Uri = {Uri}{mimeInfo}, Length = {byteLength} bytes";
4142
}
4243
}
4344
}

src/ModelContextProtocol.Core/Protocol/ContentBlock.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ private string DebuggerDisplay
402402
{
403403
get
404404
{
405-
const int MaxLength = 80;
406-
string dataPreview = Data.Length <= MaxLength ? Data : $"{Data.Substring(0, MaxLength)}...";
407-
return $"MimeType = {MimeType}, Data = {dataPreview}";
405+
// Decode base64 to get actual byte length
406+
int byteLength = Data.Length * 3 / 4;
407+
return $"MimeType = {MimeType}, Length = {byteLength} bytes";
408408
}
409409
}
410410
}
@@ -436,9 +436,9 @@ private string DebuggerDisplay
436436
{
437437
get
438438
{
439-
const int MaxLength = 80;
440-
string dataPreview = Data.Length <= MaxLength ? Data : $"{Data.Substring(0, MaxLength)}...";
441-
return $"MimeType = {MimeType}, Data = {dataPreview}";
439+
// Decode base64 to get actual byte length
440+
int byteLength = Data.Length * 3 / 4;
441+
return $"MimeType = {MimeType}, Length = {byteLength} bytes";
442442
}
443443
}
444444
}
@@ -542,7 +542,7 @@ public sealed class ResourceLinkBlock : ContentBlock
542542
}
543543

544544
/// <summary>Represents a request from the assistant to call a tool.</summary>
545-
[DebuggerDisplay("{DebuggerDisplay,nq}")]
545+
[DebuggerDisplay("Name = {Name}, Id = {Id}")]
546546
public sealed class ToolUseContentBlock : ContentBlock
547547
{
548548
/// <inheritdoc/>
@@ -568,9 +568,6 @@ public sealed class ToolUseContentBlock : ContentBlock
568568
/// </summary>
569569
[JsonPropertyName("input")]
570570
public required JsonElement Input { get; set; }
571-
572-
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
573-
private string DebuggerDisplay => $"Name = {Name}, Id = {Id}";
574571
}
575572

576573
/// <summary>Represents the result of a tool use, provided by the user back to the assistant.</summary>
@@ -621,5 +618,35 @@ public sealed class ToolResultContentBlock : ContentBlock
621618
public bool? IsError { get; set; }
622619

623620
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
624-
private string DebuggerDisplay => $"ToolUseId = {ToolUseId}, ContentCount = {Content.Count}, IsError = {IsError ?? false}";
621+
private string DebuggerDisplay
622+
{
623+
get
624+
{
625+
if (IsError == true)
626+
{
627+
return $"ToolUseId = {ToolUseId}, IsError = true";
628+
}
629+
630+
// Try to show the result content
631+
if (Content.Count == 1 && Content[0] is TextContentBlock textBlock)
632+
{
633+
return $"ToolUseId = {ToolUseId}, Result = \"{textBlock.Text}\"";
634+
}
635+
636+
if (StructuredContent.HasValue)
637+
{
638+
try
639+
{
640+
string json = StructuredContent.Value.GetRawText();
641+
return $"ToolUseId = {ToolUseId}, Result = {json}";
642+
}
643+
catch
644+
{
645+
// Fall back to content count if GetRawText fails
646+
}
647+
}
648+
649+
return $"ToolUseId = {ToolUseId}, ContentCount = {Content.Count}";
650+
}
651+
}
625652
}

src/ModelContextProtocol.Core/Protocol/PromptMessage.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,17 @@ public sealed class PromptMessage
5353
public required Role Role { get; set; }
5454

5555
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
56-
private string DebuggerDisplay => $"Role = {Role}, ContentType = {Content.Type}";
56+
private string DebuggerDisplay
57+
{
58+
get
59+
{
60+
// Show actual text content if it's a TextContentBlock
61+
if (Content is TextContentBlock textBlock)
62+
{
63+
return $"Role = {Role}, Text = \"{textBlock.Text}\"";
64+
}
65+
66+
return $"Role = {Role}, ContentType = {Content.Type}";
67+
}
68+
}
5769
}

src/ModelContextProtocol.Core/Protocol/Resource.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ModelContextProtocol.Protocol;
1212
/// <remarks>
1313
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
1414
/// </remarks>
15-
[DebuggerDisplay("{DebuggerDisplay,nq}")]
15+
[DebuggerDisplay("Name = {Name}, Uri = {Uri}")]
1616
public sealed class Resource : IBaseMetadata
1717
{
1818
/// <inheritdoc />
@@ -107,7 +107,4 @@ public sealed class Resource : IBaseMetadata
107107
/// </summary>
108108
[JsonIgnore]
109109
public McpServerResource? McpServerResource { get; set; }
110-
111-
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
112-
private string DebuggerDisplay => $"Name = {Name}, Uri = {Uri}";
113110
}

src/ModelContextProtocol.Core/Protocol/TextResourceContents.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ModelContextProtocol.Protocol;
2020
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for more details.
2121
/// </para>
2222
/// </remarks>
23-
[DebuggerDisplay("{DebuggerDisplay,nq}")]
23+
[DebuggerDisplay("Uri = {Uri}, Text = \\\"{Text}\\\"")]
2424
public sealed class TextResourceContents : ResourceContents
2525
{
2626
/// <summary>
@@ -31,7 +31,4 @@ public sealed class TextResourceContents : ResourceContents
3131

3232
/// <inheritdoc/>
3333
public override string ToString() => Text;
34-
35-
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
36-
private string DebuggerDisplay => $"Uri = {Uri}, Text = \"{Text}\"";
3734
}

0 commit comments

Comments
 (0)