* 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
* Set IsError on CallToolResponse to true when result is ErrorContent
* Updated the `IsError` determination for a list of AIContent to require that all items in `contentItems` are instances of `ErrorContent` and that the collection is not empty
* Introduce ConvertAiContentEnumerableToCallToolResponse to transform an IEnumerable<AIContent> into a CallToolResponse
* Move location of ConvertAIContentEnumerableToCallToolResponse helper function
---------
Co-authored-by: Andy Tagg <antagg@microsoft.com>
* Adds test to show where trace IDs are encoded
Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
* update impl to params._meta
Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
---------
Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
* Add SchemaCreateOptions in McpServerToolCreateOptions
* Use TransformSchemaNode for SchemaCreateOptions testing
* Add SchemaCreateOptions in McpServerPromptCreateOptions also
* Add idle session pruning tests
* Remove redundant CTS from StreamableHttpHandler
* StreamableHttpServerTransport.HandlePostRequest already creates the equivelant CTS
which DeleteRequest_CompletesSession_WhichCancelsLongRunningToolCalls verifies
* Fix accept header validation for GET
* Use InvalidOperationException for transport-not-connected errors in doc comments
* Fix flaky Cancellation_ThrowsCancellationException test
- Changes IJsonRpcMessage to an abstract base class so RelatedTransport will always be available
- Streamable HTTP supports multiple concurrent HTTP request with their own indpendent SSE response streams
- RelatedTransport indicates the source or destination of the JsonRpcMessage
- Changes the default RequestId to a JSON number for better compatibility with MCP servers in the wild
* Simplify ModelContextProtocol.AspNetCore README
* Add StreamableHttpHandler
* Use "docker info" in CheckIsDockerAvailable
* Call WithHttpTransport in samples, tests and README
* Cleanup test namespaces
* Add CanConnect_WithMcpClient_AfterCustomizingRoute test
* Simplify relative URI handling
* Handle request made directly to the MapMcp route pattern
* Add Messages_FromNewUser_AreRejected test
* Fix README
* Shorten UserIdClaim ValueTuple names
* Remove MaxReconnectAttempts and ReconnectDelay from SseClientTransportOptions
- Add proper AdditionalHeaders support
* Remove code coverage PR commenting
* Only run markdown-link-check when markdown files are updated
* Declare CI workflow permissions
* Refactor release workflow and declare permissions
* Pin all actions to SHAs
* Run CI manually, on all pushes to main, or if code changes in a PR
* NuGet publishing doesn't need any permissions
* AI generated `///` comment updates
* Fix compilation issues
* Fix incorrect XML comment structure
* Update all Client comments
* Update all Configuration comments
* Update all Messages comments
* Update all Transport comments
* Update all Types comments
* Update all Server comments
* Undo some commenting
---------
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible.
* Fix merge conflicts.
* Update tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj
Co-authored-by: Stephen Halter <halter73@gmail.com>
* Revert "Fix merge conflicts."
This reverts commit 852169b96786bad2144795540fa164e20b4b197e.
* Fix merge conflicts
---------
Co-authored-by: Stephen Halter <halter73@gmail.com>
* Fix race in TransportBase.SetConnected
- Previously the ChannelWriter could already be completed if multiple
threads raced in SetConnected(false)
* Fix WriteMessageAsync IsConnected test
* Fixes#248 - Add CultureInfo.InvariantCulture to string interpolation for langitude and longitude so the sample works everywhere.
* Update samples/QuickstartWeatherServer/Tools/WeatherTools.cs
Co-authored-by: Stephen Toub <stoub@microsoft.com>
---------
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update markdown-link-check to ignore external links causing 403 in CI
* Apply wildcards on ignored links
* Bump version of mlc to latest to gain --ignore-links arg
* Do not warn on redirects from markdown-link-check action
* Do not warn on redirects from markdown-link-check action
* Update comment
* Propagate CancellationToken request cancellation to remote endpoint
* Refactor existing tests to have a shared base class
* Add cancellation tests
---------
Co-authored-by: Stephen Toub <stoub@microsoft.com>