Overhaul of Resources (#125)

* Supporting resource templates with read resource callback

Fixes #123

* Aligning the resource data structures with the 2024-11-05 schema

- Introducing separate classes for Text and Blob ResourceContents
- Custom JSON converter to allow those types to be returned, making it easier to follow the type system against the spec
- Updated tests

* Apply suggestions from code review

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Peder Holdgaard Pedersen <127606677+PederHP@users.noreply.github.com>

* Putting files back where they belong

* Adding an internal constructor to prevent overloads

* Addressing feedback

* Apply suggestions from code review

Co-authored-by: Stephen Toub <stoub@microsoft.com>

* Update src/ModelContextProtocol/Protocol/Types/ResourceContents.cs

* Addressing feedback

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Peder Holdgaard Pedersen <127606677+PederHP@users.noreply.github.com>
This commit is contained in:
Aaron Powell 2025-03-31 13:45:03 +11:00 • committed by GitHub
commit 3c0679e92b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,12 +16,16 @@ public record Resource
/// <summary>
/// A human-readable name for this resource.
///
/// This can be used by clients to populate UI elements.
/// </summary>
[JsonPropertyName("name")]
public required string Name { get; init; }
/// <summary>
/// A description of what this resource represents.
///
/// This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a \"hint\" to the model.
/// </summary>
[JsonPropertyName("description")]
public string? Description { get; init; }
@ -32,6 +36,14 @@ public record Resource
[JsonPropertyName("mimeType")]
public string? MimeType { get; init; }
/// <summary>
/// The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
///
/// This can be used by Hosts to display file sizes and estimate context window usage.
/// </summary>
[JsonPropertyName("size")]
public long? Size { get; init; }
/// <summary>
/// Optional annotations for the resource.
/// </summary>