Update content according to latest spec (#513)

* Update content according to latest spec

* Add Title to a bunch of types

* Add _meta to lots of types

* Address feedback, more cleanup, fix NAOT test failure
This commit is contained in:
Stephen Toub 2025-06-16 19:39:41 -04:00 • committed by GitHub
commit 2bcff315f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -101,7 +101,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
case "test://ResourceTemplate2":
return new ReadResourceResult()
{
Contents = [new TextResourceContents() { Text = request.Params?.Uri ?? "(null)" }]
Contents = [new TextResourceContents { Text = request.Params?.Uri ?? "(null)" }]
};
}
@ -196,6 +196,24 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
Assert.DoesNotContain(resources, t => t.Name == "NewResource");
}
[Fact]
public async Task TitleAttributeProperty_PropagatedToTitle()
{
await using IMcpClient client = await CreateMcpClientForServer();
var resources = await client.ListResourcesAsync(cancellationToken: TestContext.Current.CancellationToken);
Assert.NotNull(resources);
Assert.NotEmpty(resources);
McpClientResource resource = resources.First(t => t.Name == nameof(SimpleResources.SomeNeatDirectResource));
Assert.Equal("This is a title", resource.Title);
var resourceTemplates = await client.ListResourceTemplatesAsync(cancellationToken: TestContext.Current.CancellationToken);
Assert.NotNull(resourceTemplates);
Assert.NotEmpty(resourceTemplates);
McpClientResourceTemplate resourceTemplate = resourceTemplates.First(t => t.Name == nameof(SimpleResources.SomeNeatTemplatedResource));
Assert.Equal("This is another title", resourceTemplate.Title);
}
[Fact]
public async Task Throws_When_Resource_Fails()
{
@ -273,10 +291,10 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
[McpServerResourceType]
public sealed class SimpleResources
{
[McpServerResource, Description("Some neat direct resource")]
[McpServerResource(Title = "This is a title"), Description("Some neat direct resource")]
public static string SomeNeatDirectResource() => "This is a neat resource";
[McpServerResource, Description("Some neat resource with parameters")]
[McpServerResource(Title = "This is another title"), Description("Some neat resource with parameters")]
public static string SomeNeatTemplatedResource(string name) => $"This is a neat resource with parameters: {name}";
[McpServerResource]