From 7f7306fc41dfff339b03bd162872a28f64f0356c Mon Sep 17 00:00:00 2001 From: Stephen Walsh Date: Wed, 28 Oct 2026 14:00:57 +0000 Subject: [PATCH 1/4] Run the MCP Inspector in Docker Compose, pointed at the server docker compose up now also starts the official MCP Inspector on localhost:6274, already configured for the server over Streamable HTTP, so the tools, their descriptions and input schemas can be browsed and run without installing anything. --- README.md | 2 +- docker-compose.yml | 9 +++++++++ docs/RUN.md | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f4fc306..8798de2 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --author " docker compose up -d ``` -Then open the MCP endpoint (connect with an MCP client such as the [MCP Inspector](https://github.com/modelcontextprotocol/inspector)) at . See [docs/RUN.md](docs/RUN.md) for every way to run it. +Then open the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) at . It's already pointed at the MCP endpoint (), so connect and open **Tools** to browse and run them. See [docs/RUN.md](docs/RUN.md) for every way to run it. The `Dockerfile` has stages for testing, publishing and running, so you can build just the part you need. You can also stamp a version into the assembly. diff --git a/docker-compose.yml b/docker-compose.yml index 14946d5..ca1bb02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,15 @@ services: - cleanmodelcontextprotocol_network depends_on: - seq + inspector: + image: ghcr.io/modelcontextprotocol/inspector:2.12.0 + command: ["--web", "--transport", "http", "--server-url", "http://api:8080"] + ports: + - "127.0.0.1:6274:6274" + networks: + - cleanmodelcontextprotocol_network + depends_on: + - api seq: image: datalust/seq:latest ports: diff --git a/docs/RUN.md b/docs/RUN.md index bece1f6..69edcad 100644 --- a/docs/RUN.md +++ b/docs/RUN.md @@ -12,13 +12,14 @@ dotnet run --project ./src/Presentation ## Docker Compose -`docker-compose.yml` starts the app and a Seq container for logs. +`docker-compose.yml` starts the app, the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) already pointed at it, and a Seq container for logs. ``` bash docker compose up -d --build ``` -- App: (MCP endpoint (connect with an MCP client such as the [MCP Inspector](https://github.com/modelcontextprotocol/inspector))) +- App: (MCP endpoint, Streamable HTTP) +- MCP Inspector: . Flip the switch on the server card to connect, then open **Tools** to see every tool with its description and input schema and run it. - Seq: To shut the containers down: From 0231b12b115efe2474cbb051fa14257935e896b1 Mon Sep 17 00:00:00 2001 From: Stephen Walsh Date: Wed, 28 Oct 2026 15:38:30 +0000 Subject: [PATCH 2/4] feat: give every MCP tool agent-ready metadata Rename the tools by resource (authors_list, movies_get, reviews_create and so on), add titles and the read-only, destructive, idempotent and open-world hints, and rewrite the descriptions and parameter names for agents. The server instructions now describe the domain instead of output formatting, the server info has a proper title and an absolute icon URL, and not-found and validation errors tell the agent how to recover. The server now runs stateless at /mcp, and a tools/list test pins the names, titles and hints. --- README.md | 7 +- docker-compose.yml | 2 +- docs/RUN.md | 2 +- src/Presentation/Errors/ToolErrorFilter.cs | 17 +++-- .../WebApplicationBuilderExtensions.cs | 24 ++++--- .../Extensions/WebApplicationExtensions.cs | 2 +- .../Properties/launchSettings.json | 3 +- src/Presentation/Tools/AuthorTools.cs | 17 +++-- src/Presentation/Tools/MovieTools.cs | 17 +++-- src/Presentation/Tools/ReviewTools.cs | 53 +++++++------- src/Presentation/Tools/VersionTools.cs | 4 +- .../Tools/AuthorToolTests.cs | 24 +++---- .../Tools/BaseToolTests.cs | 2 +- .../Tools/MovieToolTests.cs | 24 +++---- .../Tools/ReviewToolTests.cs | 54 +++++++------- .../Tools/ToolListTests.cs | 71 +++++++++++++++++++ .../Tools/VersionToolTests.cs | 2 +- .../Errors/ToolErrorFilterTests.cs | 16 ++++- .../Tools/AuthorToolTests.cs | 4 +- .../Tools/MovieToolTests.cs | 4 +- .../Tools/ReviewToolTests.cs | 4 +- 21 files changed, 230 insertions(+), 123 deletions(-) create mode 100644 tests/Presentation.Tests.Integration/Tools/ToolListTests.cs diff --git a/README.md b/README.md index 8798de2..b522130 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --author " docker compose up -d ``` -Then open the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) at . It's already pointed at the MCP endpoint (), so connect and open **Tools** to browse and run them. See [docs/RUN.md](docs/RUN.md) for every way to run it. +Then open the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) at . It's already pointed at the MCP endpoint (), so connect and open **Tools** to browse and run them. See [docs/RUN.md](docs/RUN.md) for every way to run it. The `Dockerfile` has stages for testing, publishing and running, so you can build just the part you need. You can also stamp a version into the assembly. @@ -79,11 +79,12 @@ The one deliberate break from Clean Architecture is that the Presentation projec ## Features -- MCP server using the [MCP C# SDK](https://github.com/modelcontextprotocol/csharp-sdk) +- MCP server using the [MCP C# SDK](https://github.com/modelcontextprotocol/csharp-sdk), stateless Streamable HTTP at `/mcp` +- Tools named by resource (`movies_list`, `reviews_create`) with titles, read-only, destructive and idempotent hints, and descriptions written for agents - Logging using [Serilog](https://github.com/serilog/serilog), with [Seq](https://datalust.co/seq) when running in Docker - Mediator pattern using [Mediator](https://github.com/martinothamar/Mediator) - Validation using [FluentValidation](https://github.com/FluentValidation/FluentValidation) in an Application pipeline behaviour -- Tool errors mapped from Application exceptions by a single call-tool filter +- Tool errors mapped from Application exceptions by a single call-tool filter, with messages that tell the agent how to recover - Object mapping using [Mapperly](https://mapperly.riok.app) - In-memory data using [Entity Framework Core](https://learn.microsoft.com/ef/core/providers/in-memory/) seeded with [Bogus](https://github.com/bchavez/Bogus) - Testing using [xUnit](https://xunit.net), [Shouldly](https://github.com/shouldly/shouldly) and [NSubstitute](https://github.com/nsubstitute/NSubstitute), with coverage from [Coverlet](https://github.com/coverlet-coverage/coverlet) diff --git a/docker-compose.yml b/docker-compose.yml index ca1bb02..7f5267a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: - seq inspector: image: ghcr.io/modelcontextprotocol/inspector:2.12.0 - command: ["--web", "--transport", "http", "--server-url", "http://api:8080"] + command: ["--web", "--transport", "http", "--server-url", "http://api:8080/mcp"] ports: - "127.0.0.1:6274:6274" networks: diff --git a/docs/RUN.md b/docs/RUN.md index 69edcad..9ee7f48 100644 --- a/docs/RUN.md +++ b/docs/RUN.md @@ -18,7 +18,7 @@ dotnet run --project ./src/Presentation docker compose up -d --build ``` -- App: (MCP endpoint, Streamable HTTP) +- App: (MCP endpoint, Streamable HTTP) - MCP Inspector: . Flip the switch on the server card to connect, then open **Tools** to see every tool with its description and input schema and run it. - Seq: diff --git a/src/Presentation/Errors/ToolErrorFilter.cs b/src/Presentation/Errors/ToolErrorFilter.cs index c46e932..16516cf 100644 --- a/src/Presentation/Errors/ToolErrorFilter.cs +++ b/src/Presentation/Errors/ToolErrorFilter.cs @@ -20,19 +20,19 @@ public static McpRequestHandler Filter(Mc } catch (Exception exception) when (exception is not OperationCanceledException) { - return ToResult(exception); + return ToResult(exception, request?.Params?.Name); } }; } - public static CallToolResult ToResult(Exception exception) + public static CallToolResult ToResult(Exception exception, string toolName = null) { var message = exception switch { ValidationException validationException => "Validation Failed: " + string.Join(" ", validationException.Errors .Select(e => $"{e.PropertyName}: {e.ErrorMessage}") - .Distinct()), - NotFoundException => $"Not Found: {exception.Message}", + .Distinct()) + " Correct the arguments and call the tool again.", + NotFoundException => $"Not Found: {exception.Message}{ListToolHint(toolName)}", _ => "Error: An error occurred while processing your request." }; @@ -42,4 +42,13 @@ public static CallToolResult ToResult(Exception exception) Content = [new TextContentBlock { Text = message }] }; } + + private static string ListToolHint(string toolName) + { + var separator = toolName?.IndexOf('_') ?? -1; + + return separator > 0 + ? $" Check the ids, using {toolName[..separator]}_list or the other list tools to find valid ones." + : string.Empty; + } } diff --git a/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs b/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs index 28c0ee0..3e4bf3d 100644 --- a/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs +++ b/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs @@ -61,28 +61,30 @@ public static WebApplicationBuilder ConfigureApplicationBuilder(this WebApplicat { options.ServerInfo = new() { - Name = "Clean Model Context Protocol", - Description = "A demonstration of the Clean Model Context Protocol in a .NET application", - Title = "Clean Model Context Protocol - Presentation Layer", + Name = "clean-model-context-protocol", + Title = "Clean Model Context Protocol", + Description = "Movies, the authors who review them, and their star ratings, served by a Clean Architecture .NET MCP server.", Version = assembly?.GetCustomAttribute()?.InformationalVersion ?? string.Empty, WebsiteUrl = "https://github.com/stphnwlsh/CleanModelContextProtocol", Icons = [ new() { - Source = "images/Icon.png", + Source = "https://raw.githubusercontent.com/stphnwlsh/CleanModelContextProtocol/main/icon.png", MimeType = "image/png" } ], }; - options.ServerInstructions = "You are a helpful assistant for handling requests related to movies, " + - "authors, and reviews. Use the available tools to retrieve information about movies, authors, and " + - "reviews based on the queries you receive. Always ensure that your responses are accurate and relevant " + - "to the user's request. Return the full sets of data anc convert them into tabulated markdown formats " + - "for display where sensible. Some datasets involve a number of sub objects, please calculate a count of " + - "that data for better formatting."; + options.ServerInstructions = """ + This server holds a catalogue of movies, the authors who review them, and their reviews. + A review links one author to one movie with a star rating from 1 (worst) to 5 (best). + Every movie, author and review is identified by a GUID id. Ids are never guessable, so look them up + with movies_list, authors_list or reviews_list before calling a tool that needs one. + To change a review use reviews_update, which overwrites the author, movie and stars together. + reviews_delete can't be undone, so confirm with the user before calling it. + """; }) - .WithHttpTransport() + .WithHttpTransport(options => options.Stateless = true) .WithToolsFromAssembly() .WithRequestFilters(filters => filters.AddCallToolFilter(ToolErrorFilter.Filter)); diff --git a/src/Presentation/Extensions/WebApplicationExtensions.cs b/src/Presentation/Extensions/WebApplicationExtensions.cs index 75f2544..d6c3709 100644 --- a/src/Presentation/Extensions/WebApplicationExtensions.cs +++ b/src/Presentation/Extensions/WebApplicationExtensions.cs @@ -17,7 +17,7 @@ public static WebApplication ConfigureApplication(this WebApplication app) #region Model Context Protocol - _ = app.MapMcp(); + _ = app.MapMcp("/mcp"); #endregion Model Context Protocol diff --git a/src/Presentation/Properties/launchSettings.json b/src/Presentation/Properties/launchSettings.json index 82ac895..227f1a5 100644 --- a/src/Presentation/Properties/launchSettings.json +++ b/src/Presentation/Properties/launchSettings.json @@ -3,8 +3,7 @@ "profiles": { "CleanModelContextProtocol": { "commandName": "Project", - "launchBrowser": true, - "launchUrl": "swagger", + "launchBrowser": false, "applicationUrl": "https://localhost:7032;http://localhost:5032", "environmentVariables": { "DOTNET_ENVIRONMENT": "local" diff --git a/src/Presentation/Tools/AuthorTools.cs b/src/Presentation/Tools/AuthorTools.cs index 26fd2bd..bbfa88e 100644 --- a/src/Presentation/Tools/AuthorTools.cs +++ b/src/Presentation/Tools/AuthorTools.cs @@ -9,22 +9,25 @@ namespace CleanModelContextProtocol.Presentation.Tools; [McpServerToolType] public static class AuthorTools { - [McpServerTool(Name = "GetAllAuthors", ReadOnly = true)] - [Description("Get all authors in the system")] - public static async Task GetAllAuthors(ISender sender) + [McpServerTool(Name = "authors_list", Title = "List authors", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("List every author who has written reviews, with their id, first and last name, and the reviews they have written. " + + "Use this to find an author's id before calling authors_get, reviews_create or reviews_update.")] + public static async Task ListAuthors(ISender sender) { var result = await sender.Send(new Queries.GetAuthors.GetAuthorsQuery()); return JsonSerializer.Serialize(result); } - [McpServerTool(Name = "GetAuthorById", ReadOnly = true)] - [Description("Get a specific author by their unique ID")] - public static async Task GetAuthorById(ISender sender, [Description("The GUID of the author")] Guid id) + [McpServerTool(Name = "authors_get", Title = "Get author", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("Get one author by id, including every review they have written and the movie each review is for.")] + public static async Task GetAuthor( + ISender sender, + [Description("The author's id (a GUID). Use authors_list to find it.")] Guid authorId) { return JsonSerializer.Serialize(await sender.Send(new Queries.GetAuthorById.GetAuthorByIdQuery { - Id = id + Id = authorId })); } } diff --git a/src/Presentation/Tools/MovieTools.cs b/src/Presentation/Tools/MovieTools.cs index 30546e7..bc84866 100644 --- a/src/Presentation/Tools/MovieTools.cs +++ b/src/Presentation/Tools/MovieTools.cs @@ -9,22 +9,25 @@ namespace CleanModelContextProtocol.Presentation.Tools; [McpServerToolType] public static class MovieTools { - [McpServerTool(Name = "GetAllMovies", ReadOnly = true)] - [Description("Get all movies in the system")] - public static async Task GetAllMovies(ISender sender) + [McpServerTool(Name = "movies_list", Title = "List movies", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("List every movie with its id, title and reviews. " + + "Use this to find a movie's id before calling movies_get, reviews_create or reviews_update.")] + public static async Task ListMovies(ISender sender) { var result = await sender.Send(new Queries.GetMovies.GetMoviesQuery()); return JsonSerializer.Serialize(result); } - [McpServerTool(Name = "GetMovieById", ReadOnly = true)] - [Description("Get a specific movie by its unique ID")] - public static async Task GetMovieById(ISender sender, [Description("The GUID of the movie")] Guid id) + [McpServerTool(Name = "movies_get", Title = "Get movie", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("Get one movie by id, including every review of it with the star rating and the author who wrote it.")] + public static async Task GetMovie( + ISender sender, + [Description("The movie's id (a GUID). Use movies_list to find it.")] Guid movieId) { return JsonSerializer.Serialize(await sender.Send(new Queries.GetMovieById.GetMovieByIdQuery { - Id = id + Id = movieId })); } } diff --git a/src/Presentation/Tools/ReviewTools.cs b/src/Presentation/Tools/ReviewTools.cs index 14470f4..d8d7bfc 100644 --- a/src/Presentation/Tools/ReviewTools.cs +++ b/src/Presentation/Tools/ReviewTools.cs @@ -10,33 +10,35 @@ namespace CleanModelContextProtocol.Presentation.Tools; [McpServerToolType] public static class ReviewTools { - [McpServerTool(Name = "GetAllReviews", ReadOnly = true)] - [Description("Get all reviews in the system")] - public static async Task GetAllReviews(ISender sender) + [McpServerTool(Name = "reviews_list", Title = "List reviews", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("List every review with its id, star rating (1 to 5), the movie it is for and the author who wrote it.")] + public static async Task ListReviews(ISender sender) { var result = await sender.Send(new Queries.GetReviews.GetReviewsQuery()); return JsonSerializer.Serialize(result); } - [McpServerTool(Name = "GetReviewById", ReadOnly = true)] - [DisplayName("GetReviewById2")] - [Description("Get a specific review by its unique ID")] - public static async Task GetReviewById(ISender sender, [Description("The GUID of the review")] Guid id) + [McpServerTool(Name = "reviews_get", Title = "Get review", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("Get one review by id, with its star rating, the movie it is for and the author who wrote it.")] + public static async Task GetReview( + ISender sender, + [Description("The review's id (a GUID). Use reviews_list to find it.")] Guid reviewId) { return JsonSerializer.Serialize(await sender.Send(new Queries.GetReviewById.GetReviewByIdQuery { - Id = id + Id = reviewId })); } - [McpServerTool(Name = "CreateReview")] - [Description("Create a new review linking an author and a movie")] + [McpServerTool(Name = "reviews_create", Title = "Create review", ReadOnly = false, Destructive = false, Idempotent = false, OpenWorld = false)] + [Description("Create a review of a movie by an author with a star rating from 1 to 5, and return the new review. " + + "Each call creates another review, so don't retry a call that succeeded.")] public static async Task CreateReview( ISender sender, - [Description("The GUID of the author writing the review")] Guid authorId, - [Description("The GUID of the movie being reviewed")] Guid movieId, - [Description("Star rating for the movie (e.g. 1-5)")] int stars) + [Description("The id of the author writing the review. Use authors_list to find it.")] Guid authorId, + [Description("The id of the movie being reviewed. Use movies_list to find it.")] Guid movieId, + [Description("The star rating, a whole number from 1 (worst) to 5 (best).")] int stars) { var result = await sender.Send(new Commands.CreateReview.CreateReviewCommand { @@ -48,18 +50,19 @@ public static async Task CreateReview( return JsonSerializer.Serialize(result); } - [McpServerTool(Name = "UpdateReview")] - [Description("Update an existing review")] + [McpServerTool(Name = "reviews_update", Title = "Update review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false)] + [Description("Replace an existing review's author, movie and star rating. Every field is overwritten, " + + "so pass the current author and movie ids when you only want to change the stars.")] public static async Task UpdateReview( ISender sender, - [Description("The GUID of the review to update")] Guid id, - [Description("The GUID of the author writing the review")] Guid authorId, - [Description("The GUID of the movie being reviewed")] Guid movieId, - [Description("Star rating for the movie (e.g. 1-5)")] int stars) + [Description("The id of the review to update. Use reviews_list to find it.")] Guid reviewId, + [Description("The id of the author writing the review. Use authors_list to find it.")] Guid authorId, + [Description("The id of the movie being reviewed. Use movies_list to find it.")] Guid movieId, + [Description("The star rating, a whole number from 1 (worst) to 5 (best).")] int stars) { _ = await sender.Send(new Commands.UpdateReview.UpdateReviewCommand { - Id = id, + Id = reviewId, AuthorId = authorId, MovieId = movieId, Stars = stars @@ -68,13 +71,15 @@ public static async Task UpdateReview( return "Review updated successfully"; } - [McpServerTool(Name = "DeleteReview")] - [Description("Delete a review by its unique ID")] - public static async Task DeleteReview(ISender sender, [Description("The GUID of the review to delete")] Guid id) + [McpServerTool(Name = "reviews_delete", Title = "Delete review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false)] + [Description("Permanently delete a review. This can't be undone, so confirm with the user first.")] + public static async Task DeleteReview( + ISender sender, + [Description("The id of the review to delete. Use reviews_list to find it.")] Guid reviewId) { _ = await sender.Send(new Commands.DeleteReview.DeleteReviewCommand { - Id = id + Id = reviewId }); return "Review deleted successfully"; diff --git a/src/Presentation/Tools/VersionTools.cs b/src/Presentation/Tools/VersionTools.cs index 1e86066..53baf03 100644 --- a/src/Presentation/Tools/VersionTools.cs +++ b/src/Presentation/Tools/VersionTools.cs @@ -8,8 +8,8 @@ namespace CleanModelContextProtocol.Presentation.Tools; [McpServerToolType] public static class VersionTools { - [McpServerTool(Name = "GetVersion", ReadOnly = true)] - [Description("Get the current application version details")] + [McpServerTool(Name = "server_get_version", Title = "Get server version", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [Description("Get the version of this server: the file version and the informational version, which includes the commit it was built from.")] public static async Task GetVersion(ISender sender) { var result = await sender.Send(new Queries.GetVersion.GetVersionQuery()); diff --git a/tests/Presentation.Tests.Integration/Tools/AuthorToolTests.cs b/tests/Presentation.Tests.Integration/Tools/AuthorToolTests.cs index 77c0dff..6086f2c 100644 --- a/tests/Presentation.Tests.Integration/Tools/AuthorToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/AuthorToolTests.cs @@ -13,7 +13,7 @@ public class AuthorToolTests : BaseToolTests public async Task GetAllAuthors_ShouldReturn_Authors() { // Act - var result = await this.Client.CallToolAsync("GetAllAuthors"); + var result = await this.Client.CallToolAsync("authors_list"); var text = result.Content.OfType().First().Text; var authors = text.Deserialize>(); @@ -48,13 +48,13 @@ public async Task GetAllAuthors_ShouldReturn_Authors() public async Task GetAuthorById_ShouldReturn_Author() { // Arrange - var allResult = await this.Client.CallToolAsync("GetAllAuthors"); + var allResult = await this.Client.CallToolAsync("authors_list"); var allText = allResult.Content.OfType().First().Text; var firstAuthor = allText.Deserialize>()[0]; // Act - var result = await this.Client.CallToolAsync("GetAuthorById", - new Dictionary { ["id"] = firstAuthor.Id }); + var result = await this.Client.CallToolAsync("authors_get", + new Dictionary { ["authorId"] = firstAuthor.Id }); var text = result.Content.OfType().First().Text; var author = text.Deserialize(); @@ -83,26 +83,26 @@ public async Task GetAuthorById_ShouldReturn_Author() public async Task GetAuthorById_WithEmptyId_ShouldReturn_ValidationError() { // Act - var result = await this.Client.CallToolAsync("GetAuthorById", - new Dictionary { ["id"] = Guid.Empty }); + var result = await this.Client.CallToolAsync("authors_get", + new Dictionary { ["authorId"] = Guid.Empty }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Validation Failed: Id: An Author Id was not supplied."); + text.ShouldBe("Validation Failed: Id: An Author Id was not supplied. Correct the arguments and call the tool again."); } [Fact] public async Task GetAuthorById_WithUnknownId_ShouldReturn_NotFoundError() { // Act - var result = await this.Client.CallToolAsync("GetAuthorById", - new Dictionary { ["id"] = Guid.NewGuid() }); + var result = await this.Client.CallToolAsync("authors_get", + new Dictionary { ["authorId"] = Guid.NewGuid() }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Not Found: The Author with the supplied id was not found."); + text.ShouldBe("Not Found: The Author with the supplied id was not found. Check the ids, using authors_list or the other list tools to find valid ones."); } [Theory] @@ -113,8 +113,8 @@ public async Task GetAuthorById_WithInvalidId_ShouldReturn_Error(string input) try { // Act - var result = await this.Client.CallToolAsync("GetAuthorById", - new Dictionary { ["id"] = input }); + var result = await this.Client.CallToolAsync("authors_get", + new Dictionary { ["authorId"] = input }); // Assert result.IsError.ShouldBe(true); diff --git a/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs b/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs index 9e9633e..bcebd96 100644 --- a/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs @@ -18,7 +18,7 @@ public async Task InitializeAsync() this.application = new CleanModelContextProtocolApplication(); this.Client = await McpClient.CreateAsync( new HttpClientTransport( - new HttpClientTransportOptions { Endpoint = new Uri("http://localhost") }, + new HttpClientTransportOptions { Endpoint = new Uri("http://localhost/mcp") }, this.application.CreateClient(), null, false), diff --git a/tests/Presentation.Tests.Integration/Tools/MovieToolTests.cs b/tests/Presentation.Tests.Integration/Tools/MovieToolTests.cs index 5314d61..d45bae6 100644 --- a/tests/Presentation.Tests.Integration/Tools/MovieToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/MovieToolTests.cs @@ -13,7 +13,7 @@ public class MovieToolTests : BaseToolTests public async Task GetAllMovies_ShouldReturn_Movies() { // Act - var result = await this.Client.CallToolAsync("GetAllMovies"); + var result = await this.Client.CallToolAsync("movies_list"); var text = result.Content.OfType().First().Text; var movies = text.Deserialize>(); @@ -49,13 +49,13 @@ public async Task GetAllMovies_ShouldReturn_Movies() public async Task GetMovieById_ShouldReturn_Movie() { // Arrange - var allResult = await this.Client.CallToolAsync("GetAllMovies"); + var allResult = await this.Client.CallToolAsync("movies_list"); var allText = allResult.Content.OfType().First().Text; var firstMovie = allText.Deserialize>().First(m => m.Reviews?.Count > 0); // Act - var result = await this.Client.CallToolAsync("GetMovieById", - new Dictionary { ["id"] = firstMovie.Id }); + var result = await this.Client.CallToolAsync("movies_get", + new Dictionary { ["movieId"] = firstMovie.Id }); var text = result.Content.OfType().First().Text; var movie = text.Deserialize(); @@ -85,26 +85,26 @@ public async Task GetMovieById_ShouldReturn_Movie() public async Task GetMovieById_WithEmptyId_ShouldReturn_ValidationError() { // Act - var result = await this.Client.CallToolAsync("GetMovieById", - new Dictionary { ["id"] = Guid.Empty }); + var result = await this.Client.CallToolAsync("movies_get", + new Dictionary { ["movieId"] = Guid.Empty }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Validation Failed: Id: A Movie Id was not supplied."); + text.ShouldBe("Validation Failed: Id: A Movie Id was not supplied. Correct the arguments and call the tool again."); } [Fact] public async Task GetMovieById_WithUnknownId_ShouldReturn_NotFoundError() { // Act - var result = await this.Client.CallToolAsync("GetMovieById", - new Dictionary { ["id"] = Guid.NewGuid() }); + var result = await this.Client.CallToolAsync("movies_get", + new Dictionary { ["movieId"] = Guid.NewGuid() }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Not Found: The Movie with the supplied id was not found."); + text.ShouldBe("Not Found: The Movie with the supplied id was not found. Check the ids, using movies_list or the other list tools to find valid ones."); } [Theory] @@ -115,8 +115,8 @@ public async Task GetMovieById_WithInvalidId_ShouldReturn_Error(string input) try { // Act - var result = await this.Client.CallToolAsync("GetMovieById", - new Dictionary { ["id"] = input }); + var result = await this.Client.CallToolAsync("movies_get", + new Dictionary { ["movieId"] = input }); // Assert result.IsError.ShouldBe(true); diff --git a/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs b/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs index 41c984d..c8b9541 100644 --- a/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs @@ -15,7 +15,7 @@ public class ReviewToolTests : BaseToolTests public async Task GetAllReviews_ShouldReturn_Reviews() { // Act - var result = await this.Client.CallToolAsync("GetAllReviews"); + var result = await this.Client.CallToolAsync("reviews_list"); var text = result.Content.OfType().First().Text; var reviews = text.Deserialize>(); @@ -50,13 +50,13 @@ public async Task GetAllReviews_ShouldReturn_Reviews() public async Task GetReviewById_ShouldReturn_Review() { // Arrange - var allResult = await this.Client.CallToolAsync("GetAllReviews"); + var allResult = await this.Client.CallToolAsync("reviews_list"); var allText = allResult.Content.OfType().First().Text; var firstReview = allText.Deserialize>()[0]; // Act - var result = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = firstReview.Id }); + var result = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = firstReview.Id }); var text = result.Content.OfType().First().Text; var review = text.Deserialize(); @@ -84,16 +84,16 @@ public async Task GetReviewById_ShouldReturn_Review() public async Task CreateReview_ShouldReturn_Review() { // Arrange - var authorResult = await this.Client.CallToolAsync("GetAllAuthors"); + var authorResult = await this.Client.CallToolAsync("authors_list"); var authorText = authorResult.Content.OfType().First().Text; var author = authorText.Deserialize>()[0]; - var movieResult = await this.Client.CallToolAsync("GetAllMovies"); + var movieResult = await this.Client.CallToolAsync("movies_list"); var movieText = movieResult.Content.OfType().First().Text; var movie = movieText.Deserialize>()[0]; // Act - var result = await this.Client.CallToolAsync("CreateReview", + var result = await this.Client.CallToolAsync("reviews_create", new Dictionary { ["authorId"] = author.Id, @@ -124,23 +124,23 @@ public async Task CreateReview_ShouldReturn_Review() public async Task UpdateReview_ShouldReturn_Success() { // Arrange - var authorResult = await this.Client.CallToolAsync("GetAllAuthors"); + var authorResult = await this.Client.CallToolAsync("authors_list"); var authorText = authorResult.Content.OfType().First().Text; var author = authorText.Deserialize>()[0]; - var movieResult = await this.Client.CallToolAsync("GetAllMovies"); + var movieResult = await this.Client.CallToolAsync("movies_list"); var movieText = movieResult.Content.OfType().First().Text; var movie = movieText.Deserialize>()[0]; - var reviewsResult = await this.Client.CallToolAsync("GetAllReviews"); + var reviewsResult = await this.Client.CallToolAsync("reviews_list"); var reviewsText = reviewsResult.Content.OfType().First().Text; var existingReview = reviewsText.Deserialize>()[0]; // Act - var result = await this.Client.CallToolAsync("UpdateReview", + var result = await this.Client.CallToolAsync("reviews_update", new Dictionary { - ["id"] = existingReview.Id, + ["reviewId"] = existingReview.Id, ["authorId"] = author.Id, ["movieId"] = movie.Id, ["stars"] = 5 @@ -150,8 +150,8 @@ public async Task UpdateReview_ShouldReturn_Success() // Assert text.ShouldBe("Review updated successfully"); - var validateResult = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = existingReview.Id }); + var validateResult = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = existingReview.Id }); var validateText = validateResult.Content.OfType().First().Text; var updatedReview = validateText.Deserialize(); @@ -174,20 +174,20 @@ public async Task UpdateReview_ShouldReturn_Success() public async Task DeleteReview_ShouldReturn_Success() { // Arrange - var reviewsResult = await this.Client.CallToolAsync("GetAllReviews"); + var reviewsResult = await this.Client.CallToolAsync("reviews_list"); var reviewsText = reviewsResult.Content.OfType().First().Text; var existingReview = reviewsText.Deserialize>()[0]; // Act - var result = await this.Client.CallToolAsync("DeleteReview", - new Dictionary { ["id"] = existingReview.Id }); + var result = await this.Client.CallToolAsync("reviews_delete", + new Dictionary { ["reviewId"] = existingReview.Id }); var text = result.Content.OfType().First().Text; // Assert text.ShouldBe("Review deleted successfully"); - var validateResult = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = existingReview.Id }); + var validateResult = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = existingReview.Id }); var validateText = validateResult.Content.OfType().First().Text; validateText.ShouldStartWith("Not Found:"); @@ -197,26 +197,26 @@ public async Task DeleteReview_ShouldReturn_Success() public async Task GetReviewById_WithEmptyId_ShouldReturn_ValidationError() { // Act - var result = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = Guid.Empty }); + var result = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = Guid.Empty }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Validation Failed: Id: A Review Id was not supplied."); + text.ShouldBe("Validation Failed: Id: A Review Id was not supplied. Correct the arguments and call the tool again."); } [Fact] public async Task GetReviewById_WithUnknownId_ShouldReturn_NotFoundError() { // Act - var result = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = Guid.NewGuid() }); + var result = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = Guid.NewGuid() }); var text = result.Content.OfType().First().Text; // Assert result.IsError.ShouldBe(true); - text.ShouldBe("Not Found: The Review with the supplied id was not found."); + text.ShouldBe("Not Found: The Review with the supplied id was not found. Check the ids, using reviews_list or the other list tools to find valid ones."); } [Theory] @@ -227,8 +227,8 @@ public async Task GetReviewById_WithInvalidId_ShouldReturn_Error(string input) try { // Act - var result = await this.Client.CallToolAsync("GetReviewById", - new Dictionary { ["id"] = input }); + var result = await this.Client.CallToolAsync("reviews_get", + new Dictionary { ["reviewId"] = input }); // Assert result.IsError.ShouldBe(true); diff --git a/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs b/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs new file mode 100644 index 0000000..0849c36 --- /dev/null +++ b/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs @@ -0,0 +1,71 @@ +namespace CleanModelContextProtocol.Presentation.Tests.Integration.Tools; + +using Shouldly; +using Xunit; + +public class ToolListTests : BaseToolTests +{ + public static TheoryData Tools => new() + { + { "authors_list", "List authors", true, false, true }, + { "authors_get", "Get author", true, false, true }, + { "movies_list", "List movies", true, false, true }, + { "movies_get", "Get movie", true, false, true }, + { "reviews_list", "List reviews", true, false, true }, + { "reviews_get", "Get review", true, false, true }, + { "reviews_create", "Create review", false, false, false }, + { "reviews_update", "Update review", false, true, true }, + { "reviews_delete", "Delete review", false, true, true }, + { "server_get_version", "Get server version", true, false, true } + }; + + [Fact] + public async Task ListTools_ShouldReturn_EveryTool() + { + // Act + var tools = await this.Client.ListToolsAsync(); + + // Assert + tools.Select(t => t.Name).ShouldBe(Tools.Select(t => (string)t[0]), ignoreOrder: true); + } + + [Theory] + [MemberData(nameof(Tools))] + public async Task ListTools_ShouldDescribe_Tool(string name, string title, bool readOnly, bool destructive, bool idempotent) + { + // Act + var tool = (await this.Client.ListToolsAsync()).Single(t => t.Name == name).ProtocolTool; + + // Assert + tool.Title.ShouldBe(title); + tool.Description.ShouldNotBeNullOrWhiteSpace(); + + _ = tool.Annotations.ShouldNotBeNull(); + tool.Annotations.ReadOnlyHint.ShouldBe(readOnly); + tool.Annotations.OpenWorldHint.ShouldBe(false); + tool.Annotations.IdempotentHint.ShouldBe(idempotent); + + if (!readOnly) + { + tool.Annotations.DestructiveHint.ShouldBe(destructive); + } + + foreach (var property in tool.InputSchema.GetProperty("properties").EnumerateObject()) + { + property.Value.GetProperty("description").GetString().ShouldNotBeNullOrWhiteSpace(); + } + } + + [Fact] + public async Task ServerInfo_ShouldDescribe_Server() + { + // Assert + var serverInfo = this.Client.ServerInfo; + + serverInfo.Name.ShouldBe("clean-model-context-protocol"); + serverInfo.Title.ShouldBe("Clean Model Context Protocol"); + this.Client.ServerInstructions.ShouldNotBeNullOrWhiteSpace(); + + await Task.CompletedTask; + } +} diff --git a/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs b/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs index 32bd661..41b038d 100644 --- a/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs @@ -10,7 +10,7 @@ public class VersionToolTests : BaseToolTests public async Task GetVersion_ShouldReturn_Version() { // Act - var result = await this.Client.CallToolAsync("GetVersion"); + var result = await this.Client.CallToolAsync("server_get_version"); var text = result.Content.OfType().First().Text; // Assert diff --git a/tests/Presentation.Tests.Unit/Errors/ToolErrorFilterTests.cs b/tests/Presentation.Tests.Unit/Errors/ToolErrorFilterTests.cs index b94e727..ed2c61f 100644 --- a/tests/Presentation.Tests.Unit/Errors/ToolErrorFilterTests.cs +++ b/tests/Presentation.Tests.Unit/Errors/ToolErrorFilterTests.cs @@ -54,7 +54,7 @@ public void ToResult_ShouldReturn_ValidationError() // Assert result.IsError.ShouldBe(true); result.Content.OfType().Single().Text - .ShouldBe("Validation Failed: AuthorId: An author id was not supplied to create the review. Stars: A star rating must be between 1 and 5."); + .ShouldBe("Validation Failed: AuthorId: An author id was not supplied to create the review. Stars: A star rating must be between 1 and 5. Correct the arguments and call the tool again."); } [Fact] @@ -68,6 +68,20 @@ public void ToResult_ShouldReturn_NotFoundError() result.Content.OfType().Single().Text.ShouldBe("Not Found: Expected Exception"); } + [Theory] + [InlineData("movies_get", "Not Found: Expected Exception Check the ids, using movies_list or the other list tools to find valid ones.")] + [InlineData("server", "Not Found: Expected Exception")] + [InlineData("_get", "Not Found: Expected Exception")] + public void ToResult_ShouldReturn_NotFoundErrorWithHint(string toolName, string expected) + { + // Act + var result = ToolErrorFilter.ToResult(new NotFoundException("Expected Exception"), toolName); + + // Assert + result.IsError.ShouldBe(true); + result.Content.OfType().Single().Text.ShouldBe(expected); + } + [Fact] public void ToResult_ShouldReturn_Error() { diff --git a/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs b/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs index e98855a..197dbce 100644 --- a/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs @@ -27,7 +27,7 @@ public async Task GetAllAuthors_ShouldReturn_JsonResult() ]); // Act - var response = await AuthorTools.GetAllAuthors(sender); + var response = await AuthorTools.ListAuthors(sender); // Assert var result = JsonSerializer.Deserialize>(response, JsonOptions); @@ -50,7 +50,7 @@ public async Task GetAuthorById_ShouldReturn_JsonResult() .ReturnsForAnyArgs(new Entities.Author(Guid.Empty, "Lorem", "Ipsum")); // Act - var response = await AuthorTools.GetAuthorById(sender, Guid.Empty); + var response = await AuthorTools.GetAuthor(sender, Guid.Empty); // Assert var result = JsonSerializer.Deserialize(response, JsonOptions); diff --git a/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs b/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs index a939450..bfd5e01 100644 --- a/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs @@ -27,7 +27,7 @@ public async Task GetAllMovies_ShouldReturn_JsonResult() ]); // Act - var response = await MovieTools.GetAllMovies(sender); + var response = await MovieTools.ListMovies(sender); // Assert var result = JsonSerializer.Deserialize>(response, JsonOptions); @@ -49,7 +49,7 @@ public async Task GetMovieById_ShouldReturn_JsonResult() .ReturnsForAnyArgs(new Entities.Movie(Guid.Empty, "Lorem Ipsum")); // Act - var response = await MovieTools.GetMovieById(sender, Guid.Empty); + var response = await MovieTools.GetMovie(sender, Guid.Empty); // Assert var result = JsonSerializer.Deserialize(response, JsonOptions); diff --git a/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs b/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs index abb1aa7..f096ed8 100644 --- a/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs @@ -36,7 +36,7 @@ public async Task GetAllReviews_ShouldReturn_JsonResult() .ReturnsForAnyArgs([SampleReview()]); // Act - var response = await ReviewTools.GetAllReviews(sender); + var response = await ReviewTools.ListReviews(sender); // Assert var result = JsonSerializer.Deserialize>(response, JsonOptions); @@ -62,7 +62,7 @@ public async Task GetReviewById_ShouldReturn_JsonResult() .ReturnsForAnyArgs(SampleReview()); // Act - var response = await ReviewTools.GetReviewById(sender, Guid.Empty); + var response = await ReviewTools.GetReview(sender, Guid.Empty); // Assert var result = JsonSerializer.Deserialize(response, JsonOptions); From b294ae31e1e4c91efa64bcc6b8f57170dc0a2e56 Mon Sep 17 00:00:00 2001 From: Stephen Walsh Date: Wed, 28 Oct 2026 15:41:46 +0000 Subject: [PATCH 3/4] feat: return typed, structured results from every MCP tool Tools now return Application entities instead of JSON strings, with UseStructuredContent so the SDK publishes an output schema and returns structuredContent alongside the JSON text. The tool serializer uses camelCase and the source-generated context, which was registered but never used. reviews_update returns the updated review, reviews_delete returns a small result object, and server_get_version returns an object instead of a markdown table. --- README.md | 1 + .../WebApplicationBuilderExtensions.cs | 17 +++---- src/Presentation/Models/DeletedReview.cs | 12 +++++ .../Serialization/AppJsonSerializerContext.cs | 2 + src/Presentation/Tools/AuthorTools.cs | 18 ++++---- src/Presentation/Tools/MovieTools.cs | 18 ++++---- src/Presentation/Tools/ReviewTools.cs | 46 +++++++++---------- src/Presentation/Tools/VersionTools.cs | 14 ++---- .../Tools/ReviewToolTests.cs | 17 ++++--- .../Tools/ToolListTests.cs | 2 + .../Tools/VersionToolTests.cs | 14 ++++-- .../Tools/AuthorToolTests.cs | 11 ++--- .../Tools/MovieToolTests.cs | 11 ++--- .../Tools/ReviewToolTests.cs | 29 ++++++------ .../Tools/VersionToolTests.cs | 6 +-- 15 files changed, 111 insertions(+), 107 deletions(-) create mode 100644 src/Presentation/Models/DeletedReview.cs diff --git a/README.md b/README.md index b522130..48cb600 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ The one deliberate break from Clean Architecture is that the Presentation projec - Logging using [Serilog](https://github.com/serilog/serilog), with [Seq](https://datalust.co/seq) when running in Docker - Mediator pattern using [Mediator](https://github.com/martinothamar/Mediator) - Validation using [FluentValidation](https://github.com/FluentValidation/FluentValidation) in an Application pipeline behaviour +- Typed tool results published with an output schema and returned as structured content as well as JSON text - Tool errors mapped from Application exceptions by a single call-tool filter, with messages that tell the agent how to recover - Object mapping using [Mapperly](https://mapperly.riok.app) - In-memory data using [Entity Framework Core](https://learn.microsoft.com/ef/core/providers/in-memory/) seeded with [Bogus](https://github.com/bchavez/Bogus) diff --git a/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs b/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs index 3e4bf3d..5e3a61b 100644 --- a/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs +++ b/src/Presentation/Extensions/WebApplicationBuilderExtensions.cs @@ -9,8 +9,8 @@ namespace CleanModelContextProtocol.Presentation.Extensions; using CleanModelContextProtocol.Presentation.Serialization; using Infrastructure; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http.Json; using Microsoft.Extensions.DependencyInjection; +using ModelContextProtocol; using Serilog; [ExcludeFromCodeCoverage] @@ -34,15 +34,12 @@ public static WebApplicationBuilder ConfigureApplicationBuilder(this WebApplicat #region Serialisation - _ = builder.Services.Configure(opt => + var serializerOptions = new JsonSerializerOptions(McpJsonUtilities.DefaultOptions) { - opt.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; - opt.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; - opt.SerializerOptions.PropertyNameCaseInsensitive = true; - opt.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - opt.SerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); - opt.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); - }); + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }; + serializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); #endregion Serialisation @@ -85,7 +82,7 @@ A review links one author to one movie with a star rating from 1 (worst) to 5 (b """; }) .WithHttpTransport(options => options.Stateless = true) - .WithToolsFromAssembly() + .WithToolsFromAssembly(serializerOptions: serializerOptions) .WithRequestFilters(filters => filters.AddCallToolFilter(ToolErrorFilter.Filter)); #endregion Model Context Protocol diff --git a/src/Presentation/Models/DeletedReview.cs b/src/Presentation/Models/DeletedReview.cs new file mode 100644 index 0000000..4920453 --- /dev/null +++ b/src/Presentation/Models/DeletedReview.cs @@ -0,0 +1,12 @@ +namespace CleanModelContextProtocol.Presentation.Models; + +using System.ComponentModel; + +/// +/// The result of deleting a review. +/// +/// The id of the review that was deleted. +/// Whether the review was deleted. +public record DeletedReview( + [property: Description("The id of the review that was deleted.")] Guid ReviewId, + [property: Description("Whether the review was deleted.")] bool Deleted); diff --git a/src/Presentation/Serialization/AppJsonSerializerContext.cs b/src/Presentation/Serialization/AppJsonSerializerContext.cs index f7b82e0..449d5a0 100644 --- a/src/Presentation/Serialization/AppJsonSerializerContext.cs +++ b/src/Presentation/Serialization/AppJsonSerializerContext.cs @@ -5,6 +5,7 @@ namespace CleanModelContextProtocol.Presentation.Serialization; using Application.Movies.Entities; using Application.Reviews.Entities; using Application.Versions.Entities; +using CleanModelContextProtocol.Presentation.Models; /// /// JSON serialization context for compile-time source generation. @@ -26,6 +27,7 @@ namespace CleanModelContextProtocol.Presentation.Serialization; [JsonSerializable(typeof(ReviewedMovie))] [JsonSerializable(typeof(Version))] [JsonSerializable(typeof(List))] +[JsonSerializable(typeof(DeletedReview))] public partial class AppJsonSerializerContext : JsonSerializerContext { } diff --git a/src/Presentation/Tools/AuthorTools.cs b/src/Presentation/Tools/AuthorTools.cs index bbfa88e..85bfa04 100644 --- a/src/Presentation/Tools/AuthorTools.cs +++ b/src/Presentation/Tools/AuthorTools.cs @@ -1,33 +1,31 @@ namespace CleanModelContextProtocol.Presentation.Tools; using System.ComponentModel; -using System.Text.Json; using Mediator; using ModelContextProtocol.Server; +using Entities = Application.Authors.Entities; using Queries = Application.Authors.Queries; [McpServerToolType] public static class AuthorTools { - [McpServerTool(Name = "authors_list", Title = "List authors", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "authors_list", Title = "List authors", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("List every author who has written reviews, with their id, first and last name, and the reviews they have written. " + "Use this to find an author's id before calling authors_get, reviews_create or reviews_update.")] - public static async Task ListAuthors(ISender sender) + public static async Task> ListAuthors(ISender sender) { - var result = await sender.Send(new Queries.GetAuthors.GetAuthorsQuery()); - - return JsonSerializer.Serialize(result); + return await sender.Send(new Queries.GetAuthors.GetAuthorsQuery()); } - [McpServerTool(Name = "authors_get", Title = "Get author", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "authors_get", Title = "Get author", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Get one author by id, including every review they have written and the movie each review is for.")] - public static async Task GetAuthor( + public static async Task GetAuthor( ISender sender, [Description("The author's id (a GUID). Use authors_list to find it.")] Guid authorId) { - return JsonSerializer.Serialize(await sender.Send(new Queries.GetAuthorById.GetAuthorByIdQuery + return await sender.Send(new Queries.GetAuthorById.GetAuthorByIdQuery { Id = authorId - })); + }); } } diff --git a/src/Presentation/Tools/MovieTools.cs b/src/Presentation/Tools/MovieTools.cs index bc84866..096e62b 100644 --- a/src/Presentation/Tools/MovieTools.cs +++ b/src/Presentation/Tools/MovieTools.cs @@ -1,33 +1,31 @@ namespace CleanModelContextProtocol.Presentation.Tools; using System.ComponentModel; -using System.Text.Json; using Mediator; using ModelContextProtocol.Server; +using Entities = Application.Movies.Entities; using Queries = Application.Movies.Queries; [McpServerToolType] public static class MovieTools { - [McpServerTool(Name = "movies_list", Title = "List movies", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "movies_list", Title = "List movies", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("List every movie with its id, title and reviews. " + "Use this to find a movie's id before calling movies_get, reviews_create or reviews_update.")] - public static async Task ListMovies(ISender sender) + public static async Task> ListMovies(ISender sender) { - var result = await sender.Send(new Queries.GetMovies.GetMoviesQuery()); - - return JsonSerializer.Serialize(result); + return await sender.Send(new Queries.GetMovies.GetMoviesQuery()); } - [McpServerTool(Name = "movies_get", Title = "Get movie", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "movies_get", Title = "Get movie", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Get one movie by id, including every review of it with the star rating and the author who wrote it.")] - public static async Task GetMovie( + public static async Task GetMovie( ISender sender, [Description("The movie's id (a GUID). Use movies_list to find it.")] Guid movieId) { - return JsonSerializer.Serialize(await sender.Send(new Queries.GetMovieById.GetMovieByIdQuery + return await sender.Send(new Queries.GetMovieById.GetMovieByIdQuery { Id = movieId - })); + }); } } diff --git a/src/Presentation/Tools/ReviewTools.cs b/src/Presentation/Tools/ReviewTools.cs index d8d7bfc..86ac7a6 100644 --- a/src/Presentation/Tools/ReviewTools.cs +++ b/src/Presentation/Tools/ReviewTools.cs @@ -1,59 +1,56 @@ namespace CleanModelContextProtocol.Presentation.Tools; using System.ComponentModel; -using System.Text.Json; +using CleanModelContextProtocol.Presentation.Models; using Mediator; using ModelContextProtocol.Server; using Commands = Application.Reviews.Commands; +using Entities = Application.Reviews.Entities; using Queries = Application.Reviews.Queries; [McpServerToolType] public static class ReviewTools { - [McpServerTool(Name = "reviews_list", Title = "List reviews", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "reviews_list", Title = "List reviews", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("List every review with its id, star rating (1 to 5), the movie it is for and the author who wrote it.")] - public static async Task ListReviews(ISender sender) + public static async Task> ListReviews(ISender sender) { - var result = await sender.Send(new Queries.GetReviews.GetReviewsQuery()); - - return JsonSerializer.Serialize(result); + return await sender.Send(new Queries.GetReviews.GetReviewsQuery()); } - [McpServerTool(Name = "reviews_get", Title = "Get review", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "reviews_get", Title = "Get review", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Get one review by id, with its star rating, the movie it is for and the author who wrote it.")] - public static async Task GetReview( + public static async Task GetReview( ISender sender, [Description("The review's id (a GUID). Use reviews_list to find it.")] Guid reviewId) { - return JsonSerializer.Serialize(await sender.Send(new Queries.GetReviewById.GetReviewByIdQuery + return await sender.Send(new Queries.GetReviewById.GetReviewByIdQuery { Id = reviewId - })); + }); } - [McpServerTool(Name = "reviews_create", Title = "Create review", ReadOnly = false, Destructive = false, Idempotent = false, OpenWorld = false)] + [McpServerTool(Name = "reviews_create", Title = "Create review", ReadOnly = false, Destructive = false, Idempotent = false, OpenWorld = false, UseStructuredContent = true)] [Description("Create a review of a movie by an author with a star rating from 1 to 5, and return the new review. " + "Each call creates another review, so don't retry a call that succeeded.")] - public static async Task CreateReview( + public static async Task CreateReview( ISender sender, [Description("The id of the author writing the review. Use authors_list to find it.")] Guid authorId, [Description("The id of the movie being reviewed. Use movies_list to find it.")] Guid movieId, [Description("The star rating, a whole number from 1 (worst) to 5 (best).")] int stars) { - var result = await sender.Send(new Commands.CreateReview.CreateReviewCommand + return await sender.Send(new Commands.CreateReview.CreateReviewCommand { AuthorId = authorId, MovieId = movieId, Stars = stars }); - - return JsonSerializer.Serialize(result); } - [McpServerTool(Name = "reviews_update", Title = "Update review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "reviews_update", Title = "Update review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Replace an existing review's author, movie and star rating. Every field is overwritten, " + - "so pass the current author and movie ids when you only want to change the stars.")] - public static async Task UpdateReview( + "so pass the current author and movie ids when you only want to change the stars. Returns the updated review.")] + public static async Task UpdateReview( ISender sender, [Description("The id of the review to update. Use reviews_list to find it.")] Guid reviewId, [Description("The id of the author writing the review. Use authors_list to find it.")] Guid authorId, @@ -68,20 +65,23 @@ public static async Task UpdateReview( Stars = stars }); - return "Review updated successfully"; + return await sender.Send(new Queries.GetReviewById.GetReviewByIdQuery + { + Id = reviewId + }); } - [McpServerTool(Name = "reviews_delete", Title = "Delete review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "reviews_delete", Title = "Delete review", ReadOnly = false, Destructive = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Permanently delete a review. This can't be undone, so confirm with the user first.")] - public static async Task DeleteReview( + public static async Task DeleteReview( ISender sender, [Description("The id of the review to delete. Use reviews_list to find it.")] Guid reviewId) { - _ = await sender.Send(new Commands.DeleteReview.DeleteReviewCommand + var deleted = await sender.Send(new Commands.DeleteReview.DeleteReviewCommand { Id = reviewId }); - return "Review deleted successfully"; + return new DeletedReview(reviewId, deleted); } } diff --git a/src/Presentation/Tools/VersionTools.cs b/src/Presentation/Tools/VersionTools.cs index 53baf03..2020752 100644 --- a/src/Presentation/Tools/VersionTools.cs +++ b/src/Presentation/Tools/VersionTools.cs @@ -3,22 +3,16 @@ namespace CleanModelContextProtocol.Presentation.Tools; using System.ComponentModel; using Mediator; using ModelContextProtocol.Server; +using Entities = Application.Versions.Entities; using Queries = Application.Versions.Queries; [McpServerToolType] public static class VersionTools { - [McpServerTool(Name = "server_get_version", Title = "Get server version", ReadOnly = true, Idempotent = true, OpenWorld = false)] + [McpServerTool(Name = "server_get_version", Title = "Get server version", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] [Description("Get the version of this server: the file version and the informational version, which includes the commit it was built from.")] - public static async Task GetVersion(ISender sender) + public static async Task GetVersion(ISender sender) { - var result = await sender.Send(new Queries.GetVersion.GetVersionQuery()); - - return $""" - | Property | Value | - | --- | --- | - | File Version | {result.FileVersion} | - | Informational Version | {result.InformationalVersion} | - """; + return await sender.Send(new Queries.GetVersion.GetVersionQuery()); } } diff --git a/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs b/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs index c8b9541..860d818 100644 --- a/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs @@ -1,5 +1,6 @@ namespace CleanModelContextProtocol.Presentation.Tests.Integration.Tools; +using CleanModelContextProtocol.Presentation.Models; using Extensions; using ModelContextProtocol; using ModelContextProtocol.Protocol; @@ -121,7 +122,7 @@ public async Task CreateReview_ShouldReturn_Review() } [Fact] - public async Task UpdateReview_ShouldReturn_Success() + public async Task UpdateReview_ShouldReturn_Review() { // Arrange var authorResult = await this.Client.CallToolAsync("authors_list"); @@ -148,12 +149,7 @@ public async Task UpdateReview_ShouldReturn_Success() var text = result.Content.OfType().First().Text; // Assert - text.ShouldBe("Review updated successfully"); - - var validateResult = await this.Client.CallToolAsync("reviews_get", - new Dictionary { ["reviewId"] = existingReview.Id }); - var validateText = validateResult.Content.OfType().First().Text; - var updatedReview = validateText.Deserialize(); + var updatedReview = text.Deserialize(); _ = updatedReview.ShouldNotBeNull(); @@ -171,7 +167,7 @@ public async Task UpdateReview_ShouldReturn_Success() } [Fact] - public async Task DeleteReview_ShouldReturn_Success() + public async Task DeleteReview_ShouldReturn_Result() { // Arrange var reviewsResult = await this.Client.CallToolAsync("reviews_list"); @@ -184,7 +180,10 @@ public async Task DeleteReview_ShouldReturn_Success() var text = result.Content.OfType().First().Text; // Assert - text.ShouldBe("Review deleted successfully"); + var deleted = text.Deserialize(); + + deleted.ReviewId.ShouldBe(existingReview.Id); + deleted.Deleted.ShouldBeTrue(); var validateResult = await this.Client.CallToolAsync("reviews_get", new Dictionary { ["reviewId"] = existingReview.Id }); diff --git a/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs b/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs index 0849c36..4a28f69 100644 --- a/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/ToolListTests.cs @@ -50,6 +50,8 @@ public async Task ListTools_ShouldDescribe_Tool(string name, string title, bool tool.Annotations.DestructiveHint.ShouldBe(destructive); } + _ = tool.OutputSchema.ShouldNotBeNull(); + foreach (var property in tool.InputSchema.GetProperty("properties").EnumerateObject()) { property.Value.GetProperty("description").GetString().ShouldNotBeNullOrWhiteSpace(); diff --git a/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs b/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs index 41b038d..db4e21a 100644 --- a/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/VersionToolTests.cs @@ -1,5 +1,6 @@ namespace CleanModelContextProtocol.Presentation.Tests.Integration.Tools; +using Extensions; using ModelContextProtocol.Protocol; using Shouldly; using Xunit; @@ -13,12 +14,15 @@ public async Task GetVersion_ShouldReturn_Version() var result = await this.Client.CallToolAsync("server_get_version"); var text = result.Content.OfType().First().Text; + var version = text.Deserialize(); + // Assert - _ = text.ShouldNotBeNull(); - _ = text.ShouldBeOfType(); + _ = version.ShouldNotBeNull(); + + version.FileVersion.ShouldNotBeNullOrWhiteSpace(); + version.InformationalVersion.ShouldNotBeNullOrWhiteSpace(); - text.ShouldNotBeNullOrWhiteSpace(); - text.ShouldContain("File Version"); - text.ShouldContain("Informational Version"); + _ = result.StructuredContent.ShouldNotBeNull(); + result.StructuredContent.Value.GetProperty("fileVersion").GetString().ShouldBe(version.FileVersion); } } diff --git a/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs b/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs index 197dbce..1cd9184 100644 --- a/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs @@ -1,6 +1,5 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; -using System.Text.Json; using CleanModelContextProtocol.Presentation.Tools; using Mediator; using NSubstitute; @@ -11,10 +10,8 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; public class AuthorToolTests { - private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; - [Fact] - public async Task GetAllAuthors_ShouldReturn_JsonResult() + public async Task GetAllAuthors_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -30,7 +27,7 @@ public async Task GetAllAuthors_ShouldReturn_JsonResult() var response = await AuthorTools.ListAuthors(sender); // Assert - var result = JsonSerializer.Deserialize>(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result[0].Id.ShouldBe(Guid.Empty); @@ -40,7 +37,7 @@ public async Task GetAllAuthors_ShouldReturn_JsonResult() } [Fact] - public async Task GetAuthorById_ShouldReturn_JsonResult() + public async Task GetAuthorById_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -53,7 +50,7 @@ public async Task GetAuthorById_ShouldReturn_JsonResult() var response = await AuthorTools.GetAuthor(sender, Guid.Empty); // Assert - var result = JsonSerializer.Deserialize(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result.Id.ShouldBe(Guid.Empty); diff --git a/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs b/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs index bfd5e01..68f07f1 100644 --- a/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs @@ -1,6 +1,5 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; -using System.Text.Json; using CleanModelContextProtocol.Presentation.Tools; using Mediator; using NSubstitute; @@ -11,10 +10,8 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; public class MovieToolTests { - private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; - [Fact] - public async Task GetAllMovies_ShouldReturn_JsonResult() + public async Task GetAllMovies_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -30,7 +27,7 @@ public async Task GetAllMovies_ShouldReturn_JsonResult() var response = await MovieTools.ListMovies(sender); // Assert - var result = JsonSerializer.Deserialize>(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result[0].Id.ShouldBe(Guid.Empty); @@ -39,7 +36,7 @@ public async Task GetAllMovies_ShouldReturn_JsonResult() } [Fact] - public async Task GetMovieById_ShouldReturn_JsonResult() + public async Task GetMovieById_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -52,7 +49,7 @@ public async Task GetMovieById_ShouldReturn_JsonResult() var response = await MovieTools.GetMovie(sender, Guid.Empty); // Assert - var result = JsonSerializer.Deserialize(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result.Id.ShouldBe(Guid.Empty); diff --git a/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs b/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs index f096ed8..d011719 100644 --- a/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs @@ -1,6 +1,5 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; -using System.Text.Json; using Application.Authors.Entities; using Application.Movies.Entities; using CleanModelContextProtocol.Presentation.Tools; @@ -14,8 +13,6 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; public class ReviewToolTests { - private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; - private static Entities.Review SampleReview() { return new( @@ -26,7 +23,7 @@ private static Entities.Review SampleReview() } [Fact] - public async Task GetAllReviews_ShouldReturn_JsonResult() + public async Task GetAllReviews_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -39,7 +36,7 @@ public async Task GetAllReviews_ShouldReturn_JsonResult() var response = await ReviewTools.ListReviews(sender); // Assert - var result = JsonSerializer.Deserialize>(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result[0].Id.ShouldBe(Guid.Empty); @@ -52,7 +49,7 @@ public async Task GetAllReviews_ShouldReturn_JsonResult() } [Fact] - public async Task GetReviewById_ShouldReturn_JsonResult() + public async Task GetReviewById_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -65,7 +62,7 @@ public async Task GetReviewById_ShouldReturn_JsonResult() var response = await ReviewTools.GetReview(sender, Guid.Empty); // Assert - var result = JsonSerializer.Deserialize(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result.Id.ShouldBe(Guid.Empty); @@ -78,7 +75,7 @@ public async Task GetReviewById_ShouldReturn_JsonResult() } [Fact] - public async Task CreateReview_ShouldReturn_JsonResult() + public async Task CreateReview_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -91,7 +88,7 @@ public async Task CreateReview_ShouldReturn_JsonResult() var response = await ReviewTools.CreateReview(sender, Guid.Empty, Guid.Empty, 5); // Assert - var result = JsonSerializer.Deserialize(response, JsonOptions); + var result = response; result.ShouldNotBeNull(); result.Id.ShouldBe(Guid.Empty); @@ -104,7 +101,7 @@ public async Task CreateReview_ShouldReturn_JsonResult() } [Fact] - public async Task UpdateReview_ShouldReturn_Success() + public async Task UpdateReview_ShouldReturn_Review() { // Arrange var sender = Substitute.For(); @@ -113,15 +110,20 @@ public async Task UpdateReview_ShouldReturn_Success() .Send(Arg.Any()) .ReturnsForAnyArgs(true); + _ = sender + .Send(Arg.Any()) + .ReturnsForAnyArgs(SampleReview()); + // Act var response = await ReviewTools.UpdateReview(sender, Guid.Empty, Guid.Empty, Guid.Empty, 5); // Assert - response.ShouldBe("Review updated successfully"); + response.Id.ShouldBe(Guid.Empty); + response.Stars.ShouldBe(5); } [Fact] - public async Task DeleteReview_ShouldReturn_Success() + public async Task DeleteReview_ShouldReturn_Result() { // Arrange var sender = Substitute.For(); @@ -134,6 +136,7 @@ public async Task DeleteReview_ShouldReturn_Success() var response = await ReviewTools.DeleteReview(sender, Guid.Empty); // Assert - response.ShouldBe("Review deleted successfully"); + response.ReviewId.ShouldBe(Guid.Empty); + response.Deleted.ShouldBeTrue(); } } diff --git a/tests/Presentation.Tests.Unit/Tools/VersionToolTests.cs b/tests/Presentation.Tests.Unit/Tools/VersionToolTests.cs index 19693de..8c759cc 100644 --- a/tests/Presentation.Tests.Unit/Tools/VersionToolTests.cs +++ b/tests/Presentation.Tests.Unit/Tools/VersionToolTests.cs @@ -11,7 +11,7 @@ namespace CleanModelContextProtocol.Presentation.Tests.Unit.Tools; public class VersionToolTests { [Fact] - public async Task GetVersion_ShouldReturn_MarkdownTable() + public async Task GetVersion_ShouldReturn_Version() { // Arrange var sender = Substitute.For(); @@ -28,7 +28,7 @@ public async Task GetVersion_ShouldReturn_MarkdownTable() var response = await VersionTools.GetVersion(sender); // Assert - response.ShouldContain("| File Version | 1.2.3.4 |"); - response.ShouldContain("| Informational Version | 5.6.7.8 |"); + response.FileVersion.ShouldBe("1.2.3.4"); + response.InformationalVersion.ShouldBe("5.6.7.8"); } } From caa42fa99f8809b25e1fba5dddaece845144d82a Mon Sep 17 00:00:00 2001 From: Stephen Walsh Date: Wed, 28 Oct 2026 15:56:49 +0000 Subject: [PATCH 4/4] fix: guard the tool name before building the not-found hint --- src/Presentation/Errors/ToolErrorFilter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Presentation/Errors/ToolErrorFilter.cs b/src/Presentation/Errors/ToolErrorFilter.cs index 16516cf..de302f8 100644 --- a/src/Presentation/Errors/ToolErrorFilter.cs +++ b/src/Presentation/Errors/ToolErrorFilter.cs @@ -45,7 +45,12 @@ public static CallToolResult ToResult(Exception exception, string toolName = nul private static string ListToolHint(string toolName) { - var separator = toolName?.IndexOf('_') ?? -1; + if (toolName is null) + { + return string.Empty; + } + + var separator = toolName.IndexOf('_'); return separator > 0 ? $" Check the ids, using {toolName[..separator]}_list or the other list tools to find valid ones."