From 84070ad342625bfcd6380b6393be0967730f328c Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Sat, 26 Apr 2025 10:46:59 -0500 Subject: [PATCH 1/4] Add static resources --- samples/EverythingServer/Program.cs | 29 +++++++++++++++++-- samples/EverythingServer/ResourceGenerator.cs | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/samples/EverythingServer/Program.cs b/samples/EverythingServer/Program.cs index 59d9b845..943b91a5 100644 --- a/samples/EverythingServer/Program.cs +++ b/samples/EverythingServer/Program.cs @@ -38,13 +38,23 @@ .WithTools() .WithPrompts() .WithPrompts() + .WithListResourcesHandler(async (ctx, ct) => + { + return new ListResourcesResult + { + Resources = + [ + new ModelContextProtocol.Protocol.Types.Resource { Name = "Static Resource", Description = "A static resource", Uri = "test://static/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}" } ] }; }) @@ -52,12 +62,25 @@ { var uri = ctx.Params?.Uri; - if (uri is null || !uri.StartsWith("test://static/resource/")) + if (uri?.StartsWith("test://static/resource/") == true) + { + return new ReadResourceResult + { + Contents = [new TextResourceContents + { + Text = "This is a static 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) { diff --git a/samples/EverythingServer/ResourceGenerator.cs b/samples/EverythingServer/ResourceGenerator.cs index 3ae4c17f..7e812625 100644 --- a/samples/EverythingServer/ResourceGenerator.cs +++ b/samples/EverythingServer/ResourceGenerator.cs @@ -6,7 +6,7 @@ static class ResourceGenerator { private static readonly List _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 From 9eb98565d541f6150aafc22d10f7627698c2b215 Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Mon, 28 Apr 2025 15:23:37 -0500 Subject: [PATCH 2/4] Apply suggestions from PR review Co-authored-by: Stephen Halter --- samples/EverythingServer/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/EverythingServer/Program.cs b/samples/EverythingServer/Program.cs index 943b91a5..fab6072a 100644 --- a/samples/EverythingServer/Program.cs +++ b/samples/EverythingServer/Program.cs @@ -44,7 +44,7 @@ { Resources = [ - new ModelContextProtocol.Protocol.Types.Resource { Name = "Static Resource", Description = "A static resource", Uri = "test://static/resource/" } + new ModelContextProtocol.Protocol.Types.Resource { Name = "Static Text Resource", Description = "A static text resource", MimeType = "text/plain", Uri = "test://direct/text/resource" }, ] }; }) From 96129507cb821cce3969cd8b416590199315201c Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Mon, 28 Apr 2025 15:27:40 -0500 Subject: [PATCH 3/4] Apply suggestions from PR review Co-authored-by: Stephen Halter --- samples/EverythingServer/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/EverythingServer/Program.cs b/samples/EverythingServer/Program.cs index fab6072a..ecb0181a 100644 --- a/samples/EverythingServer/Program.cs +++ b/samples/EverythingServer/Program.cs @@ -62,7 +62,7 @@ { var uri = ctx.Params?.Uri; - if (uri?.StartsWith("test://static/resource/") == true) + if (uri == "test://direct/text/resource") { return new ReadResourceResult { From bc4a52566d1cc97c1220980c308500bbb91b1c17 Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Mon, 28 Apr 2025 15:30:59 -0500 Subject: [PATCH 4/4] Update name and description of direct resource --- samples/EverythingServer/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/EverythingServer/Program.cs b/samples/EverythingServer/Program.cs index ecb0181a..92a5211f 100644 --- a/samples/EverythingServer/Program.cs +++ b/samples/EverythingServer/Program.cs @@ -44,7 +44,7 @@ { Resources = [ - new ModelContextProtocol.Protocol.Types.Resource { Name = "Static Text Resource", Description = "A static text resource", MimeType = "text/plain", Uri = "test://direct/text/resource" }, + new ModelContextProtocol.Protocol.Types.Resource { Name = "Direct Text Resource", Description = "A direct text resource", MimeType = "text/plain", Uri = "test://direct/text/resource" }, ] }; }) @@ -68,7 +68,7 @@ { Contents = [new TextResourceContents { - Text = "This is a static resource", + Text = "This is a direct resource", MimeType = "text/plain", Uri = uri, }]