Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7f7306f
Run the MCP Inspector in Docker Compose, pointed at the server
stphnwlsh Oct 28, 2026
709abbc
Merge branch 'main' into feature/docker-mcp-inspector
stphnwlsh Oct 28, 2026
0231b12
feat: give every MCP tool agent-ready metadata
stphnwlsh Oct 28, 2026
b294ae3
feat: return typed, structured results from every MCP tool
stphnwlsh Oct 28, 2026
9a0cf69
feat: add search and paging queries to the Application layer
stphnwlsh Oct 28, 2026
e0a1f9e
Merge branch 'feature/search-and-paging' into feature/mcp-intent-tools
stphnwlsh Oct 28, 2026
7f0dff5
feat: reshape the MCP tools around what agents need to do
stphnwlsh Oct 28, 2026
8c13519
fix: pattern-match the optional review filters
stphnwlsh Oct 28, 2026
caa42fa
fix: guard the tool name before building the not-found hint
stphnwlsh Oct 28, 2026
c76b486
Merge branch 'feature/mcp-tool-metadata' into feature/mcp-structured-…
stphnwlsh Oct 28, 2026
1061a36
Merge branch 'feature/search-and-paging' into feature/mcp-intent-tools
stphnwlsh Oct 28, 2026
a1384f3
Merge branch 'feature/mcp-structured-output' into feature/mcp-intent-…
stphnwlsh Oct 28, 2026
01330ee
test: assert the average stars without dereferencing the nullable
stphnwlsh Oct 28, 2026
721569b
Merge branch 'main' into feature/mcp-structured-output
stphnwlsh Oct 28, 2026
82c7338
Merge branch 'feature/mcp-structured-output' into feature/mcp-intent-…
stphnwlsh Oct 28, 2026
7adb732
Merge remote-tracking branch 'origin/main' into feature/mcp-intent-tools
stphnwlsh Oct 28, 2026
68829e0
Merge branch 'main' into feature/mcp-intent-tools
stphnwlsh Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ 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), 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
- Six task-shaped tools (`movies_search`, `movies_get`, `authors_search`, `reviews_list`, `reviews_write`, `reviews_delete`) with titles, read-only, destructive and idempotent hints, and descriptions written for agents
- Search with paging and small results by default: every list returns 10 items, a total count and a cursor, with names and average ratings next to ids
- 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
Expand Down
20 changes: 3 additions & 17 deletions src/Presentation/Errors/ToolErrorFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public static McpRequestHandler<CallToolRequestParams, CallToolResult> Filter(Mc
}
catch (Exception exception) when (exception is not OperationCanceledException)
{
return ToResult(exception, request?.Params?.Name);
return ToResult(exception);
}
};
}

public static CallToolResult ToResult(Exception exception, string toolName = null)
public static CallToolResult ToResult(Exception exception)
{
var message = exception switch
{
ValidationException validationException => "Validation Failed: " + string.Join(" ", validationException.Errors
.Select(e => $"{e.PropertyName}: {e.ErrorMessage}")
.Distinct()) + " Correct the arguments and call the tool again.",
NotFoundException => $"Not Found: {exception.Message}{ListToolHint(toolName)}",
NotFoundException => $"Not Found: {exception.Message} Check the ids: movies_search, authors_search and reviews_list return valid ones.",
_ => "Error: An error occurred while processing your request."
};

Expand All @@ -42,18 +42,4 @@ public static CallToolResult ToResult(Exception exception, string toolName = nul
Content = [new TextContentBlock { Text = message }]
};
}

private static string ListToolHint(string toolName)
{
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."
: string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public static WebApplicationBuilder ConfigureApplicationBuilder(this WebApplicat
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.
Find things by name first: movies_search and authors_search return ids, review counts and average
stars, and reviews_list filters reviews by movie or author. Every search returns one page at a time,
so pass nextCursor back to continue rather than raising the limit.
reviews_write creates a review, or replaces one when you pass its reviewId.
reviews_delete can't be undone, so confirm with the user before calling it.
""";
})
Expand Down
18 changes: 18 additions & 0 deletions src/Presentation/Models/AuthorResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace CleanModelContextProtocol.Presentation.Models;

using System.ComponentModel;

/// <summary>
/// An author with a summary of the reviews they have written.
/// </summary>
/// <param name="Id">The author's id.</param>
/// <param name="Name">The author's full name.</param>
/// <param name="ReviewCount">How many reviews the author has written.</param>
/// <param name="AverageStars">The average star rating the author gives, from 1 to 5, or null when they have no reviews.</param>
/// <param name="Reviews">Every review the author has written, when they were asked for.</param>
public record AuthorResult(
[property: Description("The author's id.")] Guid Id,
[property: Description("The author's full name.")] string Name,
[property: Description("How many reviews the author has written.")] int ReviewCount,
[property: Description("The average star rating the author gives, from 1 to 5, or null when they have no reviews.")] double? AverageStars,
[property: Description("Every review the author has written, when they were asked for.")] List<ReviewResult> Reviews = null);
18 changes: 18 additions & 0 deletions src/Presentation/Models/MovieResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace CleanModelContextProtocol.Presentation.Models;

using System.ComponentModel;

/// <summary>
/// A movie with a summary of how it was reviewed.
/// </summary>
/// <param name="Id">The movie's id.</param>
/// <param name="Title">The movie's title.</param>
/// <param name="ReviewCount">How many reviews the movie has.</param>
/// <param name="AverageStars">The average star rating, from 1 to 5, or null when there are no reviews.</param>
/// <param name="Reviews">Every review of the movie, when they were asked for.</param>
public record MovieResult(
[property: Description("The movie's id.")] Guid Id,
[property: Description("The movie's title.")] string Title,
[property: Description("How many reviews the movie has.")] int ReviewCount,
[property: Description("The average star rating, from 1 to 5, or null when there are no reviews.")] double? AverageStars,
[property: Description("Every review of the movie, when they were asked for.")] List<ReviewResult> Reviews = null);
65 changes: 65 additions & 0 deletions src/Presentation/Models/ResultMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace CleanModelContextProtocol.Presentation.Models;

using Application.Authors.Entities;
using Application.Common.Paging;
using Application.Movies.Entities;
using Application.Reviews.Entities;

/// <summary>
/// Maps Application entities onto the results the tools return.
/// </summary>
public static class ResultMapper
{
public static MovieResult ToResult(this Movie movie, bool includeReviews)
{
var reviews = movie.Reviews ?? [];

return new MovieResult(
movie.Id,
movie.Title,
reviews.Count,
Average(reviews),
includeReviews ? [.. reviews.Select(r => r.ToResult(movie: new ReviewedMovie(movie.Id, movie.Title)))] : null);
}

public static AuthorResult ToResult(this Author author, bool includeReviews)
{
var reviews = author.Reviews ?? [];

return new AuthorResult(
author.Id,
FullName(author.FirstName, author.LastName),
reviews.Count,
Average(reviews),
includeReviews ? [.. reviews.Select(r => r.ToResult(author: new ReviewAuthor(author.Id, author.FirstName, author.LastName)))] : null);
}

public static ReviewResult ToResult(this Review review, ReviewedMovie movie = null, ReviewAuthor author = null)
{
movie = review.ReviewedMovie ?? movie;
author = review.ReviewAuthor ?? author;

return new ReviewResult(
review.Id,
review.Stars,
movie?.Id,
movie?.Title,
author?.Id,
author is null ? null : FullName(author.FirstName, author.LastName));
}

public static ResultPage<TResult> ToResult<T, TResult>(this Page<T> page, Func<T, TResult> map)
{
return new ResultPage<TResult>([.. page.Items.Select(map)], page.TotalCount, page.NextCursor);
}

private static string FullName(string firstName, string lastName)
{
return $"{firstName} {lastName}".Trim();
}

private static double? Average(ICollection<Review> reviews)
{
return reviews.Count == 0 ? null : Math.Round(reviews.Average(r => r.Stars), 1);
}
}
15 changes: 15 additions & 0 deletions src/Presentation/Models/ResultPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace CleanModelContextProtocol.Presentation.Models;

using System.ComponentModel;

/// <summary>
/// One page of results from a search tool.
/// </summary>
/// <typeparam name="T">The type of the results.</typeparam>
/// <param name="Items">The results on this page.</param>
/// <param name="TotalCount">The number of results across every page.</param>
/// <param name="NextCursor">Pass this as the cursor to get the next page. Null when this is the last page.</param>
public record ResultPage<T>(
[property: Description("The results on this page.")] List<T> Items,
[property: Description("The number of results across every page.")] int TotalCount,
[property: Description("Pass this as the cursor to get the next page. Null when this is the last page.")] string NextCursor);
20 changes: 20 additions & 0 deletions src/Presentation/Models/ReviewResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace CleanModelContextProtocol.Presentation.Models;

using System.ComponentModel;

/// <summary>
/// A review, with the names of the movie and author next to their ids.
/// </summary>
/// <param name="Id">The review's id.</param>
/// <param name="Stars">The star rating, from 1 (worst) to 5 (best).</param>
/// <param name="MovieId">The id of the movie that was reviewed.</param>
/// <param name="MovieTitle">The title of the movie that was reviewed.</param>
/// <param name="AuthorId">The id of the author who wrote the review.</param>
/// <param name="AuthorName">The full name of the author who wrote the review.</param>
public record ReviewResult(
[property: Description("The review's id.")] Guid Id,
[property: Description("The star rating, from 1 (worst) to 5 (best).")] int Stars,
[property: Description("The id of the movie that was reviewed.")] Guid? MovieId,
[property: Description("The title of the movie that was reviewed.")] string MovieTitle,
[property: Description("The id of the author who wrote the review.")] Guid? AuthorId,
[property: Description("The full name of the author who wrote the review.")] string AuthorName);
6 changes: 6 additions & 0 deletions src/Presentation/Serialization/AppJsonSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace CleanModelContextProtocol.Presentation.Serialization;
[JsonSerializable(typeof(Version))]
[JsonSerializable(typeof(List<Version>))]
[JsonSerializable(typeof(DeletedReview))]
[JsonSerializable(typeof(MovieResult))]
[JsonSerializable(typeof(AuthorResult))]
[JsonSerializable(typeof(ReviewResult))]
[JsonSerializable(typeof(ResultPage<MovieResult>))]
[JsonSerializable(typeof(ResultPage<AuthorResult>))]
[JsonSerializable(typeof(ResultPage<ReviewResult>))]
public partial class AppJsonSerializerContext : JsonSerializerContext
{
}
31 changes: 16 additions & 15 deletions src/Presentation/Tools/AuthorTools.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
namespace CleanModelContextProtocol.Presentation.Tools;

using System.ComponentModel;
using CleanModelContextProtocol.Presentation.Models;
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, 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<List<Entities.Author>> ListAuthors(ISender sender)
{
return await sender.Send(new Queries.GetAuthors.GetAuthorsQuery());
}

[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<Entities.Author> GetAuthor(
[McpServerTool(Name = "authors_search", Title = "Search authors", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)]
[Description("Find the authors who write reviews by first name, last name or full name, ignoring case, in last-name order. " +
"Each result has the author's id, name, review count and the average stars they give. Leave the query empty to browse " +
"every author a page at a time. Use this to find an author's id before calling reviews_list or reviews_write.")]
public static async Task<ResultPage<AuthorResult>> SearchAuthors(
ISender sender,
[Description("The author's id (a GUID). Use authors_list to find it.")] Guid authorId)
[Description("Part of the author's name, such as 'marie' or 'marie hirthe'. Leave empty to list every author.")] string query = null,
[Description("The most results to return, from 1 to 50.")] int limit = 10,
[Description("The nextCursor from a previous call, to get the next page. Leave empty for the first page.")] string cursor = null,
[Description("Also return every review each author has written. Leave false unless you need the individual reviews.")] bool includeReviews = false)
{
return await sender.Send(new Queries.GetAuthorById.GetAuthorByIdQuery
var page = await sender.Send(new Queries.SearchAuthors.SearchAuthorsQuery
{
Id = authorId
Query = query,
Limit = limit,
Cursor = cursor
});

return page.ToResult(a => a.ToResult(includeReviews));
}
}
35 changes: 25 additions & 10 deletions src/Presentation/Tools/MovieTools.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
namespace CleanModelContextProtocol.Presentation.Tools;

using System.ComponentModel;
using CleanModelContextProtocol.Presentation.Models;
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, 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<List<Entities.Movie>> ListMovies(ISender sender)
[McpServerTool(Name = "movies_search", Title = "Search movies", ReadOnly = true, Idempotent = true, OpenWorld = false, UseStructuredContent = true)]
[Description("Find movies whose title contains a search term, ignoring case, in title order. Each result has the movie's id, " +
"title, review count and average stars. Leave the query empty to browse every movie a page at a time. " +
"Use this to find a movie's id before calling movies_get, reviews_list or reviews_write.")]
public static async Task<ResultPage<MovieResult>> SearchMovies(
ISender sender,
[Description("Words to look for in the title, such as 'matrix'. Leave empty to list every movie.")] string query = null,
[Description("The most results to return, from 1 to 50.")] int limit = 10,
[Description("The nextCursor from a previous call, to get the next page. Leave empty for the first page.")] string cursor = null,
[Description("Also return every review of each movie. Leave false unless you need the individual reviews.")] bool includeReviews = false)
{
return await sender.Send(new Queries.GetMovies.GetMoviesQuery());
var page = await sender.Send(new Queries.SearchMovies.SearchMoviesQuery
{
Query = query,
Limit = limit,
Cursor = cursor
});

return page.ToResult(m => m.ToResult(includeReviews));
}

[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<Entities.Movie> GetMovie(
[Description("Get one movie with its review count, average stars and every review, including each author's name.")]
public static async Task<MovieResult> GetMovie(
ISender sender,
[Description("The movie's id (a GUID). Use movies_list to find it.")] Guid movieId)
[Description("The movie's id (a GUID). Use movies_search to find it.")] Guid movieId)
{
return await sender.Send(new Queries.GetMovieById.GetMovieByIdQuery
var movie = await sender.Send(new Queries.GetMovieById.GetMovieByIdQuery
{
Id = movieId
});

return movie.ToResult(includeReviews: true);
}
}
Loading
Loading