Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions samples/EverythingServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,49 @@
.WithTools<TinyImageTool>()
.WithPrompts<ComplexPromptType>()
.WithPrompts<SimplePromptType>()
.WithListResourcesHandler(async (ctx, ct) =>
{
return new ListResourcesResult
{
Resources =
[
new ModelContextProtocol.Protocol.Types.Resource { Name = "Direct Text Resource", Description = "A direct text resource", MimeType = "text/plain", Uri = "test://direct/text/resource" },
]
};
})
.WithListResourceTemplatesHandler(async (ctx, ct) =>
{
return new ListResourceTemplatesResult
{
ResourceTemplates =
[
new ResourceTemplate { Name = "Static Resource", Description = "A static resource with a numeric ID", UriTemplate = "test://static/resource/{id}" }
new ResourceTemplate { Name = "Template Resource", Description = "A template resource with a numeric ID", UriTemplate = "test://template/resource/{id}" }
]
};
})
.WithReadResourceHandler(async (ctx, ct) =>
{
var uri = ctx.Params?.Uri;

if (uri is null || !uri.StartsWith("test://static/resource/"))
if (uri == "test://direct/text/resource")
{
return new ReadResourceResult
{
Contents = [new TextResourceContents
{
Text = "This is a direct resource",
MimeType = "text/plain",
Uri = uri,
}]
};
}

if (uri is null || !uri.StartsWith("test://template/resource/"))
{
throw new NotSupportedException($"Unknown resource: {uri}");
}

int index = int.Parse(uri["test://static/resource/".Length..]) - 1;
int index = int.Parse(uri["test://template/resource/".Length..]) - 1;

if (index < 0 || index >= ResourceGenerator.Resources.Count)
{
Expand Down
2 changes: 1 addition & 1 deletion samples/EverythingServer/ResourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static class ResourceGenerator
{
private static readonly List<Resource> _resources = Enumerable.Range(1, 100).Select(i =>
{
var uri = $"test://static/resource/{i}";
var uri = $"test://template/resource/{i}";
if (i % 2 != 0)
{
return new Resource
Expand Down