-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathSimpleResourceType.cs
More file actions
40 lines (36 loc) · 1.6 KB
/
SimpleResourceType.cs
File metadata and controls
40 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Text;
namespace EverythingServer.Resources;
[McpServerResourceType]
public class SimpleResourceType
{
[McpServerResource(UriTemplate = "test://direct/text/resource", Name = "Direct Text Resource", MimeType = "text/plain", IconSource = "https://raw.githubusercontent.com/microsoft/fluentui-emoji/62ecdc0d7ca5c6df32148c169556bc8d3782fca4/assets/Memo/Flat/memo_flat.svg")]
[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 = Encoding.UTF8.GetBytes(resource.Description!),
MimeType = resource.MimeType,
Uri = resource.Uri,
};
}
}