|
38 | 38 | .WithTools<TinyImageTool>() |
39 | 39 | .WithPrompts<ComplexPromptType>() |
40 | 40 | .WithPrompts<SimplePromptType>() |
| 41 | + .WithListResourcesHandler(async (ctx, ct) => |
| 42 | + { |
| 43 | + return new ListResourcesResult |
| 44 | + { |
| 45 | + Resources = |
| 46 | + [ |
| 47 | + new ModelContextProtocol.Protocol.Types.Resource { Name = "Direct Text Resource", Description = "A direct text resource", MimeType = "text/plain", Uri = "test://direct/text/resource" }, |
| 48 | + ] |
| 49 | + }; |
| 50 | + }) |
41 | 51 | .WithListResourceTemplatesHandler(async (ctx, ct) => |
42 | 52 | { |
43 | 53 | return new ListResourceTemplatesResult |
44 | 54 | { |
45 | 55 | ResourceTemplates = |
46 | 56 | [ |
47 | | - new ResourceTemplate { Name = "Static Resource", Description = "A static resource with a numeric ID", UriTemplate = "test://static/resource/{id}" } |
| 57 | + new ResourceTemplate { Name = "Template Resource", Description = "A template resource with a numeric ID", UriTemplate = "test://template/resource/{id}" } |
48 | 58 | ] |
49 | 59 | }; |
50 | 60 | }) |
51 | 61 | .WithReadResourceHandler(async (ctx, ct) => |
52 | 62 | { |
53 | 63 | var uri = ctx.Params?.Uri; |
54 | 64 |
|
55 | | - if (uri is null || !uri.StartsWith("test://static/resource/")) |
| 65 | + if (uri == "test://direct/text/resource") |
| 66 | + { |
| 67 | + return new ReadResourceResult |
| 68 | + { |
| 69 | + Contents = [new TextResourceContents |
| 70 | + { |
| 71 | + Text = "This is a direct resource", |
| 72 | + MimeType = "text/plain", |
| 73 | + Uri = uri, |
| 74 | + }] |
| 75 | + }; |
| 76 | + } |
| 77 | + |
| 78 | + if (uri is null || !uri.StartsWith("test://template/resource/")) |
56 | 79 | { |
57 | 80 | throw new NotSupportedException($"Unknown resource: {uri}"); |
58 | 81 | } |
59 | 82 |
|
60 | | - int index = int.Parse(uri["test://static/resource/".Length..]) - 1; |
| 83 | + int index = int.Parse(uri["test://template/resource/".Length..]) - 1; |
61 | 84 |
|
62 | 85 | if (index < 0 || index >= ResourceGenerator.Resources.Count) |
63 | 86 | { |
|
0 commit comments