csharp-sdk/samples/EverythingServer/ResourceGenerator.cs
Tyler Kendrick 03e3094dcc
Fix and enhance cancellation operations across MCP Sessions. (#179)
* Propagate CancellationToken request cancellation to remote endpoint

* Refactor existing tests to have a shared base class

* Add cancellation tests

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-08 16:12:12 -04:00

34 lines
No EOL
1.1 KiB
C#

using ModelContextProtocol.Protocol.Types;
namespace EverythingServer;
static class ResourceGenerator
{
private static readonly List<Resource> _resources = Enumerable.Range(1, 100).Select(i =>
{
var uri = $"test://static/resource/{i}";
if (i % 2 != 0)
{
return new Resource
{
Uri = uri,
Name = $"Resource {i}",
MimeType = "text/plain",
Description = $"Resource {i}: This is a plaintext resource"
};
}
else
{
var buffer = System.Text.Encoding.UTF8.GetBytes($"Resource {i}: This is a base64 blob");
return new Resource
{
Uri = uri,
Name = $"Resource {i}",
MimeType = "application/octet-stream",
Description = Convert.ToBase64String(buffer)
};
}
}).ToList();
public static IReadOnlyList<Resource> Resources => _resources;
}