Use WithResources in EverythingServer sample (#400)
This commit is contained in:
parent
d86b3277d4
commit
26c3622101
1 changed files with 41 additions and 78 deletions
39
samples/EverythingServer/Resources/SimpleResourceType.cs
Normal file
39
samples/EverythingServer/Resources/SimpleResourceType.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using ModelContextProtocol.Protocol.Types;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace EverythingServer.Resources;
|
||||
|
||||
[McpServerResourceType]
|
||||
public class SimpleResourceType
|
||||
{
|
||||
[McpServerResource(UriTemplate = "test://direct/text/resource", Name = "Direct Text Resource", MimeType = "text/plain")]
|
||||
[Description("A direct text resource")]
|
||||
public static string DirectTextResource() => "This is a direct resource";
|
||||
|
||||
[McpServerResource(UriTemplate = "test://template/resource/{id}", Name = "Template Resource")]
|
||||
[Description("A template resource with a numeric ID")]
|
||||
public static ResourceContents TemplateResource(RequestContext<ReadResourceRequestParams> requestContext, int id)
|
||||
{
|
||||
int index = id - 1;
|
||||
if ((uint)index >= ResourceGenerator.Resources.Count)
|
||||
{
|
||||
throw new NotSupportedException($"Unknown resource: {requestContext.Params?.Uri}");
|
||||
}
|
||||
|
||||
var resource = ResourceGenerator.Resources[index];
|
||||
return resource.MimeType == "text/plain" ?
|
||||
new TextResourceContents
|
||||
{
|
||||
Text = resource.Description!,
|
||||
MimeType = resource.MimeType,
|
||||
Uri = resource.Uri,
|
||||
} :
|
||||
new BlobResourceContents
|
||||
{
|
||||
Blob = resource.Description!,
|
||||
MimeType = resource.MimeType,
|
||||
Uri = resource.Uri,
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue