csharp-sdk/tests/ModelContextProtocol.Tests
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Stephen Toub d86b3277d4
Add McpServer/ClientResource{Template} and friends (#391)
* Add McpServer/ClientResource{Template} and friends

This PR copies the same design used by tools and prompts to add McpServerResource, McpServerResourceAttribute, McpServerResourceTypeAttribute, McpClientResource, and then all of those for ResourceTemplate as well.

Unlike the others, [McpServerResource] is permitted not only on methods but also on properties. This convenience is afforded because such resources aren't parameterized, and thus can be easily modeled as properties, likely auto-props, e.g.
```C#
[McpServerResource]
public static BlobResourceContents MyAmazingData { get; } = Create();
```

Details about resources can be encoded into the attributes or provided via McpServerResource{Template}.Create methods. If not URI is explicitly defined, one is derived from the member name and arguments. For templates, this means manufacturing a URI template that includes variables for all non-DI parameters.

This also fixes a few issues discovered along the way:
- McpClientExtensions are updated to use `ValueTask<T>` instead of `Task<T>` where relevant.
- McpServerPrompt was missing handling for progress notifications; that's been rectified. It was also missing configuring the description on the ProtocolPrompt.
- Renamed IMcpServerPrimitive.Name to Id. For resources, names aren't unique.
- After going back and forth, updated McpServer to not fail for missing handlers and to instead register default handlers. It simplifies the implementation and makes it more consistent.
- Added a bunch of primitive types into the McpJsonUtilities JSON source generator context so that such primitives are usable with tools/prompts/resources without folks being required to add them into their own context for Native AOT. I think we should consider pushing this down to AIJsonUtilities, instead, and that will then flow up to McpJsonUtilities automatically.

* Address feedback
2025-05-09 18:21:11 -04:00
..
Client Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
Configuration Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
Protocol Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
Server Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
Transport Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
ClientIntegrationTestFixture.cs Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible. (#254) 2025-04-09 19:16:53 +01:00
ClientIntegrationTests.cs Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
ClientServerTestBase.cs Improve testing for StreamableHttpHandler and IdleTrackingBackgroundService (#345) 2025-04-24 10:49:02 -07:00
DiagnosticTests.cs Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00
DockerEverythingServerTests.cs Wrap each request in a service scope (#276) 2025-04-11 19:19:12 -04:00
EverythingSseServerFixture.cs Add StreamableHttpHandler and WithHttpTransport (#291) 2025-04-14 10:15:33 -04:00
GlobalUsings.cs Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible. (#254) 2025-04-09 19:16:53 +01:00
McpJsonUtilitiesTests.cs Disable STJ reflection for testing. (#266) 2025-04-10 16:02:00 +01:00
ModelContextProtocol.Tests.csproj Improve testing for StreamableHttpHandler and IdleTrackingBackgroundService (#345) 2025-04-24 10:49:02 -07:00
StdioServerIntegrationTests.cs Fix StdioServerTransport.DisposeAsync hang (#235) 2025-04-08 10:20:16 -07:00
TestAttributes.cs Add initial Activity / Metric support (#183) 2025-04-02 11:09:05 -04:00